Detect if the player is at a specific y level in 1.14

Solution 1:

You can set up a scoreboard objective with this command:

/scoreboard objectives add yPos dummy

Then you run this command to update the height with very high precision, I recommend using this in a repeating command block:

/execute as <target> store result score @s yPos run data get entity @s Pos[1] 1000000

And finally to make every target at a very specific y-level say hi you can use this command:

/execute as @e[scores={yPos=70000000}] run say hi

In this particular case it would be for any entity standing at a y-level of exactly 70.

This solution is multiplayer friendly and works for non-player entities, too.

Solution 2:

You can use this code:

/execute as <player you want to check> at @s if entity @s[y=65,dy=0] run say hi

It will say hi if the hitbox of the player is within the block at y=65. the dy=0 appears to be nessessary to prevent it from always saying hi, the x and z seem to default to the position where the command is executed.

This would probably work, too:

/execute at <player you want to check> if entity @p[y=65,dy=0] run say hi

Solution 3:

I found the next 1 line command to be working. First, execute as all players, then as all players that are at y=10 with dy=0.

/execute as @p as @s[y=10,dy=0] run tellraw @s "Test"

One thing I found is that y seems to be where any part of the player is.