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};
}
List<ItemStack> 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()]);
}
}