diff --git a/src/main/java/carpet/mixins/ScreenHandler_stackableSBoxesMixin.java b/src/main/java/carpet/mixins/ScreenHandler_stackableSBoxesMixin.java new file mode 100644 index 00000000..6c8ff20e --- /dev/null +++ b/src/main/java/carpet/mixins/ScreenHandler_stackableSBoxesMixin.java @@ -0,0 +1,33 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import carpet.helpers.InventoryHelper; +import net.minecraft.block.ShulkerBoxBlock; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.slot.Slot; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ScreenHandler.class) +public class ScreenHandler_stackableSBoxesMixin +{ + @Redirect(method = "internalOnSlotClick", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/screen/slot/Slot;getMaxItemCount(Lnet/minecraft/item/ItemStack;)I" + )) + private int getMaxCountForSboxesInScreenHander(Slot slot, ItemStack stack) + { + if (CarpetSettings.stackableShulkerBoxes && + stack.getItem() instanceof BlockItem && + ((BlockItem)stack.getItem()).getBlock() instanceof ShulkerBoxBlock && + !InventoryHelper.shulkerBoxHasItems(stack) + ) + { + return CarpetSettings.SHULKER_STACK_SIZE; + } + return slot.getMaxItemCount(stack); + } +} diff --git a/src/main/java/carpet/mixins/Slot_stackableSBoxesMixin.java b/src/main/java/carpet/mixins/Slot_stackableSBoxesMixin.java index 557ea506..317ca1b6 100644 --- a/src/main/java/carpet/mixins/Slot_stackableSBoxesMixin.java +++ b/src/main/java/carpet/mixins/Slot_stackableSBoxesMixin.java @@ -16,7 +16,7 @@ public class Slot_stackableSBoxesMixin { value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;getMaxItemCount(Lnet/minecraft/item/ItemStack;)I" )) - private int getMaxCountForSboxes(Slot slot, ItemStack stack) + private int getMaxCountForSboxesInSlot(Slot slot, ItemStack stack) { if (CarpetSettings.stackableShulkerBoxes && stack.getItem() instanceof BlockItem && diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 24f70d9b..40d083d7 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -136,6 +136,7 @@ "CauldronBlock_stackableSBoxesMixin", "AbstractCauldronBlock_stackableSBoxesMixin", "Slot_stackableSBoxesMixin", + "ScreenHandler_stackableSBoxesMixin", "ItemEntityMixin", "TntBlockMixin", "ExplosionMixin",