From e2d537ce5c09ecd4703709f434bb893198d73f39 Mon Sep 17 00:00:00 2001 From: Reece Mackie <20544390+Rover656@users.noreply.github.com> Date: Thu, 26 Sep 2024 21:29:59 +0100 Subject: [PATCH] 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 <61201275+ferriarnus@users.noreply.github.com> --- .../machines/common/menu/MachineMenu.java | 22 +++++++++++-------- .../base/common/menu/FluidFilterMenu.java | 15 ++++++++----- .../base/common/menu/ItemFilterMenu.java | 15 ++++++++----- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/machines/java/com/enderio/machines/common/menu/MachineMenu.java b/src/machines/java/com/enderio/machines/common/menu/MachineMenu.java index 8b4605c94c..cdc0894ca5 100644 --- a/src/machines/java/com/enderio/machines/common/menu/MachineMenu.java +++ b/src/machines/java/com/enderio/machines/common/menu/MachineMenu.java @@ -176,16 +176,20 @@ protected boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex, // Overrides the swapping behaviour. Required for ghost slots to prevent duping @Override public void doClick(int slotId, int button, ClickType clickType, Player player) { - if(slotId >= 0 && clickType == ClickType.PICKUP && this.slots.get(slotId) instanceof GhostMachineSlot ghostSlot) { - ItemStack slotItem = ghostSlot.getItem(); - ItemStack carriedItem = this.getCarried(); - if(!slotItem.isEmpty() && !carriedItem.isEmpty() && ghostSlot.mayPlace(carriedItem)){ - if(!ItemStack.isSameItemSameTags(slotItem, carriedItem)){ - int count = Math.min(carriedItem.getCount(), ghostSlot.getMaxStackSize(carriedItem)); - ghostSlot.setByPlayer(carriedItem.copyWithCount(count)); - ghostSlot.setChanged(); - return; + if(slotId >= 0 && this.slots.get(slotId) instanceof GhostMachineSlot ghostSlot) { + if (clickType == ClickType.PICKUP) { + ItemStack slotItem = ghostSlot.getItem(); + ItemStack carriedItem = this.getCarried(); + if(!slotItem.isEmpty() && !carriedItem.isEmpty() && ghostSlot.mayPlace(carriedItem)){ + if(!ItemStack.isSameItemSameTags(slotItem, carriedItem)){ + int count = Math.min(carriedItem.getCount(), ghostSlot.getMaxStackSize(carriedItem)); + ghostSlot.setByPlayer(carriedItem.copyWithCount(count)); + ghostSlot.setChanged(); + return; + } } + } else if (clickType == ClickType.SWAP) { + return; } } super.doClick(slotId, button, clickType, player); diff --git a/src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java b/src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java index 4649166ee6..914633b0a0 100644 --- a/src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java +++ b/src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java @@ -98,12 +98,17 @@ public void setInverted(Boolean inverted) { } @Override - public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer) { - if (pSlotId > 0 && pSlotId < capability.size()) { - if (!capability.getEntry(pSlotId).isEmpty()) { - capability.setEntry(pSlotId, FluidStack.EMPTY); + public void doClick(int slotId, int button, ClickType clickType, Player player) { + if (slotId >= 0 && slotId < capability.size()) { + if (clickType == ClickType.PICKUP) { + if (!capability.getEntry(slotId).isEmpty()) { + capability.setEntry(slotId, FluidStack.EMPTY); + } + } else if (clickType == ClickType.SWAP) { + return; } } - super.clicked(pSlotId, pButton, pClickType, pPlayer); + + super.doClick(slotId, button, clickType, player); } } diff --git a/src/main/java/com/enderio/base/common/menu/ItemFilterMenu.java b/src/main/java/com/enderio/base/common/menu/ItemFilterMenu.java index 5be5367cd9..2c89c4e4b6 100644 --- a/src/main/java/com/enderio/base/common/menu/ItemFilterMenu.java +++ b/src/main/java/com/enderio/base/common/menu/ItemFilterMenu.java @@ -98,12 +98,17 @@ public void setInverted(Boolean inverted) { } @Override - public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer) { - if (pSlotId > 0 && pSlotId < capability.size()) { - if (!capability.getEntry(pSlotId).isEmpty()) { - capability.setEntry(pSlotId, ItemStack.EMPTY); + public void doClick(int slotId, int button, ClickType clickType, Player player) { + if (slotId >= 0 && slotId < capability.size()) { + if (clickType == ClickType.PICKUP) { + if (!capability.getEntry(slotId).isEmpty()) { + capability.setEntry(slotId, ItemStack.EMPTY); + } + } else if (clickType == ClickType.SWAP) { + return; } } - super.clicked(pSlotId, pButton, pClickType, pPlayer); + + super.doClick(slotId, button, clickType, player); } }