How to check is there any blocks above player?

Hey, I’m making a plugin that fires user if there’s no blocks above him (except for light-ski for my project.

So… I saw that there is ‘BlockRay’ method to track is there any blocks (except light transmitting blocks), buy after ~20 attempts to use BlockRay i’ve got no result, so I just started to check blocks in the loop (for (int y = playerLocation.getFloorY(); y <= 256; y++)), is there a proper way to check is there any blocks above player?

The BlockRay class is for if you wanted to get a block (or multiple) in a line that is abnormal (such as players looking direction). So no you would not use that.

Your method of checking in a loop is completely valid, however if you want a sponge way of doing it. Here you go

Player player;
Location<World> loc = player.asHighestLocation();
if(player.getY() >= loc.getY()){
    //No blocks above
}
1 Like