From 89bd5788a6bc6ced2a4c5224704e857d6cafa272 Mon Sep 17 00:00:00 2001 From: Fff Date: Tue, 14 Jul 2026 19:25:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=B1=BC=E7=BC=B8=E5=8A=A0?= =?UTF-8?q?=E5=B7=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cache/item/ItemHandlerCacheElement.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/module.recipe/src/main/java/dev/anvilcraft/lib/v2/recipe/cache/item/ItemHandlerCacheElement.java b/module.recipe/src/main/java/dev/anvilcraft/lib/v2/recipe/cache/item/ItemHandlerCacheElement.java index 01455f10..0f0bce09 100644 --- a/module.recipe/src/main/java/dev/anvilcraft/lib/v2/recipe/cache/item/ItemHandlerCacheElement.java +++ b/module.recipe/src/main/java/dev/anvilcraft/lib/v2/recipe/cache/item/ItemHandlerCacheElement.java @@ -6,6 +6,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.IItemHandlerModifiable; import javax.annotation.Nullable; @@ -84,6 +85,20 @@ public void sync() { this.growSimulateStack.clear(); this.shrinkSimulateStack.clear(); ItemStack stack = this.iItemHandler.getStackInSlot(this.slot); + if (ItemHandlerCacheElement.matches(stack, this.simulate)) return; + if (this.iItemHandler instanceof IItemHandlerModifiable modifiable) { + modifiable.setStackInSlot(this.slot, this.simulate.copy()); + return; + } + if (ItemStack.isSameItemSameComponents(stack, this.simulate)) { + int difference = this.simulate.getCount() - stack.getCount(); + if (difference > 0) { + this.iItemHandler.insertItem(this.slot, this.simulate.copyWithCount(difference), false); + } else { + this.iItemHandler.extractItem(this.slot, -difference, false); + } + return; + } if (!stack.isEmpty()) { this.iItemHandler.extractItem(this.slot, Integer.MAX_VALUE, false); } @@ -91,4 +106,9 @@ public void sync() { this.iItemHandler.insertItem(this.slot, this.simulate.copy(), false); } } + + private static boolean matches(ItemStack first, ItemStack second) { + if (first.isEmpty() || second.isEmpty()) return first.isEmpty() && second.isEmpty(); + return first.getCount() == second.getCount() && ItemStack.isSameItemSameComponents(first, second); + } }