mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-23 18:45:31 +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};
|
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()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user