Fix incorrect held click slot

This commit is contained in:
TheMode 2021-08-11 19:51:08 +02:00
parent 5714d9db79
commit 5607652378

View File

@ -131,19 +131,12 @@ public class InventoryClickProcessor {
@NotNull @NotNull
public InventoryClickResult changeHeld(@Nullable Inventory inventory, @NotNull Player player, int slot, int key, public InventoryClickResult changeHeld(@Nullable Inventory inventory, @NotNull Player player, int slot, int key,
@NotNull ItemStack clicked, @NotNull ItemStack cursor) { @NotNull ItemStack clicked, @NotNull ItemStack cursor) {
// Verify the clicked item
InventoryClickResult clickResult = startCondition(inventory, player, slot, ClickType.CHANGE_HELD, clicked, cursor); InventoryClickResult clickResult = startCondition(inventory, player, slot, ClickType.CHANGE_HELD, clicked, cursor);
if (clickResult.isCancel()) return clickResult;
if (clickResult.isCancel()) { // Verify the destination (held bar)
return clickResult; clickResult = startCondition(null, player, key, ClickType.CHANGE_HELD, clicked, cursor);
} if (clickResult.isCancel()) return clickResult;
// Converted again during the inventory condition calling to internal slot
final int keySlot = PlayerInventoryUtils.convertToPacketSlot(key);
clickResult = startCondition(null, player, keySlot, ClickType.CHANGE_HELD, clicked, cursor);
if (clickResult.isCancel()) {
return clickResult;
}
if (cursor.isAir() && clicked.isAir()) { if (cursor.isAir() && clicked.isAir()) {
clickResult.setCancel(true); clickResult.setCancel(true);
@ -152,7 +145,6 @@ public class InventoryClickProcessor {
ItemStack resultClicked; ItemStack resultClicked;
ItemStack resultHeld; ItemStack resultHeld;
if (clicked.isAir()) { if (clicked.isAir()) {
// Set held item [key] to slot // Set held item [key] to slot
resultClicked = cursor; resultClicked = cursor;
@ -162,16 +154,14 @@ public class InventoryClickProcessor {
// if held item [key] is air then set clicked to held // if held item [key] is air then set clicked to held
resultClicked = ItemStack.AIR; resultClicked = ItemStack.AIR;
} else { } else {
// Otherwise replace held item and held // Otherwise, replace held item and held
resultClicked = cursor; resultClicked = cursor;
} }
resultHeld = clicked; resultHeld = clicked;
} }
clickResult.setClicked(resultClicked); clickResult.setClicked(resultClicked);
clickResult.setCursor(resultHeld); clickResult.setCursor(resultHeld);
return clickResult; return clickResult;
} }