From eaeeb80fd350ff72bdadabfbded7f4cc50975517 Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Mon, 8 Jan 2018 23:56:58 +0100 Subject: [PATCH] Fix issues with partial item transfer due to full inventory --- .../com/Acrobot/Breeze/Utils/MaterialUtil.java | 2 +- .../PartialTransactionModule.java | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java b/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java index 7485096..f50bd91 100644 --- a/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java +++ b/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java @@ -59,7 +59,7 @@ public class MaterialUtil { */ public static boolean equals(ItemStack one, ItemStack two) { if (one == null || two == null) { - return one != two; + return one == two; } if (one.isSimilar(two)) { return true; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java index 16b0adb..ab3f463 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java @@ -234,15 +234,13 @@ public class PartialTransactionModule implements Listener { List resultStock = new ArrayList<>(); int emptySlots = InventoryUtil.countEmpty(inventory); - ItemStack[] itemsInInventory = getItems(stock, inventory); - for (ItemStack item : stock) { + for (ItemStack item : InventoryUtil.mergeSimilarStacks(stock)) { int maxStackSize = InventoryUtil.getMaxStackSize(item); int free = 0; - for (ItemStack itemInInventory : itemsInInventory) { + for (ItemStack itemInInventory : inventory.getContents()) { if (MaterialUtil.equals(item, itemInInventory)) { - free = (maxStackSize - itemInInventory.getAmount()) % maxStackSize; - break; + free += (maxStackSize - itemInInventory.getAmount()) % maxStackSize; } } @@ -250,21 +248,20 @@ public class PartialTransactionModule implements Listener { continue; } - ItemStack clone = item.clone(); if (item.getAmount() > free) { if (emptySlots > 0) { - int requiredSlots = (int) Math.ceil((item.getAmount() - free) / maxStackSize); + int requiredSlots = (int) Math.ceil(((double) item.getAmount() - free) / maxStackSize); if (requiredSlots <= emptySlots) { emptySlots = emptySlots - requiredSlots; } else { + item.setAmount(free + maxStackSize * emptySlots); emptySlots = 0; - clone.setAmount(free + maxStackSize * emptySlots); } } else { - clone.setAmount(free); + item.setAmount(free); } } - resultStock.add(clone); + resultStock.add(item); } return resultStock.toArray(new ItemStack[resultStock.size()]);