(Java Minecraft 1.13) How to test for if a beacon is activated?
I would like to use execute as @e[type=item,nbt={Item:{id:"minecraft:nether_star", Count:1b}}] at @s if block ~ ~-1 ~ minecraft:beacon run...
but only if the beacon is activated. Is there a way to do this without checking every block of the underlying structure to make sure it is complete? Basically, what is the id/nbt of a Beacon which can be used to test for if it is activated?
For NBT questions the Minecraft wiki page "Chunk format" (archive) always helps. It can tell you that the "Level
" tag of a beacon stores the number of layers of the pyramid that are available to it (with the usual small delay), "Primary
" stores the first and "Secondary
" the second status effect.
So you can do something based on that check like this:
/execute if block ~ ~ ~ beacon{Level:1} run <command>
But that only works for a single value, not all four. You could use execute store
with data get
to put it into a scoreboard, then you could check for a range, but since you are only interested in "not 0", you can use this:
/execute if block ~ ~ ~ beacon unless block ~ ~ ~ beacon{Level:0} run <command>
This would in theory also select beacons without the Level
tag, but that doesn't happen unless it's explicitly removed with commands (or the world gets corrupted or whatever).
If you want to check for the effect instead, you can do something like this:
/execute if block ~ ~ ~ beacon unless block ~ ~ ~ beacon{Primary:{Id:0b}}
The value 0 in a beacon's effect ID means "no effect".