InventoryUtils

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

Link copied to clipboard
fun findItem(item: SkyblockItem, inInv: Boolean = false): Int?

Returns the first slot where the specified item is found. Returns null if no matches were found.

fun findItem(vararg attributes: SkyblockItem.Attribute, inInv: Boolean = false): Int?

Returns the first slot where an item with one of the specified attributes is found. Returns null if no matches were found.

fun findItem(inInv: Boolean = false, predicate: (ItemStack?) -> Boolean): Int?

Returns the first slot where the ItemStack matches the predicate or null if no matches were found.

fun findItem(regex: Regex, inInv: Boolean = false, mode: Int = 0): Int?

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.

fun findItem(name: String, ignoreCase: Boolean = false, inInv: Boolean = false, mode: Int = 0): Int?

Returns the first slot where the item name or id passes a check for name. The item name is checked to contain name. The item id is checked for a full match with name. Returns null if no matches were found.

Link copied to clipboard
fun EntityPlayerSP?.isHolding(vararg attributes: SkyblockItem.Attribute): Boolean

Check whether the player is holding an item with one of the specified attributes.

fun EntityPlayerSP?.isHolding(vararg items: SkyblockItem): Boolean

Check whether the player is holding one of the given items. Returns null if no matches were found.

fun EntityPlayerSP?.isHolding(predicate: (ItemStack?) -> Boolean): Boolean

Check whether the held item is matching the predicate.

fun EntityPlayerSP?.isHolding(regex: Regex, mode: Int = 0): Boolean

Check whether the player is holding the given item. Can check both the name and item ID.

fun EntityPlayerSP?.isHolding(vararg names: String, ignoreCase: Boolean = false, mode: Int = 0): Boolean

Check whether the player is holding one of the given items. Can check both the name and item ID.