How to see if a chest been emptied by the player

How to see if a chest been emptied by the player - Hand of man with racket and ball on tennis table

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 


Best Answer

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:[]}



Pictures about "How to see if a chest been emptied by the player"

How to see if a chest been emptied by the player - Interior of light bedroom with soft bed in front of chest of drawers with TV near windows with light curtains
How to see if a chest been emptied by the player - Brown Wooden Storage Box on White Box
How to see if a chest been emptied by the player - Girl with a Phrase on her T-shirt



How do you make a NBT chest in Minecraft?

Then you need to tell when the player leaves the chest which can't really be done, but you can tell when the player starts to move. However, you need to test for if the player walks, sprints, crouches, climbs, or jumps. Otherwise, the player could break the system.

How do you detect if a player opens a chest?

For Java Edition (PC/Mac), right click on the large chest. For Pocket Edition (PE), you tap on the large chest. For Xbox 360 and Xbox One, press the LT button on the Xbox controller. For PS3 and PS4, press the L2 button on the PS controller.

How do you close a chest in Minecraft?

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.



How to see into another persons Ender Chest in Minecraft




More answers regarding how to see if a chest been emptied by the player

Answer 2

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.

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Andrea Piacquadio, Max Vakhtbovych, Pixabay, Karolina Grabowska