1

I'd like to know if there is a way to select all entities which are exposed to the sky (excludes all entities which are underground, under a roof, etc.). A rudimentary workaround to this would be to select all entities which y-level of 64 or higher, but this doesn't work properly because it doesn't account for entities in holes (i.e. ravines) and overcounts entities which are covered (i.e. in a house).

Is there any way to achieve this, and if not, what would be a workaround that covers as many cases as possible?

6
  • 1
    1.20 has a new /execute command for that. Should be something like /execute as @e at @s positioned over surface if @s[distance=..1] or so. Not sure if distance=0 would work in all cases, there are some bugs with it. Disclaimer: I only read the title so far, currently in meeting. Commented Jun 12, 2023 at 18:53
  • Wait, what's the point of the distance argument in that execute command? And also, interesting new command :D
    – BunnyMerz
    Commented Jun 12, 2023 at 22:51
  • @FabianRöling You've got yourself a potential answer right there! :)
    – WarpPrime
    Commented Jun 13, 2023 at 23:20
  • Yes, but that requires testing the distance thing first and actually having correct syntax, not just from memory. I'm very busy currently. If that helped you, you can self-answer with what you ended up using. Commented Jun 14, 2023 at 4:33
  • @BunnyMerz positioned moves execution position. If that's still the same spot, then the entity should already be on the surface. Commented Jun 14, 2023 at 4:34

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.