EffectiveInventoryUtils

Inventory helpers. Item matching uses EffectiveItem.equalByNamespacedKeyIfExistElseByMaterial, so custom items match by their key and vanilla items by material.

Types

Link copied to clipboard

Outcome of giveItem: fully added, or overflow dropped on the ground.

Link copied to clipboard

Outcome of removeItems: all removed, or not enough were present (nothing removed).

Functions

Link copied to clipboard
fun getHandThatHoldItem(player: Player, item: ItemStack): EquipmentSlot?

Which hand holds item (EquipmentSlot.HAND/EquipmentSlot.OFF_HAND), or null if neither.

Link copied to clipboard
fun getItemFromAnotherHandByItemInHand(player: Player, item: ItemStack): ItemStack?

Given that one hand holds item, returns the item in the other hand, or null if neither matches.

Link copied to clipboard
fun getItemFromEquipmentSlot(player: Player, slot: EquipmentSlot): ItemStack?

The item in player's given equipment slot (hands or armor), or null for unsupported slots.

Link copied to clipboard
fun getUsedItemFromHands(player: Player): ItemStack

The main-hand item if not empty, otherwise the off-hand item.

Link copied to clipboard
fun giveItem(item: ItemStack, player: Player): EffectiveInventoryUtils.GiveResult

Gives item to player, dropping any overflow at their feet. Reports whether anything dropped.

Link copied to clipboard
fun hasItems(inventory: Inventory, item: ItemStack, count: Int): Boolean

Whether inventory holds at least count of item (summed across matching stacks).

Link copied to clipboard
fun isFullInventory(inventory: Inventory): Boolean

Whether the inventory's storage slots are all occupied (ignores armor/offhand for player inventories).

Link copied to clipboard
fun removeItems(inventory: Inventory, item: ItemStack, count: Int): EffectiveInventoryUtils.RemoveResult

Removes count of item from inventory; if fewer are present, removes nothing and returns RemoveResult.NOT_ENOUGH.

Link copied to clipboard
fun tryGiveItem(item: ItemStack, player: Player): HashMap<Int, ItemStack>

Adds item to player's inventory; returns the leftover that did not fit (empty if all fit).