Fixed inventory held click & slot on InventoryCondition

This commit is contained in:
Felix Cravic 2020-04-30 02:42:44 +02:00
parent 4b3e3e8e65
commit 7980ee6ebb
3 changed files with 14 additions and 4 deletions

View File

@ -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());

View File

@ -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);

View File

@ -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;