Working on a datapack. Is it possible to detect if a barrel or dropper/dispenser is empty?
(This seems like a silly question...)
(This seems like a silly question...)
4
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 :)
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 :)
It works, thanks for the help!
No problem, happy to be of service
3 years later and a google search away. This solution was exactly what I needed for my game. Thank you! :)
