1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Check inv maxStackSize

As mentioned in CS-CoreLib2's #141 and #142 PR's, previous iterations of Slimefun AContainers would not consider the underlying Inventory's max stack size when determining sizing or pushing items. This commit changes DirtyChestMenus to act similarly by storing a variable defined as the lower of the Inventory's max stack size and the ItemStack's max stack size in a slot.
This commit is contained in:
Keaton 2021-01-22 13:40:01 -06:00 committed by GitHub
parent 1169896034
commit 76a0ea1fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,15 +105,18 @@ public class DirtyChestMenu extends ChestMenu {
if (stack == null) {
replaceExistingItem(slot, item);
return null;
} else if (stack.getAmount() < stack.getMaxStackSize()) {
if (wrapper == null) {
wrapper = new ItemStackWrapper(item);
}
} else {
int maxStackSize = Math.min(stack.getMaxStackSize(), toInventory().getMaxStackSize());
if (stack.getAmount() < maxStackSize) {
if (wrapper == null) {
wrapper = new ItemStackWrapper(item);
}
if (ItemUtils.canStack(wrapper, stack)) {
amount -= (stack.getMaxStackSize() - stack.getAmount());
stack.setAmount(Math.min(stack.getAmount() + item.getAmount(), stack.getMaxStackSize()));
item.setAmount(amount);
if (ItemUtils.canStack(wrapper, stack)) {
amount -= (maxStackSize - stack.getAmount());
stack.setAmount(Math.min(stack.getAmount() + item.getAmount(), maxStackSize));
item.setAmount(amount);
}
}
}
}