From 2216c33f12ef17af0b30a1945f5474e2a2d2970a Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Sat, 10 Oct 2020 20:13:36 +0200 Subject: [PATCH] Be less defensive about copying item stacks in simulated extractions (but still catch obviously broken implementations). Also fix looping over the same slot while simulating, and try to heuristically guess the maximum extraction from the slot given what getStackInSlot returned. --- .../appeng/parts/misc/ItemHandlerAdapter.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java index fbc9f7abf..23a698873 100644 --- a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java +++ b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java @@ -122,6 +122,15 @@ class ItemHandlerAdapter implements IMEInventory, IBaseMonitor remainingCurrentSlot) { // Something broke. It should never return more than we requested... // We're going to silently eat the remainder @@ -131,19 +140,28 @@ class ItemHandlerAdapter implements IMEInventory, IBaseMonitor extracted.getMaxStackSize()) { + extracted.setCount(remainingCurrentSlot); + } + // We're just gonna use the first stack we get our hands on as the template for // the rest. - // In case some stupid itemhandler (aka forge) returns an internal state we have - // to do a second - // expensive copy again. if (gathered.isEmpty()) { - gathered = extracted.copy(); + gathered = extracted; } else { gathered.grow(extracted.getCount()); } remainingCurrentSlot -= extracted.getCount(); } - } while (!extracted.isEmpty() && remainingCurrentSlot > 0); + } while (!simulate && !extracted.isEmpty() && remainingCurrentSlot > 0); remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;