1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Is this possible?

Discussion in 'Development' started by BruhLol, Dec 28, 2018.

  1. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    Is it possible to get the second highest block at some $x, $z?
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I imagine you would begin by getting the coordinates of the highest block, then you could use a loop to find the next block below it, using the coordinates from the highest block as a starting place.
     
    BruhLol likes this.
  3. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    how to find the block below it?
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Well you can write your own function to do that
    PHP:
        public function getSecondHighestBlockAt(Level $level,int $x,$int z): int{
            
    $chunk $level->getChunk($x >> 4,$z >> 4,true);
            
    $first true;
            for(
    $y $level->getWorldHeight();$y >= 0;$y--)
                if(
    $chunk->getBlockId($x 0x0f,$y,$z 0x0f) !== 0){
                    if(
    $first$first false;
                    else return 
    $y;
                }
            return -
    1;
        }

     
    BruhLol likes this.
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PMMP uses a similar mechanism in Level::getSafeSpawn(). Maybe the source code can assist you.
     
    corytortoise and BruhLol like this.
  6. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    why did u do $x & 0x0f?
     
  7. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Because blocks inside chunks only have x and z that is >= 0 and <= 15
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.