mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-23 10:35:15 +01:00
Calculate the amount instead of using a loop (Fixes #78)
This commit is contained in:
parent
e81077143e
commit
61c08a3b18
@ -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()]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user