Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed dupe with External Storage and a higher stack size than 64 #3669

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down