From b465bbc7deb60b0db434b06f6b7b127a8338a7be Mon Sep 17 00:00:00 2001 From: NichtStudioCode <51272202+NichtStudioCode@users.noreply.github.com> Date: Sun, 18 Jul 2021 14:17:59 +0200 Subject: [PATCH] Update BaseGUI.java Fixed a bug that didn't let players put items inside a VirtualInventory if the whole stack didn't fit. --- .../de/studiocode/invui/gui/impl/BaseGUI.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/InvUI/src/main/java/de/studiocode/invui/gui/impl/BaseGUI.java b/InvUI/src/main/java/de/studiocode/invui/gui/impl/BaseGUI.java index 611127f..2f82028 100644 --- a/InvUI/src/main/java/de/studiocode/invui/gui/impl/BaseGUI.java +++ b/InvUI/src/main/java/de/studiocode/invui/gui/impl/BaseGUI.java @@ -152,21 +152,14 @@ public abstract class BaseGUI implements GUI { // if the cursor is empty, pick the stack up if (inventory.setItemStack(updateReason, slot, null)) event.setCursor(clicked); - } else if (clicked == null) { - // if the clicked slot is empty, place the item on the cursor there - if (inventory.setItemStack(updateReason, slot, cursor)) + } else if (clicked == null || cursor.isSimilar(clicked)) { + // if there are no items or they're similar to the cursor, add the cursor items to the stack + int remains = inventory.putItemStack(updateReason, slot, cursor); + if (remains == 0) { event.setCursor(null); - } else if (cursor.isSimilar(clicked)) { - // if the items on the cursor are similar to the clicked ones, add them to the stack - int cursorAmount = cursor.getAmount(); - 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 { + cursor.setAmount(remains); + event.setCursor(cursor); } } else if (!cursor.isSimilar(clicked)) { // if the stacks are not similar, swap them