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

getting all the blocks above a certain height

Discussion in 'Development' started by rektpixel, Jan 12, 2018.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    I have this:
    PHP:
      public function checkVoid(PlayerMoveEvent $event){
        
    $player $event->getPlayer();
        
    $x $this->getServer()->getDefaultLevel()->getSafeSpawn()->getFloorX();
        
    $y $this->getServer()->getDefaultLevel()->getSafeSpawn()->getFloorZ();
        
    $z $this->getServer()->getDefaultLevel()->getSafeSpawn()->getFloorZ();
        
    $level $this->getServer()->getDefaultLevel();
        if(
    $event->getTo()->getFloorY() < 122){;
    so when a player moves above Y 122 I want to get all the blocks in $level above Y 122 and foreach block get id and position,
    how can this be done?
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    World's are infinite. What do you mean by "all blocks"?
     
  3. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    getting all the blocks in the world above Y 122. this wouldn't have any lag because I know that in the world there are only 2 blocks above Y 122. or is air a block? :eek:
     
  4. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    PHP:
      public function checkVoid(PlayerMoveEvent $event){
        
    $player $event->getPlayer();
        
    $x $this->getServer()->getDefaultLevel()->getSafeSpawn()->getFloorX();
        
    $y $this->getServer()->getDefaultLevel()->getSafeSpawn()->getFloorZ();
        
    $z $this->getServer()->getDefaultLevel()->getSafeSpawn()->getFloorZ();
        
    $level $this->getServer()->getDefaultLevel();
        if(
    $event->getTo()->getFloorY() < 122){;
        
        foreach(
    $level->getBlock->getId() < 122 as $b){
            
    $X $b->getX();
            
    $Y $b->getY();
            
    $Z $b->getZ();
            
    $pos = new Vector3($X-1$Y$Z);
            
    $level->setBlock($pos$bfalsefalse);
    this didn't work :(
     
  5. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    whoops, i meant to use '> 122' not '< 122'
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You will need to load each generated chunk and iterate all blocks in its y>122.
    It is not feasible to "get all blocks in an area in an array". Arrays are for storing data, and here, you just want a logical algorithm for looping, not a data storage for scanning. You should just use an ordinary for loop rather than a foreach loop.
     
  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.