2

Empty container detection

Avitopia 4/30/20 12:57 pm
1.3k
8/13/2023 4:17 pm
Working on a datapack. Is it possible to detect if a barrel or dropper/dispenser is empty?

(This seems like a silly question...)
Posted by
Avitopia
Level 5 : Apprentice Artist
7

  Have something to say?

JoinSign in

4

ElectroSheep_
05/04/2020 12:02 am
Level 43 : Master Procrastinator
history
Yes this is possible.

For example a chest at the coordinates: 3, 3, 3

To run a command only if it's empty you'd use:

/execute if block 3 3 3 chest{Items:[]} run [​Command]


The way that works is that is tests for the "Items" tag having no data stored in it (the chest being empty), only then will it run the command.
If there is anything in those square brackets such as "Items:[{id:"minecraft:stone",Count:1b}] then the test will fail and the command won't be run.


As far as I know, all containers such as chests, droppers, etc all use that same "Items" tag

Hope this helps :)
3
Avitopia
05/04/2020 6:02 pm
Level 5 : Apprentice Artist
It works, thanks for the help!
3
ElectroSheep_
05/04/2020 6:43 pm
Level 43 : Master Procrastinator
No problem, happy to be of service
2
Antimony_Sb
08/13/2023 4:17 pm
Level 1 : New System
3 years later and a google search away. This solution was exactly what I needed for my game. Thank you! :)
1

Welcome