As Fabian Röling commented that command would work, as:
/execute as @e at @s positioned over world_surface if entity @s[distance=..1] run <command>
However, the distance
is quite important.
If the entity stands on a full block and can see the sun, distance=..0
works great. But in my testing, I used honey blocks to keep entities still, and then those entities didn't get affected.
Using distance=..0.5
worked, as well as when the entity was on a slab.
But if the entity is in mid-jump and further away from the surface than 0.5, then it won't get detected.
If you increase the distance to something higher you might detect the roof instead, as I found out if there is a block above the entity's head and the distance is 3, it will still be affected.
The smaller block the entity stands on the bigger distance you need, if the entity stands on a carpet or 1 snow layer, you need at least a distance of 0.94.
So I would recommend using distance=..1
as it should work for all half-blocks. For an entity in mid-jump, I found that 1.3 works fine, but those tests aren't perfect.
/execute
command for that. Should be something like/execute as @e at @s positioned over surface if @s[distance=..1]
or so. Not sure ifdistance=0
would work in all cases, there are some bugs with it. Disclaimer: I only read the title so far, currently in meeting.positioned
moves execution position. If that's still the same spot, then the entity should already be on the surface.