mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
PopulationTask: reduce code duplication
This commit is contained in:
parent
88f799da2c
commit
c7e9138994
@ -102,32 +102,13 @@ class PopulationTask extends AsyncTask{
|
||||
}
|
||||
}
|
||||
|
||||
$manager->setChunk($this->chunkX, $this->chunkZ, $chunk ?? new Chunk());
|
||||
if($chunk === null){
|
||||
$generator->generateChunk($manager, $this->chunkX, $this->chunkZ);
|
||||
$chunk = $manager->getChunk($this->chunkX, $this->chunkZ);
|
||||
if($chunk === null){
|
||||
throw new AssumptionFailedError("We just set this chunk, so it must exist");
|
||||
}
|
||||
$chunk->setTerrainDirtyFlag(Chunk::DIRTY_FLAG_TERRAIN, true);
|
||||
$chunk->setTerrainDirtyFlag(Chunk::DIRTY_FLAG_BIOMES, true);
|
||||
}
|
||||
self::setOrGenerateChunk($manager, $generator, $this->chunkX, $this->chunkZ, $chunk);
|
||||
|
||||
$resultChunks = []; //this is just to keep phpstan's type inference happy
|
||||
foreach($chunks as $i => $c){
|
||||
$cX = (-1 + $i % 3) + $this->chunkX;
|
||||
$cZ = (-1 + intdiv($i, 3)) + $this->chunkZ;
|
||||
$manager->setChunk($cX, $cZ, $c ?? new Chunk());
|
||||
if($c === null){
|
||||
$generator->generateChunk($manager, $cX, $cZ);
|
||||
$c = $manager->getChunk($cX, $cZ);
|
||||
if($c === null){
|
||||
throw new AssumptionFailedError("We just set this chunk, so it must exist");
|
||||
}
|
||||
$c->setTerrainDirtyFlag(Chunk::DIRTY_FLAG_TERRAIN, true);
|
||||
$c->setTerrainDirtyFlag(Chunk::DIRTY_FLAG_BIOMES, true);
|
||||
}
|
||||
$resultChunks[$i] = $c;
|
||||
$resultChunks[$i] = self::setOrGenerateChunk($manager, $generator, $cX, $cZ, $c);
|
||||
}
|
||||
$chunks = $resultChunks;
|
||||
|
||||
@ -145,6 +126,20 @@ class PopulationTask extends AsyncTask{
|
||||
}
|
||||
}
|
||||
|
||||
private static function setOrGenerateChunk(SimpleChunkManager $manager, Generator $generator, int $chunkX, int $chunkZ, ?Chunk $chunk) : Chunk{
|
||||
$manager->setChunk($chunkX, $chunkZ, $chunk ?? new Chunk());
|
||||
if($chunk === null){
|
||||
$generator->generateChunk($manager, $chunkX, $chunkZ);
|
||||
$chunk = $manager->getChunk($chunkX, $chunkZ);
|
||||
if($chunk === null){
|
||||
throw new AssumptionFailedError("We just set this chunk, so it must exist");
|
||||
}
|
||||
$chunk->setTerrainDirtyFlag(Chunk::DIRTY_FLAG_TERRAIN, true);
|
||||
$chunk->setTerrainDirtyFlag(Chunk::DIRTY_FLAG_BIOMES, true);
|
||||
}
|
||||
return $chunk;
|
||||
}
|
||||
|
||||
public function onCompletion() : void{
|
||||
/** @var World $world */
|
||||
$world = $this->fetchLocal(self::TLS_KEY_WORLD);
|
||||
|
Loading…
x
Reference in New Issue
Block a user