Count number of each item generically
I've got multiple item_display entities and I'm trying to extract the items from them for a custom crafting system. Importantly, it needs to count items properly as some recipes need to use multiple of one item. I could probably do this with scoreboards per item type that I want to detect, and just check against each item type, but Ideally I'd like to do it more generically so that I don't have to manually set up scoreboard stuff for every new ingredient I want to use. Is there any way to do this?
I've managed to store the items in storage as both an array without slots and a correctly formatted array with slots (I can set the inventory of a chest to contain the items correctly), but the item stacks of the same type aren't merged.
Current:
Continue to help post[{count:1, Slot:1b, id:"minecraft:stick"}, {count:1, Slot:2b, id:"minecraft:stick"}, {count:1, Slot:3b, id:"minecraft:stone"}]
Desired: [{count:2, Slot:1b, id:"minecraft:stick"}, {count:1, Slot:2b, id:"minecraft:stone"}]
The slots aren't important for the output, as long as the stacks are correct. Also note that I'm planning on using some custom items as ingredients, so any merging of item stacks would probably need to be aware of that (i.e. not just merging by id
).