Skip to content

Commit

Permalink
Fix upgrades not being insertable/extractable in compacting drawers
Browse files Browse the repository at this point in the history
Fixes #371 too
  • Loading branch information
Matyrobbrt committed Feb 10, 2025
1 parent 1a1379d commit cf4e892
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ public IItemHandler getStorage() {
return handler;
}

@Override
protected boolean canChangeMultiplier(long newSizeMultiplier) {
var stack = getStorage().getStackInSlot(2);
if (stack.isEmpty()) return true;
return stack.getCount() <= Math.min(Integer.MAX_VALUE, stack.getMaxStackSize() * newSizeMultiplier);
}

@NotNull
@Override
public CompactingDrawerTile getSelf() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,8 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {
replacement[slot] = stack;

var newSize = (long) SizeProvider.calculate(this, FSAttachments.ITEM_STORAGE_MODIFIER, baseSize, replacement);
for (int i = 0; i < getStorage().getSlots(); i++) {
var stored = getStorage().getStackInSlot(i);
if (stored.getCount() > Math.min(Integer.MAX_VALUE, newSize * stored.getMaxStackSize())) {
return ItemStack.EMPTY;
}
if (!canChangeMultiplier(newSize)) {
return ItemStack.EMPTY;
}
}
return super.extractItem(slot, amount, simulate);
Expand All @@ -125,11 +122,8 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {
replacement[integer] = stack;

var newSize = (long) SizeProvider.calculate(getStorageUpgrades(), FSAttachments.ITEM_STORAGE_MODIFIER, baseSize, replacement);
for (int i = 0; i < getStorage().getSlots(); i++) {
var stored = getStorage().getStackInSlot(i);
if (stored.getCount() > Math.min(Integer.MAX_VALUE, newSize * stored.getMaxStackSize())) {
return false;
}
if (!canChangeMultiplier(newSize)) {
return false;
}

return true;
Expand All @@ -140,6 +134,16 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {
.setSlotLimit(1);
}

protected boolean canChangeMultiplier(long newSizeMultiplier) {
for (int i = 0; i < getStorage().getSlots(); i++) {
var stored = getStorage().getStackInSlot(i);
if (!stored.isEmpty() && stored.getCount() > Math.min(Integer.MAX_VALUE, newSizeMultiplier * stored.getMaxStackSize())) {
return false;
}
}
return true;
}

public boolean isEverythingEmpty() {
for (int i = 0; i < getStorage().getSlots(); i++) {
if (!getStorage().getStackInSlot(i).isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public IItemHandler getStorage() {
return handler;
}

@Override
protected boolean canChangeMultiplier(long newSizeMultiplier) {
var stack = getStorage().getStackInSlot(1);
if (stack.isEmpty()) return true;
return stack.getCount() <= Math.min(Integer.MAX_VALUE, stack.getMaxStackSize() * newSizeMultiplier);
}

@NotNull
@Override
Expand Down

0 comments on commit cf4e892

Please sign in to comment.