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.

Co-authored-by: ferriarnus <61201275+ferriarnus@users.noreply.github.com>
Ported-From: e2d537c
  • Loading branch information
Rover656 and ferriarnus committed Sep 29, 2024
1 parent 3d08ef0 commit 88c01d9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,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, ChemicalStack.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, ChemicalStack.EMPTY);
}
} else if (clickType == ClickType.SWAP) {
return;
}
}
super.clicked(pSlotId, pButton, pClickType, pPlayer);

super.doClick(slotId, button, clickType, player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,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.isSameItemSameComponents(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.isSameItemSameComponents(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

0 comments on commit 88c01d9

Please sign in to comment.