From 2b024fade418743224fbec3d02dc95f6f0a55588 Mon Sep 17 00:00:00 2001 From: attempt0 Date: Sun, 7 Jun 2026 23:13:09 +0800 Subject: [PATCH] Avoid NBT matching (#378) Co-authored-by: Martin Robertz --- .../item/StandardInventoryIterator.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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());