mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-27 18:41:22 +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 clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset);
|
||||||
ItemStack heldItem = playerInventory.getItemStack(key);
|
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())
|
if (clickResult.doRefresh())
|
||||||
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
||||||
|
@ -55,7 +55,12 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInventoryCondition(InventoryCondition inventoryCondition) {
|
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
|
@Override
|
||||||
@ -360,7 +365,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||||||
ItemStack heldItem = getItemStack(key);
|
ItemStack heldItem = getItemStack(key);
|
||||||
ItemStack clicked = getItemStack(slot, OFFSET);
|
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())
|
if (clickResult.doRefresh())
|
||||||
sendSlotRefresh((short) slot, clicked);
|
sendSlotRefresh((short) slot, clicked);
|
||||||
|
@ -116,13 +116,18 @@ public class InventoryClickProcessor {
|
|||||||
return clickResult;
|
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);
|
InventoryClickResult clickResult = startCondition(inventoryConditions, player, slot, ClickType.CHANGE_HELD, clicked, cursor);
|
||||||
|
|
||||||
if (clickResult.isCancel()) {
|
if (clickResult.isCancel()) {
|
||||||
return clickResult;
|
return clickResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clickResult = startCondition(clickResult, inventoryConditions, player, key, 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);
|
||||||
return clickResult;
|
return clickResult;
|
||||||
|
Loading…
Reference in New Issue
Block a user