Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved lowest block at x,z ?

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

  1. Svile
    Offline

    Svile Active Member

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

    PEMapModder Notable Member Plugin Developer

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

    CraftYourBukkit Notable Member Plugin Developer

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

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oops, I interpreted it as "the lowest air block" :p

    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. Svile
    Offline

    Svile Active Member

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

    PEMapModder Notable Member Plugin Developer

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

    Svile Active Member

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

    PEMapModder Notable Member Plugin Developer

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

    Svile Active Member

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

    PEMapModder Notable Member Plugin Developer

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

    Svile Active Member

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

    Svile Active Member

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

    Hotshot_9930 Notable Member Plugin Developer

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

    PEMapModder Notable Member Plugin Developer

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

    Svile Active Member

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

Share This Page

Advertisement