From f77809b66f5da4521f815310ede5e7093118562d Mon Sep 17 00:00:00 2001 From: mahjerion <66142256+mahjerion@users.noreply.github.com> Date: Thu, 12 Dec 2024 22:13:30 -0500 Subject: [PATCH] fixes dupe from https://github.com/refinedmods/refinedstorage/pull/3669 --- .../externalstorage/ItemExternalStorage.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/storage/externalstorage/ItemExternalStorage.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/storage/externalstorage/ItemExternalStorage.java index 57cbb66219..6f7410d211 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/storage/externalstorage/ItemExternalStorage.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/storage/externalstorage/ItemExternalStorage.java @@ -112,23 +112,30 @@ public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, Action a ItemStack received = ItemStack.EMPTY; - for (int i = 0; i < handler.getSlots(); ++i) { - ItemStack slot = handler.getStackInSlot(i); + while(remaining > 0) { + for (int i = 0; i < handler.getSlots(); ++i) { + ItemStack slot = handler.getStackInSlot(i); + + if (!slot.isEmpty() && API.instance().getComparer().isEqual(slot, stack, flags)) { + //Check if the requested amount of 64 isn't found in the slot + if(slot.getCount() < remaining) { + remaining = slot.getCount(); + } - if (!slot.isEmpty() && API.instance().getComparer().isEqual(slot, stack, flags)) { - ItemStack got = handler.extractItem(i, remaining, action == Action.SIMULATE); + ItemStack got = handler.extractItem(i, Math.min(remaining, stack.getMaxStackSize()), action == Action.SIMULATE); - if (!got.isEmpty()) { - if (received.isEmpty()) { - received = got.copy(); - } else { - received.grow(got.getCount()); - } + if (!got.isEmpty()) { + if (received.isEmpty()) { + received = got.copy(); + } else { + received.grow(got.getCount()); + } - remaining -= got.getCount(); + remaining -= got.getCount(); - if (remaining == 0) { - break; + if (remaining == 0) { + break; + } } } }