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

Solved Get chunk around a player

Discussion in 'Help' started by dadodasyra, Jul 1, 2020.

  1. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    How to get all the chunks around a player, like 3x3 around the player, paint on the support below: ')

    And are the chunks different on pocketmine or do they do 16x16 as on Java?

    For the paint the player is in the red zone somewhere and I want the chunks around him in 3x3 to be able to recover their number of tileentity.
     

    Attached Files:

  2. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    try out this
    PHP:
      $x =$player->getFloorX();
            
    $z =$player->getFloorZ();
            
    $player->getLevel()->getChunk($x,$z,false);
     
  3. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    Thank you for the help test but it does not help me much x)

    I finally found it myself, you have to get the player's current chunk and then make loops to recover all those around thanks to the X Z of the chunk.


    PHP:
            $chunks = [];

            
    $level $player->getLevel();
            
    $chunk $player->getLevel()->getChunkAtPosition($player->getPosition());

            
    $baseX $chunk->getX(); #base chunk x
            
    $baseZ $chunk->getZ(); #base chunk z

            
    for($x = -1$x <= 1$x++) { #do a loop with the chunk before and the chunk after in x
                
    for ($z = -1$z <= 1$z++) { #same but with z
                    
    $chunks[] = $level->getChunk($x $baseX$z $baseZ); #get chunk with the $x from the for + the $baseX from the base chunk
                
    }
            }
     
  4. JviguyGamesYT

    JviguyGamesYT Baby Zombie

    Messages:
    113
    GitHub:
    jviguy
    true or u could just subtract the distance between each chunk like a 16 by 16 area and get that chunk ,but a loop works way better.
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    PHP:
    $baseX $player->getX() >> 4;
    $baseZ $player->getZ() >> 4;
     
  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.