Skip to content

Commit 253f96d

Browse files
committed
fix dupe issue with phantom slots and pickup all
1 parent 9b55e76 commit 253f96d

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

src/main/java/com/cleanroommc/modularui/screen/ContainerCustomizer.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.cleanroommc.modularui.screen;
22

33
import com.cleanroommc.modularui.widgets.slot.ModularSlot;
4-
54
import com.cleanroommc.modularui.widgets.slot.SlotGroup;
65

76
import net.minecraft.entity.player.EntityPlayer;
87
import net.minecraft.entity.player.InventoryPlayer;
98
import net.minecraft.inventory.ClickType;
9+
import net.minecraft.inventory.Container;
1010
import net.minecraft.inventory.IInventory;
1111
import net.minecraft.inventory.Slot;
1212
import net.minecraft.item.ItemStack;
13-
1413
import net.minecraft.world.World;
1514
import net.minecraftforge.items.ItemHandlerHelper;
1615

@@ -140,6 +139,40 @@ public void onContainerClosed() {}
140139
}
141140
clickedSlot.onSlotChanged();
142141
}
142+
container.detectAndSendChanges();
143+
return returnable;
144+
} else if (clickTypeIn == ClickType.PICKUP_ALL && slotId >= 0) {
145+
Slot slot = container.inventorySlots.get(slotId);
146+
ItemStack itemstack1 = inventoryplayer.getItemStack();
147+
148+
if (!itemstack1.isEmpty() && (slot == null || !slot.getHasStack() || !slot.canTakeStack(player))) {
149+
int i = mouseButton == 0 ? 0 : container.inventorySlots.size() - 1;
150+
int j = mouseButton == 0 ? 1 : -1;
151+
152+
for (int k = 0; k < 2; ++k) {
153+
for (int l = i; l >= 0 && l < container.inventorySlots.size() && itemstack1.getCount() < itemstack1.getMaxStackSize(); l += j) {
154+
Slot slot1 = container.inventorySlots.get(l);
155+
if (slot1 instanceof ModularSlot modularSlot && modularSlot.isPhantom()) continue;
156+
157+
if (slot1.getHasStack() && Container.canAddItemToSlot(slot1, itemstack1, true) && slot1.canTakeStack(player) && canMergeSlot(itemstack1, slot1)) {
158+
ItemStack itemstack2 = slot1.getStack();
159+
160+
if (k != 0 || itemstack2.getCount() != itemstack2.getMaxStackSize()) {
161+
int i1 = Math.min(itemstack1.getMaxStackSize() - itemstack1.getCount(), itemstack2.getCount());
162+
ItemStack itemstack3 = slot1.decrStackSize(i1);
163+
itemstack1.grow(i1);
164+
165+
if (itemstack3.isEmpty()) {
166+
slot1.putStack(ItemStack.EMPTY);
167+
}
168+
169+
slot1.onTake(player, itemstack3);
170+
}
171+
}
172+
}
173+
}
174+
}
175+
143176
container.detectAndSendChanges();
144177
return returnable;
145178
}
@@ -154,7 +187,7 @@ public void onContainerClosed() {}
154187
if (!stack.isEmpty()) {
155188
stack = stack.copy();
156189
int base = 0;
157-
if(stack.getCount() > stack.getMaxStackSize()) {
190+
if (stack.getCount() > stack.getMaxStackSize()) {
158191
base = stack.getCount() - stack.getMaxStackSize();
159192
stack.setCount(stack.getMaxStackSize());
160193
}

src/main/java/com/cleanroommc/modularui/widgets/slot/IOnSlotChanged.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ public interface IOnSlotChanged {
77
/**
88
* An empty listener.
99
*/
10-
IOnSlotChanged DEFAULT = (newItem, onlyAmountChanged, client, init) -> {
11-
};
10+
IOnSlotChanged DEFAULT = (newItem, onlyAmountChanged, client, init) -> {};
1211

1312
/**
1413
* Called when an item stack in a {@link ModularSlot} changes.

0 commit comments

Comments
 (0)