Calculate the amount instead of using a loop (Fixes #78)

This commit is contained in:
Phoenix616 2017-10-25 15:22:26 +01:00
parent e81077143e
commit 61c08a3b18

View File

@ -315,13 +315,16 @@ public class InventoryUtil {
return new ItemStack[]{item}; return new ItemStack[]{item};
} }
List<ItemStack> items = new LinkedList<>(); List<ItemStack> items = new LinkedList<>();
int left = item.getAmount(); for (int i = 0; i < Math.floor(item.getAmount() / maxStackSize); i++) {
while (left > 0) {
ItemStack itemClone = item.clone(); ItemStack itemClone = item.clone();
itemClone.setAmount(left > maxStackSize ? maxStackSize : left); itemClone.setAmount(maxStackSize);
left -= itemClone.getAmount();
items.add(itemClone); 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()]); return items.toArray(new ItemStack[items.size()]);
} }
} }