diff --git a/src/muqsit/worldstyler/schematics/Schematic.php b/src/muqsit/worldstyler/schematics/Schematic.php index e1da775..fb4eb2e 100644 --- a/src/muqsit/worldstyler/schematics/Schematic.php +++ b/src/muqsit/worldstyler/schematics/Schematic.php @@ -7,6 +7,8 @@ use muqsit\worldstyler\utils\BlockIterator; use muqsit\worldstyler\utils\Utils; +use wumpotamus\chunkloader\ChunkRegion; + use pocketmine\level\ChunkManager; use pocketmine\level\Level; use pocketmine\math\Vector3; @@ -72,23 +74,26 @@ public function paste(ChunkManager $level, Vector3 $relative_pos, bool $replace_ for ($z = 0; $z < $length; ++$z) { $zPos = $z + $relz; $zwx = $z * $width + $x; - - for ($y = 0; $y < $height; ++$y) { - $index = $y * $wl + $zwx; - - $id = ord($blockIds{$index}); - $damage = ord($blockDatas{$index}); - - if ($replace_pc_blocks && isset(Utils::REPLACEMENTS[$id])) { - [$new_id, $new_damage] = Utils::REPLACEMENTS[$id][$damage] ?? Utils::REPLACEMENTS[$id][-1] ?? [$id, $damage]; - $id = $new_id ?? $id; - $damage = $new_damage ?? $damage; - } - - $yPos = $y + $rely; - $iterator->moveTo($xPos, $yPos, $zPos); - $iterator->currentSubChunk->setBlock($xPos & 0x0f, $yPos & 0x0f, $zPos & 0x0f, $id, $damage); - } + + ChunkRegion::onChunkGenerated($level, $xPos >> 4, $zPos >> 4, function() use($rely, $replace_pc_blocks, $iterator, $xPos, $zPos, $height, $wl, $zwx, $blockIds, $blockDatas){ + for ($y = 0; $y < $height; ++$y) { + $index = $y * $wl + $zwx; + + $id = ord($blockIds{$index}); + $damage = ord($blockDatas{$index}); + + if ($replace_pc_blocks && isset(Utils::REPLACEMENTS[$id])) { + [$new_id, $new_damage] = Utils::REPLACEMENTS[$id][$damage] ?? Utils::REPLACEMENTS[$id][-1] ?? [$id, $damage]; + $id = $new_id ?? $id; + $damage = $new_damage ?? $damage; + } + + $yPos = $y + $rely; + $iterator->moveTo($xPos, $yPos, $zPos); + $iterator->currentSubChunk->setBlock($xPos & 0x0f, $yPos & 0x0f, $zPos & 0x0f, $id, $damage); + } + }); + $level->unloadChunk( $xPos >> 4, $zPos >> 4); } }