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

replacing blocks in a area

Discussion in 'Development' started by CupidonSauce173, Mar 30, 2019.

  1. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Hello, I am trying to replace all blocks from an ID to another one.
    I get this error Error: "Call to a member function setBlock() on null"

    PHP:
            $level Main::getInstance()->getServer()->getLevelByName("factionmap");
            
    $b Block::get(Block::CARPET);
    PHP:
    $pos = new Vector3($x$y$z);
    and the problematic line
    PHP:
    $b->level->setBlock($pos$block); 
     
  2. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    whats x y and z?
     
  3. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    PHP:
                        $x mt_rand(-9,2) ;
                        
    $y++;
                        
    $z mt_rand(-47,-36);
     
  4. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    $y has a default value of 24 $y = 24;, its just outside of the while
     
  5. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    you just initiated the block it doesn't have a level
     
    Primus likes this.
  6. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    How do I give him a level ?

    Basically I try to make it so example the block 1:0 become 4:0 (this is just an example)
     
  7. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    you use $level which you already defined
     
  8. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    So how do I give the level to the block?
     
  9. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    PHP:
    $level->setBlock($pos$block);
     
  10. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    yes that works but what I try to do is to only replace a certain block for another, now it fills up everything in these positions.
    I was trying to do what they said in this thread
    https://forums.pmmp.io/threads/replace-block.6762/
    but ye..Do you have an idea on how to fix it ?
     
  11. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    it'll be really laggy, but you can loop every block in a chunk for every loaded chunk
     
  12. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    $level->setBlock($pos, $b);
     
  13. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    And there is no way to just loop every blocks from a area ? ( $minX, $maxX, $minY, $maxY, $minZ, $maxZ ), if yes, how could we do that?
     
  14. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    yes you can, just get the corresponding chunks and loop them
    $chunkX = $x << 4
    $chunkZ = $z << 4
     
  15. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Good, last thing,
    So basically I have to loop chunk and then what? Like I get all blockIDs in a array and detect the ones with example the ID of 1:0 -> 1,1,1 so $id -> $pos and I do
    $level->setBlock($pos, $block); ? $pos being all the blocks with 1:0 as id in a array of block ids and position
     
  16. Primus

    Primus Zombie Pigman

    Messages:
    749
    when iterating through area, you already should have "old" block positions. There is no necessity to store any of those values, use them on the fly. Get through frustration and experiment :)

    P.S. Use test world if not - Keep backups, don't mess your world up.
     
  17. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    factionmap is a test world in my test server ;) so I can just drop the plugins directly in the production on so I don't need to change any code, its a normal world and the production one is the real map.

    I just don't understand how to say "okay, 1:0 is changed to 2:0 in $position"
     
  18. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
  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.