The NBT path Inventory returns an ordered array of items in the villager's inventory, but as it does not return empty slots, accessing an item via Inventory[1] will not consistently return the item in slot 1.
[23:28:31] [main/INFO]: [CHAT] [Carrot] Pre
[23:28:31] [main/INFO]: [CHAT] Villager has [{id:"minecraft:bread",Count:52b},{id:"minecraft:potato",Count:3b},{id:"minecraft:beetroot",Count:4b}] and item is {id:"minecraft:carrot",Count:19b}
[23:28:31] [main/INFO]: [CHAT] [Carrot] Post
[23:28:31] [main/INFO]: [CHAT] Villager has [{id:"minecraft:bread",Count:52b},{id:"minecraft:carrot",Count:22b},{id:"minecraft:potato",Count:3b},{id:"minecraft:beetroot",Count:4b}] and item is
In the above example, the villager had no carrots in slot 1, and 3 potato in slot 2. Inventory[1] returned the potato in slot 2 (Count:3b) and added that up with the carrots from the item stack (Count:19b), and finally added 22 carrots to slot 1.
There does not seem to be an alternative for reading the item from a specific slot.
May need to check all items in the Inventory to see if any match the item type we are looking for.
https://github.com/zedwick/VillagerItemCollector/blob/e9c7010b1a76e0cff29b3d25c57d04db9dba44b2/VillagerItemCollector/data/villager_item_collector/functions/villager_food_item_carrot.mcfunction#L12
The NBT path
Inventory
returns an ordered array of items in the villager's inventory, but as it does not return empty slots, accessing an item viaInventory[1]
will not consistently return the item in slot 1.In the above example, the villager had no carrots in slot 1, and 3 potato in slot 2.
Inventory[1]
returned the potato in slot 2 (Count:3b) and added that up with the carrots from the item stack (Count:19b), and finally added 22 carrots to slot 1.There does not seem to be an alternative for reading the item from a specific slot.
May need to check all items in the Inventory to see if any match the item type we are looking for.