diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinScreenHandler.java b/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinScreenHandler.java index 2a6bf29a..20b7c394 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinScreenHandler.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinScreenHandler.java @@ -5,7 +5,8 @@ import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import dev.emi.trinkets.TrinketSlot; +import com.minelittlepony.unicopia.trinkets.TrinketsDelegate; + import net.minecraft.item.ItemStack; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; @@ -37,7 +38,7 @@ abstract class MixinScreenHandler { ) // redirect slot.getMaxItemCount() to stack aware version protected int onGetMaxItemCount(Slot sender, ItemStack stack) { - return canApply(sender) ? sender.getMaxItemCount(stack) : sender.getMaxItemCount(); + return TrinketsDelegate.getInstance().isTrinketSlot(sender) ? sender.getMaxItemCount(stack) : sender.getMaxItemCount(); } @Redirect(method = "insertItem", @@ -49,7 +50,7 @@ abstract class MixinScreenHandler { ) // redirect "if (!itemStack.isEmpty() && ItemStack.canCombine(stack, itemStack))" -> "if (!canNotInsert(itemStack, slot) && ItemStack.canCombine(stack, itemStack))" protected boolean canNotInsert(ItemStack sender) { - return sender.isEmpty() || (canApply(currentSlot) && (currentSlot.getStack().getCount() + sender.getCount()) <= currentSlot.getMaxItemCount(sender)); + return sender.isEmpty() || (TrinketsDelegate.getInstance().isTrinketSlot(currentSlot) && (currentSlot.getStack().getCount() + sender.getCount()) <= currentSlot.getMaxItemCount(sender)); } @Redirect(method = "canInsertItemIntoSlot", @@ -58,11 +59,7 @@ abstract class MixinScreenHandler { target = "Lnet/minecraft/item/ItemStack;getMaxCount()I" ) ) - private static int onCanInsertItemIntoSlot(ItemStack sender, @Nullable Slot slot) { - return canApply(slot) ? slot.getMaxItemCount(sender) : sender.getMaxCount(); - } - - private static boolean canApply(Slot slot) { - return slot instanceof TrinketSlot; + private static int onGetMaxCount(ItemStack sender, @Nullable Slot slot) { + return TrinketsDelegate.getInstance().isTrinketSlot(slot) ? slot.getMaxItemCount(sender) : sender.getMaxCount(); } } diff --git a/src/main/java/com/minelittlepony/unicopia/trinkets/TrinketsDelegate.java b/src/main/java/com/minelittlepony/unicopia/trinkets/TrinketsDelegate.java index fec45d14..780bbbb1 100644 --- a/src/main/java/com/minelittlepony/unicopia/trinkets/TrinketsDelegate.java +++ b/src/main/java/com/minelittlepony/unicopia/trinkets/TrinketsDelegate.java @@ -9,6 +9,7 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.mob.MobEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; import net.minecraft.util.Identifier; public interface TrinketsDelegate { @@ -69,4 +70,8 @@ public interface TrinketsDelegate { default void registerTrinket(Item item) { } + + default boolean isTrinketSlot(Slot slot) { + return false; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/trinkets/TrinketsDelegateImpl.java b/src/main/java/com/minelittlepony/unicopia/trinkets/TrinketsDelegateImpl.java index b4dd91e8..4ca11c28 100644 --- a/src/main/java/com/minelittlepony/unicopia/trinkets/TrinketsDelegateImpl.java +++ b/src/main/java/com/minelittlepony/unicopia/trinkets/TrinketsDelegateImpl.java @@ -12,6 +12,7 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; import net.minecraft.sound.SoundEvent; import net.minecraft.util.Identifier; import net.minecraft.world.event.GameEvent; @@ -80,6 +81,11 @@ public class TrinketsDelegateImpl implements TrinketsDelegate { .flatMap(group -> group.values().stream()); } + @Override + public boolean isTrinketSlot(Slot slot) { + return slot instanceof TrinketSlot; + } + private static Identifier getSlotId(SlotType slotType) { return new Identifier(slotType.getGroup(), slotType.getName()); }