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

Solved Error loading Chunk

Discussion in 'Development' started by xKolqd_, May 27, 2020.

  1. xKolqd_

    xKolqd_ Silverfish

    Messages:
    17
    I have a big mistake that I could not be fixing.
    // Code
    $border = 500;
    $x = mt_rand(-$border, $border);
    $z = mt_rand(-$border, $border);
    $y = $this->getLevel()->getHighestBlockAt($x,$z);
    $vector = new Vector3($x, $y, $z);
    $this->getLevel()->loadChunk($x >> 4, $z >> 4);
    $player->teleport($vector);
    print_r([$x, $y, $z]);

    what happens here is that "y" returns -1.
    I tried loading the Chunk but it doesn't work.
     
  2. Joao Nunes

    Joao Nunes Spider Jockey

    Messages:
    30
    GitHub:
    joaonunes12
    You're taking the tallest block without loading the chunk

    PHP:
    $border 500;
    $x mt_rand(-$border$border);
    $z mt_rand(-$border$border);
    $this->getLevel()->loadChunk($x >> 4$z >> 4);

    $y $this->getLevel()->getHighestBlockAt($x,$z);
    $vector = new Vector3($x$y$z);

    $player->teleport($vector);
     
  3. xKolqd_

    xKolqd_ Silverfish

    Messages:
    17
    I used the same structure that you did, load the chunk before locating the "y" and it didn't work..
     
  4. Joao Nunes

    Joao Nunes Spider Jockey

    Messages:
    30
    GitHub:
    joaonunes12
    xKolqd_ likes this.
  5. xKolqd_

    xKolqd_ Silverfish

    Messages:
    17
  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.