How can i get the y coord of the lowest block at x,z ? maybe with Level->getSafeSpawn(new Vector3($x, 1, $z))->y; I wanted to ask before i try thanks.
Oops, I interpreted it as "the lowest air block" PHP: $chunk = $level->getChunk($x >> 4, $z >> 4);$x &= 0x0F;$z &= 0x0F;for($y = 0; $y < 128; $y++){ $block = $chunk->getBlockId($x, $y, $z); if($block !== 0) break;}if($y != 128){ // there is a non air block at this column}
i don't understand why are you creating $chunk if is not used in the code :/ . i know an mcr max y height value is 128, so you are looping 128 times from y=0 to y=128 . if you find a block that isn't air, you found the lowest block, ok , but i'm not sure you can get the block ID using only the y .
ops, haven' t see this XD .I tought it was $level ... pocketmine/level/Level . btw, can i use Level->getBlockIdAt(); ?? it's the same or from chunk is better?
It searches for the chunk every time. Since you are fetching data from the same chunk, better call it from the chunk.
:/ why $x &= 0x0F; ? 15⑽ = 1111⑵ so if for example the x = 20⑽ $x &= 15; sets the x to 4 ? 20 = 10100⑵ . 100⑵ = 4 explain this to me please, maybe is my fault
If you dont know what a function does its always a good idea to go and look at it in the pocketmine source code, this way you will see exactly what happens when the method is called.
Look at the documentation for FullChunk::getBlockId(): x 0-15, y 0-127, z 0-15. It is level provider-dependent whether x and z would be converted into four least significant bits. However, as you saw, we are getting a block from a specific chunk, and a chunk is 16*128*16 large.