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

Load chunk

Discussion in 'Development' started by #A6543, Jan 30, 2017.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    How can I load all chunks in an radius from coords?
     
    Last edited: Jan 30, 2017
  2. #A6543

    #A6543 Zombie

    Messages:
    267
    Does someone know that?
     
  3. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    PHP:
    // We have $x, $z
    // Example:
    $x $player->getX() >> 4// take 'X' chunk coordinate
    $z $player->getZ() >> 4// take 'Z' chunk coordinate
    $radius 15;
    for (
    $chunkX = -$radius$chunkX <= $radius$chunkX++){
        for (
    $chunkZ = -$radius$chunkZ <= $radius$chunkZ++){
            
    // if distance <= raduis than load chunk
            
    if (sqrt($chunkX*$chunkX $chunkZ*$chunkZ) <= $radius$level->loadChunk($chunkX $x$chunkZ $z);
        }
    }
     
    Last edited: Jan 31, 2017
  4. #A6543

    #A6543 Zombie

    Messages:
    267
    Thanks :)
     
  5. #A6543

    #A6543 Zombie

    Messages:
    267
    And do u know how to check if $player is in a radius of 5 blocks from coords?
     
  6. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    https://en.wikipedia.org/wiki/Euclidean_distance
    [​IMG]
    PHP:
    // We have $p - Player and $b - Block
    $distance sqrt(($p->$b->x)*($p->$b->x) + ($p->$b->y)*($p->$b->y) + ($p->-
    $b->z)*($p->$b->z));
    if (
    $distance <= 5) {
        
    // todo
    }
     
    Last edited: Feb 1, 2017
    Teamblocket likes this.
  7. #A6543

    #A6543 Zombie

    Messages:
    267
    Ok thanks.
    Now I tried to knockback the player from $b ($b is a sign)
    How can I do it? I tried this:
    PHP:
    $direction $player->getDirectionVector();
                                            
    $x $direction->getX();
                                            
    $y $direction->getY();
                                            
    $z $direction->getZ();
                                           
                                            for (
    $i 1$i <= 10$i++)
                                            {
                                                
    $player->knockBack($player0$x$z, -1);
                                            }
     
  8. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    https://github.com/iTXTech/Genisys/blob/master/src/pocketmine/entity/Living.php#L140
     
  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.