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?
-
Do you mean "active" as in "shining light" or as in "providing selected status effect"?– Fabian RölingCommented Apr 16, 2019 at 6:19
-
@FabianRöling As in shining light.– Nik3141Commented Apr 16, 2019 at 6:28
-
I just answered for both cases now, that's more helpful for future readers and it's almost the same anyway. I did this all just from memory and the wiki, so please tell me if one of the commands isn't working right.– Fabian RölingCommented Apr 16, 2019 at 6:54
1 Answer
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".
-
Update in 1.14.0: The "Level" tag is broken currently, so you would have to check every block and every possible variant. Commented Apr 28, 2019 at 20:54