From 52732ed4cd529cb88aaa64c902173c713782a831 Mon Sep 17 00:00:00 2001 From: TheMode Date: Fri, 7 May 2021 06:48:13 +0200 Subject: [PATCH] Fix wrong slot being used in left/right click inside the player inventory --- .../server/inventory/PlayerInventory.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/minestom/server/inventory/PlayerInventory.java b/src/main/java/net/minestom/server/inventory/PlayerInventory.java index 1dfa63a6f..840850d5b 100644 --- a/src/main/java/net/minestom/server/inventory/PlayerInventory.java +++ b/src/main/java/net/minestom/server/inventory/PlayerInventory.java @@ -272,38 +272,40 @@ public class PlayerInventory extends AbstractInventory implements EquipmentHandl @Override public boolean leftClick(@NotNull Player player, int slot) { + final int convertedSlot = convertPlayerInventorySlot(slot, OFFSET); final ItemStack cursor = getCursorItem(); - final ItemStack clicked = getItemStack(convertPlayerInventorySlot(slot, OFFSET)); + final ItemStack clicked = getItemStack(convertedSlot); - final InventoryClickResult clickResult = clickProcessor.leftClick(null, player, slot, clicked, cursor); + final InventoryClickResult clickResult = clickProcessor.leftClick(null, player, convertedSlot, clicked, cursor); if (clickResult.doRefresh()) sendSlotRefresh((short) slot, clicked); - setItemStack(slot, OFFSET, clickResult.getClicked()); + setItemStack(convertedSlot, clickResult.getClicked()); setCursorItem(clickResult.getCursor()); if (!clickResult.isCancel()) - callClickEvent(player, null, slot, ClickType.LEFT_CLICK, clicked, cursor); + callClickEvent(player, null, convertedSlot, ClickType.LEFT_CLICK, clicked, cursor); return !clickResult.isCancel(); } @Override public boolean rightClick(@NotNull Player player, int slot) { + final int convertedSlot = convertPlayerInventorySlot(slot, OFFSET); final ItemStack cursor = getCursorItem(); - final ItemStack clicked = getItemStack(slot, OFFSET); + final ItemStack clicked = getItemStack(convertedSlot); - final InventoryClickResult clickResult = clickProcessor.rightClick(null, player, slot, clicked, cursor); + final InventoryClickResult clickResult = clickProcessor.rightClick(null, player, convertedSlot, clicked, cursor); if (clickResult.doRefresh()) sendSlotRefresh((short) slot, clicked); - setItemStack(slot, OFFSET, clickResult.getClicked()); + setItemStack(convertedSlot, clickResult.getClicked()); setCursorItem(clickResult.getCursor()); if (!clickResult.isCancel()) - callClickEvent(player, null, slot, ClickType.RIGHT_CLICK, clicked, cursor); + callClickEvent(player, null, convertedSlot, ClickType.RIGHT_CLICK, clicked, cursor); return !clickResult.isCancel(); }