Because you still need to have context with your inventory. For example, take a look at this representation of the MainPlayerInventory, which contains the main storage and player’s hotbar.
| | | | | | | | | |
|-|-|-|-|-|-|-|-|-|-|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| | | | | | | | | |
| 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
This inventory actually contains two inventories, so we’ll number those as well.
| | | | | | | | | |
|-|-|-|-|-|-|-|-|-|-|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| | | | | | | | | |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Additionally, this can be extended to row and column InventoryAdapters, but my understanding is that should only exist as the result of a query.
The order returned by
inventory.slots()is the same order slots are indexed in.
Notice that the SlotIndex 1 exists in three inventories - the MainPlayerInventory, GridInventory, and Hotbar. When you query for an index, it matches all the slots available - which, as I’ve mentioned above, returns an InventoryAdapter containing the three slots (though actually two as they overlap). To retrieve the actual result, you need to get it from that adapter.
Inventory inv;
Inventory result = inv.query(SlotIndex.of(1)); //Theoretically an adapter
Slot slot = result.first(); //The first slot or empty inventory
There are two takeaway points from this, first of which is context is key. Minecraft stores the inventory as a list of slots, so the fact that we have an API available to separate this into different containers and views is pretty remarkable in itself. However, the API can only provide context to a certain extent, so you need to understand what you’re working with and meet it the rest of the way.
I’ve also said this before, but please include information about what you’re doing. As much as I’d like to be a master of ESP I’m not, so for myself and others to know what you’re doing you’ll have to provide details. In 90% of cases, the most important piece of this is the code you’re using. You can either post it with code blocks here if it’s short-ish, or attach a gist with it if it becomes rather lengthy - but having it saves everyone time.