Minecraft Java Edition Commands – How to Test for a Player’s Height in Minecraft

minecraft-commandsminecraft-java-edition

I'm making a mining turtle-like one command contraption and I need to execute on the turtle when it gets to y=16.

This is the command I use:

scoreboard players tag @e[y=16,dy=0,tag=Bot] remove MiningDown

for some reason it does not work. How do I make it work properly?

Best Answer

The x, y, and z parameters will default to the sender's coordinates (such as the command block's XYZ position) if not defined. Your command will run at the command block's X and Z but with Y set to 16.

To overcome this, you can use /execute to change the origin to that of your intended target, so that XYZ are filled in with their coordinates. The nested command will modify the Y value (or you could use /execute's Y coordinate:

/execute @e[tag=Bot] ~ ~ ~ /scoreboard players tag @e[y=16,dy=0,c=1] remove MiningDown

Or:

/execute @e[tag=Bot] ~ 16 ~ /scoreboard players tag @e[dy=0,c=1] remove MiningDown