Fixed VirtualInventory#addItem

This commit is contained in:
NichtStudioCode 2021-06-15 21:09:40 +02:00
parent 31ebfb4bb8
commit a721a8c028

@ -447,19 +447,21 @@ public class VirtualInventory implements ConfigurationSerializable {
// find all slots where the item partially fits and add it there // find all slots where the item partially fits and add it there
for (int partialSlot : findPartialSlots(itemStack)) { for (int partialSlot : findPartialSlots(itemStack)) {
if (amountLeft == 0) break;
ItemStack stackToPut = itemStack.clone(); ItemStack stackToPut = itemStack.clone();
stackToPut.setAmount(amountLeft); stackToPut.setAmount(amountLeft);
amountLeft = putItemStack(updateReason, partialSlot, stackToPut); amountLeft = putItemStack(updateReason, partialSlot, stackToPut);
if (amountLeft == 0) break;
} }
// find all empty slots and put the item there // find all empty slots and put the item there
for (int emptySlot : ArrayUtils.findEmptyIndices(items)) { for (int emptySlot : ArrayUtils.findEmptyIndices(items)) {
if (amountLeft == 0) break;
ItemStack stackToPut = itemStack.clone(); ItemStack stackToPut = itemStack.clone();
stackToPut.setAmount(amountLeft); stackToPut.setAmount(amountLeft);
amountLeft = putItemStack(updateReason, emptySlot, stackToPut); amountLeft = putItemStack(updateReason, emptySlot, stackToPut);
if (amountLeft == 0) break;
} }
// if items have been added, notify windows // if items have been added, notify windows
@ -513,14 +515,17 @@ public class VirtualInventory implements ConfigurationSerializable {
// find all slots where the item partially fits // find all slots where the item partially fits
for (int partialSlot : findPartialSlots(itemStack)) { for (int partialSlot : findPartialSlots(itemStack)) {
if (amountLeft == 0) break;
ItemStack partialItem = items[partialSlot]; ItemStack partialItem = items[partialSlot];
int maxStackSize = getMaxStackSize(partialSlot, -1); int maxStackSize = getMaxStackSize(partialSlot, -1);
amountLeft = Math.max(0, amountLeft - (maxStackSize - partialItem.getAmount())); amountLeft = Math.max(0, amountLeft - (maxStackSize - partialItem.getAmount()));
if (amountLeft == 0) break;
} }
// remaining items would be added to empty slots // remaining items would be added to empty slots
for (int emptySlot : ArrayUtils.findEmptyIndices(items)) { for (int emptySlot : ArrayUtils.findEmptyIndices(items)) {
if (amountLeft == 0) break;
int maxStackSize = getMaxStackSize(emptySlot, itemStack.getMaxStackSize()); int maxStackSize = getMaxStackSize(emptySlot, itemStack.getMaxStackSize());
amountLeft -= Math.min(amountLeft, maxStackSize); amountLeft -= Math.min(amountLeft, maxStackSize);
} }