# Solved lowest block at x,z ?

Comments in 'Plugin Development' started by Svile, Jan 9, 2016.

1. Offline

### SvileActive Member

Joined:
Mar 30, 2015
Posts:
239
Minecraft User:
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.
2. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
applqpak and Svile like this.
3. Offline

### CraftYourBukkitNotable MemberPlugin Developer

Joined:
Jan 20, 2015
Posts:
1,022
Plugins:
2
Minecraft User:
PEMapModder and applqpak like this.
4. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
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} ```
Last edited: Jan 9, 2016
CraftYourBukkit likes this.
5. Offline

### SvileActive Member

Joined:
Mar 30, 2015
Posts:
239
Minecraft User:
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 .
6. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
Sorry, I was absentminded when I was writing. Edited.
7. Offline

### SvileActive Member

Joined:
Mar 30, 2015
Posts:
239
Minecraft User:
\$chunk is not used why you defined it ?
8. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
Svile and CraftYourBukkit like this.
9. Offline

### SvileActive Member

Joined:
Mar 30, 2015
Posts:
239
Minecraft User:
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?
10. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
It searches for the chunk every time. Since you are fetching data from the same chunk, better call it from the chunk.
Svile likes this.
11. Offline

### SvileActive Member

Joined:
Mar 30, 2015
Posts:
239
Minecraft User:
that's true , thanks
12. Offline

### SvileActive Member

Joined:
Mar 30, 2015
Posts:
239
Minecraft User:
:/ 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
13. Offline

### Hotshot_9930Notable MemberPlugin Developer

Joined:
May 26, 2014
Posts:
665
Plugins:
2
Minecraft User:
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.
14. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
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.
Svile likes this.
15. Offline

### SvileActive Member

Joined:
Mar 30, 2015
Posts:
239
Minecraft User:
i had no time when i wrote the message