I was trying to detect whether a player had a certain amount of items in their inventory.

I can detect if a player has an item in their inventory like this:

/execute as @a[nbt={Inventory:[{id:"minecraft:command_block"}]}] run say hi

But I thought there was a Count tag too. So I tried this, but it doesn't work:

/execute as @a[nbt={Inventory:[{id:"minecraft:command_block",Count:5}]}] run say hi

Is there a way to make this work?


NBT setting can often be done without types, namespaces or similar, but testing has to be exact:

/execute as @a[nbt={Inventory:[{id:"minecraft:command_block",Count:5b}]}]

Also, keep in mind that this will not match a player with e.g. one stack of 2 and one stack with 3 command blocks.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.