Fix inventory events not giving the proper inventory/slot

This commit is contained in:
TheMode 2021-08-18 21:08:04 +02:00
parent f26e6ef91f
commit 5cf358ac3c
2 changed files with 11 additions and 9 deletions

View File

@ -267,7 +267,8 @@ public class Inventory extends AbstractInventory implements Viewable {
final boolean isInWindow = isClickInWindow(slot); final boolean isInWindow = isClickInWindow(slot);
final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset); final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset);
final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot); final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot);
final InventoryClickResult clickResult = clickProcessor.leftClick(player, this, slot, clicked, cursor); final InventoryClickResult clickResult = clickProcessor.leftClick(player,
isInWindow ? this : playerInventory, clickSlot, clicked, cursor);
if (clickResult.isCancel()) { if (clickResult.isCancel()) {
updateAll(player); updateAll(player);
return false; return false;
@ -289,7 +290,8 @@ public class Inventory extends AbstractInventory implements Viewable {
final boolean isInWindow = isClickInWindow(slot); final boolean isInWindow = isClickInWindow(slot);
final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset); final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset);
final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot); final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot);
final InventoryClickResult clickResult = clickProcessor.rightClick(player, this, slot, clicked, cursor); final InventoryClickResult clickResult = clickProcessor.rightClick(player,
isInWindow ? this : playerInventory, clickSlot, clicked, cursor);
if (clickResult.isCancel()) { if (clickResult.isCancel()) {
updateAll(player); updateAll(player);
return false; return false;
@ -337,7 +339,8 @@ public class Inventory extends AbstractInventory implements Viewable {
final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset); final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset);
final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot); final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot);
final ItemStack heldItem = playerInventory.getItemStack(key); final ItemStack heldItem = playerInventory.getItemStack(key);
final InventoryClickResult clickResult = clickProcessor.changeHeld(player, this, slot, key, clicked, heldItem); final InventoryClickResult clickResult = clickProcessor.changeHeld(player,
isInWindow ? this : playerInventory, clickSlot, key, clicked, heldItem);
if (clickResult.isCancel()) { if (clickResult.isCancel()) {
updateAll(player); updateAll(player);
return false; return false;
@ -368,8 +371,8 @@ public class Inventory extends AbstractInventory implements Viewable {
final ItemStack clicked = outsideDrop ? final ItemStack clicked = outsideDrop ?
ItemStack.AIR : (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot)); ItemStack.AIR : (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot));
final ItemStack cursor = getCursorItem(player); final ItemStack cursor = getCursorItem(player);
final InventoryClickResult clickResult = clickProcessor.drop(player, this, final InventoryClickResult clickResult = clickProcessor.drop(player,
all, slot, button, clicked, cursor); isInWindow ? this : playerInventory, all, clickSlot, button, clicked, cursor);
if (clickResult.isCancel()) { if (clickResult.isCancel()) {
updateAll(player); updateAll(player);
return false; return false;
@ -395,8 +398,9 @@ public class Inventory extends AbstractInventory implements Viewable {
(isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot)) : (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot)) :
ItemStack.AIR; ItemStack.AIR;
final ItemStack cursor = getCursorItem(player); final ItemStack cursor = getCursorItem(player);
final InventoryClickResult clickResult = clickProcessor.dragging(player, this, final InventoryClickResult clickResult = clickProcessor.dragging(player,
slot, button, isInWindow ? this : playerInventory,
clickSlot, button,
clicked, cursor, clicked, cursor,
s -> isClickInWindow(s) ? getItemStack(s) : s -> isClickInWindow(s) ? getItemStack(s) :

View File

@ -6,7 +6,6 @@ import net.minestom.server.listener.manager.PacketListenerManager;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public abstract class ClientPlayPacket implements ClientPacket { public abstract class ClientPlayPacket implements ClientPacket {
private static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager(); private static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager();
/** /**
@ -19,5 +18,4 @@ public abstract class ClientPlayPacket implements ClientPacket {
public void process(@NotNull Player player) { public void process(@NotNull Player player) {
PACKET_LISTENER_MANAGER.processClientPacket(this, player); PACKET_LISTENER_MANAGER.processClientPacket(this, player);
} }
} }