Skip to content

Commit e2d537c

Browse files
Rover656ferriarnus
andcommitted
fix: Item duplication with filters
Modifies Ferri's solution from GH-814 to also fix duplication using the 1-9 keys. Also applies the number key fix to the machine menus. Closes: GH-769 Co-authored-by: ferriarnus <[email protected]>
1 parent 98d650c commit e2d537c

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

src/machines/java/com/enderio/machines/common/menu/MachineMenu.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,20 @@ protected boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex,
176176
// Overrides the swapping behaviour. Required for ghost slots to prevent duping
177177
@Override
178178
public void doClick(int slotId, int button, ClickType clickType, Player player) {
179-
if(slotId >= 0 && clickType == ClickType.PICKUP && this.slots.get(slotId) instanceof GhostMachineSlot ghostSlot) {
180-
ItemStack slotItem = ghostSlot.getItem();
181-
ItemStack carriedItem = this.getCarried();
182-
if(!slotItem.isEmpty() && !carriedItem.isEmpty() && ghostSlot.mayPlace(carriedItem)){
183-
if(!ItemStack.isSameItemSameTags(slotItem, carriedItem)){
184-
int count = Math.min(carriedItem.getCount(), ghostSlot.getMaxStackSize(carriedItem));
185-
ghostSlot.setByPlayer(carriedItem.copyWithCount(count));
186-
ghostSlot.setChanged();
187-
return;
179+
if(slotId >= 0 && this.slots.get(slotId) instanceof GhostMachineSlot ghostSlot) {
180+
if (clickType == ClickType.PICKUP) {
181+
ItemStack slotItem = ghostSlot.getItem();
182+
ItemStack carriedItem = this.getCarried();
183+
if(!slotItem.isEmpty() && !carriedItem.isEmpty() && ghostSlot.mayPlace(carriedItem)){
184+
if(!ItemStack.isSameItemSameTags(slotItem, carriedItem)){
185+
int count = Math.min(carriedItem.getCount(), ghostSlot.getMaxStackSize(carriedItem));
186+
ghostSlot.setByPlayer(carriedItem.copyWithCount(count));
187+
ghostSlot.setChanged();
188+
return;
189+
}
188190
}
191+
} else if (clickType == ClickType.SWAP) {
192+
return;
189193
}
190194
}
191195
super.doClick(slotId, button, clickType, player);

src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,17 @@ public void setInverted(Boolean inverted) {
9898
}
9999

100100
@Override
101-
public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer) {
102-
if (pSlotId > 0 && pSlotId < capability.size()) {
103-
if (!capability.getEntry(pSlotId).isEmpty()) {
104-
capability.setEntry(pSlotId, FluidStack.EMPTY);
101+
public void doClick(int slotId, int button, ClickType clickType, Player player) {
102+
if (slotId >= 0 && slotId < capability.size()) {
103+
if (clickType == ClickType.PICKUP) {
104+
if (!capability.getEntry(slotId).isEmpty()) {
105+
capability.setEntry(slotId, FluidStack.EMPTY);
106+
}
107+
} else if (clickType == ClickType.SWAP) {
108+
return;
105109
}
106110
}
107-
super.clicked(pSlotId, pButton, pClickType, pPlayer);
111+
112+
super.doClick(slotId, button, clickType, player);
108113
}
109114
}

src/main/java/com/enderio/base/common/menu/ItemFilterMenu.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,17 @@ public void setInverted(Boolean inverted) {
9898
}
9999

100100
@Override
101-
public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer) {
102-
if (pSlotId > 0 && pSlotId < capability.size()) {
103-
if (!capability.getEntry(pSlotId).isEmpty()) {
104-
capability.setEntry(pSlotId, ItemStack.EMPTY);
101+
public void doClick(int slotId, int button, ClickType clickType, Player player) {
102+
if (slotId >= 0 && slotId < capability.size()) {
103+
if (clickType == ClickType.PICKUP) {
104+
if (!capability.getEntry(slotId).isEmpty()) {
105+
capability.setEntry(slotId, ItemStack.EMPTY);
106+
}
107+
} else if (clickType == ClickType.SWAP) {
108+
return;
105109
}
106110
}
107-
super.clicked(pSlotId, pButton, pClickType, pPlayer);
111+
112+
super.doClick(slotId, button, clickType, player);
108113
}
109114
}

0 commit comments

Comments
 (0)