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

how to regenerate chunks selected points?

Discussion in 'Development' started by andrew1481432, Feb 13, 2017.

  1. andrew1481432

    andrew1481432 Creeper

    Messages:
    4
    GitHub:
    andrew1481432
    how to regenerate chunks selected points?
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I'm guessing you mean "regeneration" as in "repopulating" (aka "repop")..
    (P.S. I haven't tested the code, but this should work).
    PHP:
    /** @var Vector3 $initial */
    /** @var Vector3 $final */
    /** @var Level $level */
    $x = [$initial->>> 4$final->>> 4];
    $z = [$initial->>> 4$final->>> 4];

    for(
    $x min($x); $x <= max($x); ++$x){
        for(
    $z min($z); $z <= max($z); ++$z){
            if((
    $chunk $level->getChunk($x$z)) instanceof \pocketmine\level\format\Chunk$chunk->setGenerated(false);
        }
    }
     
    Last edited: Feb 14, 2017
  3. andrew1481432

    andrew1481432 Creeper

    Messages:
    4
    GitHub:
    andrew1481432
    dont work(

    [10:38:05] [Server thread/CRITICAL]: Error: "Call to a member function getChunk() on unknown" (EXCEPTION) in "/WorldEditor_v1/src/plugin/WorldEditor/WorldEditorMainFolder/Builder" at line 209

    function regen(&$session, &$output)
    {
    $pos1 = $selection[0];
    $pos2 = $selection[1];
    $minX = min($pos1[0], $pos2[0]);
    $maxX = max($pos1[0], $pos2[0]);
    $minY = min($pos1[1], $pos2[1]);
    $maxY = max($pos1[1], $pos2[1]);
    $minZ = min($pos1[2], $pos2[2]);
    $maxZ = max($pos1[2], $pos2[2]);
    /** @var Vector3 $initial */
    /** @var Vector3 $final */
    /** @var Level $level */
    $x = [$initial->x >> 4, $final->x >> 4];
    $z = [$initial->z >> 4, $final->z >> 4];
    for ($x = $minX; $x <= $maxX; ++$x) {
    for ($y = $minY; $y <= $maxY; ++$y) {
    for ($z = $minZ; $z <= $maxZ; ++$z) {
    $level->getChunk($x, $z)->setGenerated(false);
    $output .= "regen region";
    }
    }
    }
    }
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    You need to $level needs to be a level object
     
    Muqsit likes this.
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    ^
    Also, just in case getChunk()'d return null, I've added a check.
     
  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.