-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from Dragon-Seeker/1.21-CondensedCreativeCompat
[1.21] Condensed Creative Compability, Refactors mixins, and adjust such to be Client Mod
- Loading branch information
Showing
20 changed files
with
298 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ maven_group=smsk.smoothscroll | |
archives_base_name=smoothscroll | ||
|
||
item_borders_version=1.2.3 | ||
cc_version=3.4.0+1.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package smsk.smoothscroll; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.inventory.Inventory; | ||
import net.minecraft.item.ItemStack; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.IntFunction; | ||
|
||
/** | ||
* An implementation of {@link Inventory} used to allow for wrapping any method of getting a | ||
* stack from a given collection. Used to support Condensed Creative method of entries. | ||
*/ | ||
public class DelegatingInventory<S> implements Inventory { | ||
|
||
protected final IntFunction<S> getter; | ||
protected final Function<S, ItemStack> mapper; | ||
|
||
protected DelegatingInventory(IntFunction<S> getter, Function<S, ItemStack> mapper){ | ||
this.getter = getter; | ||
this.mapper = mapper; | ||
} | ||
|
||
public static DelegatingInventory<ItemStack> itemStackBased(IntFunction<ItemStack> stackGetter) { | ||
return new DelegatingInventory<>(stackGetter, stack -> stack); | ||
} | ||
|
||
@Override | ||
public ItemStack getStack(int slot) { | ||
return mapper.apply(getter.apply(slot)); | ||
} | ||
|
||
//-- DEFAULT IMPLEMENTATION SECTION BELOW --// | ||
|
||
@Override public int size() { return 1; } | ||
@Override public boolean isEmpty() { return false; } | ||
@Override public ItemStack removeStack(int slot, int amount) { return ItemStack.EMPTY; } | ||
@Override public ItemStack removeStack(int slot) { return ItemStack.EMPTY; } | ||
@Override public void setStack(int slot, ItemStack stack) {} | ||
@Override public void markDirty() {} | ||
@Override public boolean canPlayerUse(PlayerEntity player) { return true; } | ||
@Override public void clear() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 31 additions & 5 deletions
36
src/main/java/smsk/smoothscroll/compat/CondensedInventoryCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
package smsk.smoothscroll.compat; | ||
|
||
import io.wispforest.condensed_creative.util.CondensedInventory; | ||
import net.minecraft.item.ItemStack; | ||
import smsk.smoothscroll.mixin.CreativeScreen.CreativeScreenAccessor; | ||
import io.wispforest.condensed_creative.ducks.CreativeInventoryScreenHandlerDuck; | ||
import io.wispforest.condensed_creative.entry.Entry; | ||
import io.wispforest.condensed_creative.entry.EntryContainer; | ||
import io.wispforest.condensed_creative.entry.impl.ItemEntry; | ||
import net.minecraft.screen.ScreenHandler; | ||
import smsk.smoothscroll.DelegatingInventory; | ||
|
||
public class CondensedInventoryCompat { | ||
public static ItemStack getStack(int i) { | ||
return ((CondensedInventory) CreativeScreenAccessor.INVENTORY()).getEntryStack(i - 9).getEntryStack(); | ||
|
||
public static DelegatingInventory<Entry> of(ScreenHandler handler) { | ||
return new CondensedEntryDelegatingInventory(handler); | ||
} | ||
|
||
public static class CondensedEntryDelegatingInventory extends DelegatingInventory<Entry> implements EntryContainer { | ||
protected CondensedEntryDelegatingInventory(ScreenHandler handler) { | ||
super(value -> { | ||
try { | ||
if(handler instanceof CreativeInventoryScreenHandlerDuck duck) { | ||
return duck.getFilteredEntryList().get(value); | ||
} | ||
} catch (IndexOutOfBoundsException ignored) {} | ||
|
||
return ItemEntry.EMPTY; | ||
}, Entry::getDisplayStack); | ||
} | ||
|
||
@Override | ||
public Entry getEntryStack(int slot) { | ||
return this.getter.apply(slot); | ||
} | ||
|
||
@Override | ||
public void setEntryStack(int slot, Entry entryStack){} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.