Skip to content

Commit

Permalink
fix: Item duplication with filters
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Rover656 and ferriarnus committed Sep 26, 2024
1 parent 98d650c commit e2d537c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/enderio/base/common/menu/FluidFilterMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
15 changes: 10 additions & 5 deletions src/main/java/com/enderio/base/common/menu/ItemFilterMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit e2d537c

Please sign in to comment.