Minecraft – Scoreboard / test for one of multiple stacks

minecraft-commandsminecraft-java-edition

I want to test if a player has any dirt or sand on him, both with a count of 2. So I tested this command:

/testfor @a {Inventory:[{id:"minecraft:dirt",Count:2b},{id:"minecraft:glass",Count:2b},{id:"minecraft:stone",Count:2b},{id:"minecraft:planks",Count:2b}]}

But the problem is that it will only give an output if you have all the items. I want it to give an output if it have 1 of the items with a count of 2.

If you can do this with scoreboard it would be better. But I haven't found out yet how to do that.

Best Answer

Pretty much everything command related in Minecraft is AND connected, not OR. That's because you can do OR connections with multiple commands. For example:

/scoreboard players tag @a add hasItem {Inventory:[{id:"minecraft:dirt",Count:2b}]}
/scoreboard players tag @a add hasItem {Inventory:[{id:"minecraft:glass",Count:2b}]}
/scoreboard players tag @a add hasItem {Inventory:[{id:"minecraft:stone",Count:2b}]}
/scoreboard players tag @a add hasItem {Inventory:[{id:"minecraft:planks",Count:2b}]}

/execute @a[tag=hasItem] ~ ~ ~ say hi