From 926074ca0297149e19713b74b5e5cc2a36893b4a Mon Sep 17 00:00:00 2001 From: Starforcraft Date: Fri, 5 Apr 2024 11:43:47 +0200 Subject: [PATCH 1/3] Fixed dupe with External Storage and a higher stack size than 64 --- CHANGELOG.md | 4 +++ .../externalstorage/ItemExternalStorage.java | 28 ++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) 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..b7596dc427 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 @@ -111,23 +111,25 @@ 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)) { - ItemStack got = handler.extractItem(i, remaining, action == Action.SIMULATE); + if (!slot.isEmpty() && API.instance().getComparer().isEqual(slot, stack, flags)) { + 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; + } } } } From 398fde812541c9c124fabc5c1475d69cb3c7b10a Mon Sep 17 00:00:00 2001 From: Starforcraft Date: Fri, 5 Apr 2024 16:50:51 +0200 Subject: [PATCH 2/3] Fixed infinite loop --- .../storage/externalstorage/ItemExternalStorage.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 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 b7596dc427..6413a74af4 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; @@ -116,6 +117,11 @@ public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, Action a ItemStack slot = handler.getStackInSlot(i); if (!slot.isEmpty() && API.instance().getComparer().isEqual(slot, stack, flags)) { + //Checks if the requested amount of 64 isn't found in the slot + if(slot.getCount() < remaining) { + remaining = slot.getCount(); + } + ItemStack got = handler.extractItem(i, Math.min(remaining, stack.getMaxStackSize()), action == Action.SIMULATE); if (!got.isEmpty()) { @@ -127,7 +133,7 @@ public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, Action a remaining -= got.getCount(); - if (remaining <= 0) { + if (remaining == 0) { break; } } From 948343dfe92e5726505079d963806346afd72d88 Mon Sep 17 00:00:00 2001 From: Starforcraft Date: Fri, 5 Apr 2024 16:53:32 +0200 Subject: [PATCH 3/3] Changed wording --- .../apiimpl/storage/externalstorage/ItemExternalStorage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6413a74af4..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 @@ -117,7 +117,7 @@ public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, Action a ItemStack slot = handler.getStackInSlot(i); if (!slot.isEmpty() && API.instance().getComparer().isEqual(slot, stack, flags)) { - //Checks if the requested amount of 64 isn't found in the slot + //Check if the requested amount of 64 isn't found in the slot if(slot.getCount() < remaining) { remaining = slot.getCount(); }