Skip to content

Diamond dupe + other dupes in crafting grid #37

@Leonides-Moffitt

Description

@Leonides-Moffitt

There is a bug that lets you duplicate backpack upgrade materials (copper, iron, gold, diamond)

To Reproduce
Steps to reproduce the behavior:

  1. Open a crafting table
  2. surround a gold backpack with diamonds, (multiple per slot)
  3. craft the backpack
  4. Dupe the diamonds in the crafting grid!, it can even push a stack past 64

Version information:

  • Plugin version [e.g. v1.2.0]

Additional context
I actually tracked the bug down to a snippet of BackpackCraftingListener.class starting at line 133 and fixed it, by replacing

for (int i : surrounding = new int[]{0, 1, 2, 3, 5, 6, 7, 8}) {
ItemStack slot = matrix[i];
if (slot == null || slot.getType() == Material.AIR) continue;
if (slot.getAmount() > 1) {
ItemStack reduced = slot.clone();
reduced.setAmount(slot.getAmount() - 1);
inv.setItem(i + 1, reduced);
continue;
}
inv.setItem(i + 1, null);
}
inv.setItem(5, null);

With this

surrounding = new int[]{0, 1, 2, 3, 5, 6, 7, 8};
int[] var7 = surrounding;
int var8 = surrounding.length;

              for(int var9 = 0; var9 < var8; ++var9) {
                 int i = var7[var9];
                 ItemStack slot = matrix[i];
                 if (slot != null && slot.getType() != Material.AIR) {
                    int invSlot = i + 1;
                    if (slot.getAmount() > 1) {
                       ItemStack reduced = slot.clone();
                       reduced.setAmount(slot.getAmount() - 1);
                       inv.setItem(invSlot, reduced);
                    } else {
                       inv.setItem(invSlot, (ItemStack)null);
                    }
                 }
              }

              inv.setItem(5, (ItemStack)null);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions