M BUZZ CRAZE NEWS
// news

How to see if a chest been emptied by the player

By Joseph Russell

I would like to make a command that checks if a chest have been emptied by the player. If the chest is empty, I want to run this command:

/setblock x y z 
1

2 Answers

When you test for an empty list (e.g. Items:[]), it will only match if the target had an empty list as well.

The following only outputs if the chest had no items:

/testforblock ~ ~1 ~ minecraft:chest -1 {Items:[]}

A comparator will emit a redstone signal of strength directly proportional to how much "stuff" there is in an inventory it is facing away from. Simply put a camparator coming from the chest and send it into a NOT gate and use that to trigger the command block. When the chest is empty it will trigger the command but if there is at least 1 item in the chest it will output the signal and so not trigger the command block.

One thing to note is that the /setblock command may not trigger the block update so you could have your output also go to a piston after a delay to move a block top trigger the update.