From 61c08a3b185aedb702c6fedcf0ff911a34980abf Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Wed, 25 Oct 2017 15:22:26 +0100 Subject: [PATCH] Calculate the amount instead of using a loop (Fixes #78) --- .../java/com/Acrobot/Breeze/Utils/InventoryUtil.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java b/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java index 0b33230..72ce2f6 100644 --- a/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java +++ b/src/main/java/com/Acrobot/Breeze/Utils/InventoryUtil.java @@ -315,13 +315,16 @@ public class InventoryUtil { return new ItemStack[]{item}; } List items = new LinkedList<>(); - int left = item.getAmount(); - while (left > 0) { + for (int i = 0; i < Math.floor(item.getAmount() / maxStackSize); i++) { ItemStack itemClone = item.clone(); - itemClone.setAmount(left > maxStackSize ? maxStackSize : left); - left -= itemClone.getAmount(); + itemClone.setAmount(maxStackSize); items.add(itemClone); } + if (item.getAmount() % maxStackSize != 0) { + ItemStack rest = item.clone(); + rest.setAmount(item.getAmount() % maxStackSize); + items.add(rest); + } return items.toArray(new ItemStack[items.size()]); } }