Minecraft – Testforblock – Chest with a specific amount of items in it

minecraft-commandsminecraft-java-edition

I tried to test for a chest containing 10 coal. When I tried this, it didn't work:

testforblock ~-1 ~ ~ minecraft:chest -1 {Items:[{Slot:0b,id:"minecraft:coal"}],Count:10b,Damage:0s}

It only works when I test for 1 coal, but then, I have to drop the Count and Damage tag. I want to test for 10 coal in a chest, not just for one.

Best Answer

Use this command instead:

testforblock ~-1 ~ ~ minecraft:chest -1 {Items:[{Slot:0b,id:"minecraft:coal",Count:10b,Damage:0s}]} 

This works because the Count and Damage keys must be between the same brackets (in the same object and the same array) as the id key.

Note, if you want to test for the items in any of the inventory's slots, remove the Slot key.