Update BaseGUI.java

Fixed a bug that didn't let players put items inside a VirtualInventory if the whole stack didn't fit.
This commit is contained in:
NichtStudioCode 2021-07-18 14:17:59 +02:00
parent ac7302d606
commit b465bbc7de

@ -152,21 +152,14 @@ public abstract class BaseGUI implements GUI {
// if the cursor is empty, pick the stack up // if the cursor is empty, pick the stack up
if (inventory.setItemStack(updateReason, slot, null)) if (inventory.setItemStack(updateReason, slot, null))
event.setCursor(clicked); event.setCursor(clicked);
} else if (clicked == null) { } else if (clicked == null || cursor.isSimilar(clicked)) {
// if the clicked slot is empty, place the item on the cursor there // if there are no items or they're similar to the cursor, add the cursor items to the stack
if (inventory.setItemStack(updateReason, slot, cursor)) int remains = inventory.putItemStack(updateReason, slot, cursor);
if (remains == 0) {
event.setCursor(null); event.setCursor(null);
} else if (cursor.isSimilar(clicked)) { } else {
// if the items on the cursor are similar to the clicked ones, add them to the stack cursor.setAmount(remains);
int cursorAmount = cursor.getAmount(); event.setCursor(cursor);
int added = inventory.addItemAmount(updateReason, slot, cursorAmount);
if (added != 0) {
if (added == cursorAmount) {
event.setCursor(null);
} else {
cursor.setAmount(cursorAmount - added);
event.setCursor(cursor);
}
} }
} else if (!cursor.isSimilar(clicked)) { } else if (!cursor.isSimilar(clicked)) {
// if the stacks are not similar, swap them // if the stacks are not similar, swap them