mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-13 11:41:52 +01:00
Fixed inventory held click & slot on InventoryCondition
This commit is contained in:
parent
4b3e3e8e65
commit
7980ee6ebb
@ -267,7 +267,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset);
|
||||
ItemStack heldItem = playerInventory.getItemStack(key);
|
||||
|
||||
InventoryClickResult clickResult = clickProcessor.changeHeld(getInventoryConditions(), player, slot, clicked, heldItem);
|
||||
InventoryClickResult clickResult = clickProcessor.changeHeld(getInventoryConditions(), player, slot, key, clicked, heldItem);
|
||||
|
||||
if (clickResult.doRefresh())
|
||||
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
||||
|
@ -55,7 +55,12 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
|
||||
@Override
|
||||
public void addInventoryCondition(InventoryCondition inventoryCondition) {
|
||||
this.inventoryConditions.add(inventoryCondition);
|
||||
InventoryCondition condition = (p, slot, clickType, inventoryConditionResult) -> {
|
||||
slot = convertSlot(slot, OFFSET);
|
||||
inventoryCondition.accept(p, slot, clickType, inventoryConditionResult);
|
||||
};
|
||||
|
||||
this.inventoryConditions.add(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -360,7 +365,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
ItemStack heldItem = getItemStack(key);
|
||||
ItemStack clicked = getItemStack(slot, OFFSET);
|
||||
|
||||
InventoryClickResult clickResult = clickProcessor.changeHeld(getInventoryConditions(), player, slot, clicked, heldItem);
|
||||
InventoryClickResult clickResult = clickProcessor.changeHeld(getInventoryConditions(), player, slot, key, clicked, heldItem);
|
||||
|
||||
if (clickResult.doRefresh())
|
||||
sendSlotRefresh((short) slot, clicked);
|
||||
|
@ -116,13 +116,18 @@ public class InventoryClickProcessor {
|
||||
return clickResult;
|
||||
}
|
||||
|
||||
public InventoryClickResult changeHeld(List<InventoryCondition> inventoryConditions, Player player, int slot, ItemStack clicked, ItemStack cursor) {
|
||||
public InventoryClickResult changeHeld(List<InventoryCondition> inventoryConditions, Player player, int slot, int key, ItemStack clicked, ItemStack cursor) {
|
||||
InventoryClickResult clickResult = startCondition(inventoryConditions, player, slot, ClickType.CHANGE_HELD, clicked, cursor);
|
||||
|
||||
if (clickResult.isCancel()) {
|
||||
return clickResult;
|
||||
}
|
||||
|
||||
clickResult = startCondition(clickResult, inventoryConditions, player, key, ClickType.CHANGE_HELD, clicked, cursor);
|
||||
if (clickResult.isCancel()) {
|
||||
return clickResult;
|
||||
}
|
||||
|
||||
if (cursor.isAir() && clicked.isAir()) {
|
||||
clickResult.setCancel(true);
|
||||
return clickResult;
|
||||
|
Loading…
Reference in New Issue
Block a user