Fixed dupe bug in ItemMatcher and made hasRoom not modify the inventory contents.

This commit is contained in:
2026-08-29 22:23:46 +02:00
parent 46dec9a933
commit ebb4d783e8
2 changed files with 16 additions and 13 deletions
@@ -109,17 +109,20 @@ public class InventoryUtils {
if (itemStack.getAmount() <= 0) if (itemStack.getAmount() <= 0)
return true; return true;
int overflow = addItem(inventory, itemStack); int remaining = itemStack.getAmount();
//revert back if inventory cannot hold all of the items for (ItemStack stack : inventory.getStorageContents()) {
if (overflow > 0) { if (stack == null || stack.getType().isAir()) {
ItemStack revert = itemStack.clone(); remaining -= itemStack.getMaxStackSize();
revert.setAmount(revert.getAmount() - overflow); } else if (stack.isSimilar(itemStack)) {
InventoryUtils.removeItem(inventory, revert); remaining -= stack.getMaxStackSize() - stack.getAmount();
return false;
} }
removeItem(inventory, itemStack);
if (remaining <= 0)
return true; return true;
} }
return false;
}
} }
@@ -266,8 +266,8 @@ public class ItemMatcher {
return false; // not the same color return false; // not the same color
// Do we need all of the above checks inside the shulker? // Do we need all of the above checks inside the shulker?
if (Arrays.equals(shulkerBox1.getInventory().getContents(), shulkerBox2.getInventory().getContents())) // same content if true
return true; // same content return Arrays.equals(shulkerBox1.getInventory().getContents(), shulkerBox2.getInventory().getContents());
} }
} }
return true; return true;
@@ -295,7 +295,7 @@ public class ItemMatcher {
} }
if (item1 == null || item2 == null) { if (item1 == null || item2 == null) {
return true; return false;
} }
if (!item1.getType().equals(item2.getType())) { if (!item1.getType().equals(item2.getType())) {
@@ -310,7 +310,7 @@ public class ItemMatcher {
return metaMatches(item1, item2); return metaMatches(item1, item2);
} }
return !item1.hasItemMeta() && !item1.hasItemMeta(); return !item1.hasItemMeta() && !item2.hasItemMeta();
} }
protected static boolean metaMatches(ItemStack item1, ItemStack item2) { protected static boolean metaMatches(ItemStack item1, ItemStack item2) {