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