diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/item/StandardInventoryIterator.java b/src/main/java/com/gtnewhorizon/gtnhlib/item/StandardInventoryIterator.java index 9f688c0e..7996f53f 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/item/StandardInventoryIterator.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/item/StandardInventoryIterator.java @@ -107,18 +107,26 @@ public class StandardInventoryIterator extends AbstractInventoryIterator { ItemStack inSlot = getStackInSlot(slotIndex); - if (!ItemUtil.isStackEmpty(inSlot) && !stack.matches(inSlot)) { - return stack.getStackSize(); - } - ItemStack partialCopy = stack.toStackFast(); + int maxStack = getSlotStackLimit(slotIndex, partialCopy); + + if (!ItemUtil.isStackEmpty(inSlot)) { + if (!forced) { + // Skip expensive NBT check if the stack is full. + if (inSlot.stackSize >= maxStack || !inSlot.isStackable()) { + return stack.getStackSize(); + } + } + if (!stack.matches(inSlot)) { + return stack.getStackSize(); + } + } + if (!forced && !canInsert(partialCopy, slotIndex)) { return stack.getStackSize(); } - int maxStack = getSlotStackLimit(slotIndex, partialCopy); - if (!ItemUtil.isStackEmpty(inSlot)) { int toInsert = forced ? stack.getStackSize() : Math.min(maxStack - inSlot.stackSize, stack.getStackSize());