Minecraft Test If A Chest Contains An Item
Solution 1:
You can use
/testforblock x y z minecraft:chest -1 {Items:[{}]}
Note the extra {}
in the Items
list. {Items:[{}]}
checks if the list of item tags contains an item that matches all the tags present in {}
. Obviously, {}
does not contain any tags, meaning every item in the game matches this1.
You can achieve the opposite behavior using {Items:[]}
, which will test for an empty list of items.
1 Technically, everything matches {}
, including Creepers, but the Items
tag limits the scope for us.