#How to detect if a player is below or above a specific Y level

1 messages · Page 1 of 1 (latest)

vocal epoch
#

This might be a long one but here me out, I'm making an underwater ocean exploration addon and I want to make the ocean dark when the player reaches a specific Y level in water, for that I use fog, the command works when I reach the specified height the fog appears and when I leave water, the fog disappears but here's a slight issue, when I'm above the specified
Y level the fog doesn't stop until I'm fully out of water, how do I fix this? for reference here is the command I'm using
When submerged in water:
/execute as @a at @s if entity @s[x=~, y= 41, z=~, dx=0, dy=-106, dz=0] if block ~~1~ water run fog @s push minecraft:fog_soulsand_valley Soul

When out of water:
/execute as @a at @s if entity @s[x=~, y= 100, z=~, dx=0, dy=-165, dz=0] if block ~~1~ air run fog @s remove Soul

white light
#

Your y-coordinate ranges overlap. Is that intentional? IMO it would make more sense and behave better if the two regions were distinct—give this a try and let me know if the issue persists.

execute as @a at @s if entity @s[y=41,dy=-106] if block ~ ~1 ~ water run fog @s push minecraft:fog_soulsand_valley Soul
execute as @a at @s if entity @s[y=43,dy=57] if block ~ ~1 ~ water run fog @s remove Soul
vocal epoch
white light
#

The delta arguments create a volume that tests for entities in. DY sets the height of the box.

#

So y=41,dy=-106 makes a box that starts at y = 41 and ends at y = 41 - 106, which is -65