Fix double click result handling

This commit is contained in:
Matt Worzala 2021-01-02 04:40:24 -05:00
parent 4d2dd7d256
commit 1f60330abe
No known key found for this signature in database
GPG Key ID: 046D16088BA8F7DD
2 changed files with 8 additions and 12 deletions

View File

@ -405,7 +405,8 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
} }
if (isInWindow) { if (isInWindow) {
setItemStack(slot, clickResult.getClicked()); // if (clickResult.isCancel())
setItemStack(slot, clickResult.getClicked());
} else { } else {
playerInventory.setItemStack(slot, offset, clickResult.getClicked()); playerInventory.setItemStack(slot, offset, clickResult.getClicked());
} }
@ -564,7 +565,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
public boolean dragging(@NotNull Player player, int slot, int button) { public boolean dragging(@NotNull Player player, int slot, int button) {
final PlayerInventory playerInventory = player.getInventory(); final PlayerInventory playerInventory = player.getInventory();
final boolean isInWindow = isClickInWindow(slot); final boolean isInWindow = isClickInWindow(slot);
final ItemStack clicked = slot != 999 ? final ItemStack clicked = slot != -999 ?
(isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset)) : (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset)) :
ItemStack.getAirItem(); ItemStack.getAirItem();
final ItemStack cursor = getCursorItem(player); final ItemStack cursor = getCursorItem(player);
@ -611,13 +612,8 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
// Looping through player inventory // Looping through player inventory
new InventoryClickLoopHandler(0, PlayerInventory.INVENTORY_SIZE - 9, 1, new InventoryClickLoopHandler(0, PlayerInventory.INVENTORY_SIZE - 9, 1,
PlayerInventoryUtils::convertToPacketSlot, PlayerInventoryUtils::convertToPacketSlot,
index -> playerInventory.getItemStack(index, offset), index -> playerInventory.getItemStack(index, 9),
(index, itemStack) -> playerInventory.setItemStack(index, offset, itemStack)), (index, itemStack) -> playerInventory.setItemStack(index, 9, itemStack)));
// Player hot bar
new InventoryClickLoopHandler(0, 9, 1,
PlayerInventoryUtils::convertToPacketSlot,
index -> playerInventory.getItemStack(index, offset),
(index, itemStack) -> playerInventory.setItemStack(index, offset, itemStack)));
if (clickResult == null) if (clickResult == null)
return false; return false;

View File

@ -49,7 +49,7 @@ public final class PlayerInventoryUtils {
case 8: case 8:
return BOOTS_SLOT; return BOOTS_SLOT;
} }
//System.out.println("ENTRY: " + slot + " | " + offset); System.out.println("ENTRY: " + slot + " | " + offset);
final int rowSize = 9; final int rowSize = 9;
slot -= offset; slot -= offset;
if (slot >= rowSize * 3 && slot < rowSize * 4) { if (slot >= rowSize * 3 && slot < rowSize * 4) {
@ -57,7 +57,7 @@ public final class PlayerInventoryUtils {
} else { } else {
slot = slot + rowSize; slot = slot + rowSize;
} }
//System.out.println("CONVERT: " + slot); System.out.println("CONVERT: " + slot);
return slot; return slot;
} }
@ -68,7 +68,7 @@ public final class PlayerInventoryUtils {
* @return a slot id which can be used for packets * @return a slot id which can be used for packets
*/ */
public static int convertToPacketSlot(int slot) { public static int convertToPacketSlot(int slot) {
if (slot > -1 && slot < 9) { // Held bar 0-9 if (slot > -1 && slot < 9) { // Held bar 0-8
slot = slot + 36; slot = slot + 36;
} else if (slot > 8 && slot < 36) { // Inventory 9-35 } else if (slot > 8 && slot < 36) { // Inventory 9-35
slot = slot; slot = slot;