Inventory Utils
A collection of methods for finding items in inventories.
About slot numbering
Minecraft uses different numbering systems for slots in inventories. Depending on which methods are used each slot can have different indices. There are two main systems for numbering the slots in an inventory. One is used by the Container in GuiContainer classes and the other system is used when the inventory is accessed directly such as in InventoryPlayer.
The indices for the inventory slots of the GuiInventory do not match the indices of InventoryPlayer!
The difference mostly affects the numbering of the players hotbar.
Container style numbering
When the players inventory is accessed through the corresponding Container like when GuiInventory.inventorySlots is used, the crafting and armor slots are included. Numbering starts at the inventory crafting slot with numbers 0..4. Next come the armor slots taking numbers 5..8 starting with 5 at the helmet and then going down. And finally the main inventory uses the indices 9..44 starting top left, where the hot-bar comes last.
InventoryPlayer style numbering.
InventoryPlayer treats the armor slots separately from the main inventory and does not support the crafting slots (since no items can be stored there). Methods such as InventoryPlayer.getStackInSlot use the field InventoryPlayer.mainInventory which only contains the 36 slots of the players main inventory. Here the numbering starts at the hot-bar, which uses indices 0..8 left to right. After that comes the rest of the inventory again starting top left.
The indices for the non-visible inventory slots are the same in both numbering systems: 9..35.
Numbering in the Chest gui.
Chests use the Container style numbering system. Numbering starts at 0 at the top left slot of the chest inventory.
Author
Aton
See also
Functions
Returns the first slot where the specified item is found. Returns null if no matches were found.
Returns the first slot where an item with one of the specified attributes is found. Returns null if no matches were found.
Returns the first slot where the ItemStack matches the predicate or null if no matches were found.
Returns the first slot where the item name or id passes a check for the regex. The item name is checked to contain the regex. The item id is checked for a full match. Returns null if no matches were found.
Check whether the player is holding an item with one of the specified attributes.
Check whether the player is holding one of the given items. Returns null if no matches were found.
Check whether the held item is matching the predicate.
Check whether the player is holding the given item. Can check both the name and item ID.
Check whether the player is holding one of the given items. Can check both the name and item ID.