diff --git a/CHANGELOG.md b/CHANGELOG.md index 8247f33b15..be2592f823 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- Fixed dupe with External Storage and a higher stack size than 64. + ## [1.13.0-beta.4] - 2024-03-07 ### Added 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 a9d429228b..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 @@ -7,8 +7,9 @@ import com.refinedmods.refinedstorage.api.util.Action; import com.refinedmods.refinedstorage.apiimpl.API; import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.items.IItemHandler; -import net.neoforged.neoforge.items.ItemHandlerHelper; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.ItemHandlerHelper; + import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.ArrayList; @@ -111,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); - - if (!slot.isEmpty() && API.instance().getComparer().isEqual(slot, stack, flags)) { - ItemStack got = handler.extractItem(i, remaining, action == Action.SIMULATE); + while(remaining > 0) { + for (int i = 0; i < handler.getSlots(); ++i) { + ItemStack slot = handler.getStackInSlot(i); - if (!got.isEmpty()) { - if (received.isEmpty()) { - received = got.copy(); - } else { - received.grow(got.getCount()); + 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(); } - remaining -= got.getCount(); + 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()); + } + + remaining -= got.getCount(); - if (remaining == 0) { - break; + if (remaining == 0) { + break; + } } } }