From fe0fde009bda501f0b7199c9339bb93986a86270 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Sat, 3 Aug 2024 12:21:47 +0200 Subject: [PATCH] Fix #143: Battery dupe when inserting in ender cell (#177) --- .../owmii/powah/lib/logistics/inventory/ItemStackHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/owmii/powah/lib/logistics/inventory/ItemStackHandler.java b/src/main/java/owmii/powah/lib/logistics/inventory/ItemStackHandler.java index 2158fa4..f0df002 100644 --- a/src/main/java/owmii/powah/lib/logistics/inventory/ItemStackHandler.java +++ b/src/main/java/owmii/powah/lib/logistics/inventory/ItemStackHandler.java @@ -78,7 +78,8 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate if (!simulate) { if (existing.isEmpty()) { - this.stacks.set(slot, reachedLimit ? ItemStackHandlerHelper.copyStackWithSize(stack, limit) : stack); + // We must always copy the stack because onContentsChanged might change it, messing with our later use. + this.stacks.set(slot, reachedLimit ? ItemStackHandlerHelper.copyStackWithSize(stack, limit) : stack.copy()); } else { existing.grow(reachedLimit ? limit : stack.getCount()); }