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

View File

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