From 176b576c300c12b15822f7ad6fade4f642d4444c Mon Sep 17 00:00:00 2001 From: altrisi Date: Tue, 22 Nov 2022 12:48:04 +0100 Subject: [PATCH] Improve empty shulker box merging a bit - Prevents boxes with different nbt from stacking. Fixes #1596 - Makes stacks partially be able merge to max size when sum would be greater than it (by keeping both entities around, but lowering its count) Pending for the future: Checking why client doesn't render stack size changes --- .../java/carpet/mixins/ItemEntityMixin.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/carpet/mixins/ItemEntityMixin.java b/src/main/java/carpet/mixins/ItemEntityMixin.java index 9866ef3c..04731b21 100644 --- a/src/main/java/carpet/mixins/ItemEntityMixin.java +++ b/src/main/java/carpet/mixins/ItemEntityMixin.java @@ -12,6 +12,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.ShulkerBoxBlock; import carpet.fakes.ItemEntityInterface; +import java.util.Objects; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -22,8 +23,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ItemEntity.class) public abstract class ItemEntityMixin extends Entity implements ItemEntityInterface { - private static final int SHULKERBOX_MAX_STACK_AMOUNT = 64; - @Shadow private int age; @Shadow private int pickupDelay; @@ -51,12 +50,10 @@ public abstract class ItemEntityMixin extends Entity implements ItemEntityInterf private void removeEmptyShulkerBoxTags(Level worldIn, double x, double y, double z, ItemStack stack, CallbackInfo ci) { if (CarpetSettings.shulkerBoxStackSize > 1 - && stack.getItem() instanceof BlockItem - && ((BlockItem)stack.getItem()).getBlock() instanceof ShulkerBoxBlock) + && stack.getItem() instanceof BlockItem bi + && bi.getBlock() instanceof ShulkerBoxBlock) { - if (InventoryHelper.cleanUpShulkerBoxTag(stack)) { - ((ItemEntity) (Object) this).setItem(stack); - } + InventoryHelper.cleanUpShulkerBoxTag(stack); } } @@ -83,7 +80,7 @@ public abstract class ItemEntityMixin extends Entity implements ItemEntityInterf { ItemEntity self = (ItemEntity)(Object)this; ItemStack selfStack = self.getItem(); - if (CarpetSettings.shulkerBoxStackSize == 1 || !(selfStack.getItem() instanceof BlockItem) || !(((BlockItem)selfStack.getItem()).getBlock() instanceof ShulkerBoxBlock)) { + if (CarpetSettings.shulkerBoxStackSize == 1 || !(selfStack.getItem() instanceof BlockItem bi) || !(bi.getBlock() instanceof ShulkerBoxBlock)) { return; } @@ -91,8 +88,8 @@ public abstract class ItemEntityMixin extends Entity implements ItemEntityInterf if (selfStack.getItem() == otherStack.getItem() && !InventoryHelper.shulkerBoxHasItems(selfStack) && !InventoryHelper.shulkerBoxHasItems(otherStack) - && selfStack.hasTag() == otherStack.hasTag() - && selfStack.getCount() + otherStack.getCount() <= CarpetSettings.shulkerBoxStackSize) + && Objects.equals(selfStack.getTag(), otherStack.getTag()) // empty block entity tags are cleaned up when spawning + && selfStack.getCount() != CarpetSettings.shulkerBoxStackSize) { int amount = Math.min(otherStack.getCount(), CarpetSettings.shulkerBoxStackSize - selfStack.getCount()); @@ -105,7 +102,7 @@ public abstract class ItemEntityMixin extends Entity implements ItemEntityInterf otherStack.shrink(amount); if (otherStack.isEmpty()) { - other.discard(); // discard remove(); + other.discard(); } else {