Useful Backpacks

Useful Backpacks

20M Downloads

[1.12.2] Dupe Bug

focamacho opened this issue ยท 3 comments

commented

Describe the bug
Dupe items using backpacks. It seems to happen only when Sponge is installed.

To Reproduce
Steps to reproduce the behavior:

  1. Open and drop a backpack at the same time
  2. Take the itens from the backpack gui, and the backpack on the ground
  3. That's all

Expected behavior
Be impossible to pick up the items in the backpack

Versions

  • Mod version: 1.5.3.59
  • Minecraft version: 1.12.2
  • Forge version: 14.23.5.2854
  • UTeamCore version: 2.2.5.147

I did a quick fix but I don't know if it's the best way to fix it.
https://github.com/Focamacho/Useful-Backpacks/commit/98edcc80dda9d7a8b8e672edfdb099bec039a0b4

commented

Hello, thanks for the report. These issues are fixed on 1.15.2+ but 1.12.2 is kinda unsupported.
I'm happy if you want to pr the fixes:

Your fix seems to adress the main cause though so I'm happy if you want to PR that. (Would be nice if you may have a look at the oder dupe fixes and if its possible to backport them.)

if (clickType == ClickType.SWAP) {
final ItemStack stack = player.inventory.getStackInSlot(dragType);
final ItemStack currentItem = PlayerInventory.isHotbar(selectedSlot) ? player.inventory.mainInventory.get(selectedSlot) : selectedSlot == -1 ? player.inventory.offHandInventory.get(0) : ItemStack.EMPTY;
if (!currentItem.isEmpty() && stack == currentItem) {
return ItemStack.EMPTY;
}
}
return super.slotClick(slotId, dragType, clickType, player);

@Override
public boolean canInteractWith(PlayerEntity player) {
if (backpackInventory instanceof BackpackInventory) {
final ItemStack stack = ((BackpackInventory) backpackInventory).getStack();
return !stack.isEmpty() && stack.getItem() instanceof IBackpack;
}
return true;
}

@Override
public boolean onDroppedByPlayer(ItemStack item, PlayerEntity player) {
return !(player.openContainer instanceof BackpackContainer);
}

commented

Of course!