mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 03:16:35 +00:00
World: Specialize generateChunkCallback() for PopulationTask
this allows us to also set the adjacent chunks before calling ChunkPopulateEvent, to give a more accurate picture of what changed.
This commit is contained in:
parent
b9d9b69bbe
commit
8f88393184
@ -2145,12 +2145,13 @@ class World implements ChunkManager{
|
||||
}
|
||||
}
|
||||
|
||||
public function generateChunkCallback(int $x, int $z, ?Chunk $chunk) : void{
|
||||
/**
|
||||
* @param Chunk[] $adjacentChunks
|
||||
* @phpstan-param array<int, Chunk> $adjacentChunks
|
||||
*/
|
||||
public function generateChunkCallback(int $x, int $z, Chunk $chunk, array $adjacentChunks) : void{
|
||||
Timings::$generationCallback->startTiming();
|
||||
if(isset($this->chunkPopulationRequestMap[$index = World::chunkHash($x, $z)]) && isset($this->activeChunkPopulationTasks[$index])){
|
||||
if($chunk === null){
|
||||
throw new AssumptionFailedError("Primary chunk should never be NULL");
|
||||
}
|
||||
for($xx = -1; $xx <= 1; ++$xx){
|
||||
for($zz = -1; $zz <= 1; ++$zz){
|
||||
$this->unlockChunk($x + $xx, $z + $zz);
|
||||
@ -2159,6 +2160,12 @@ class World implements ChunkManager{
|
||||
|
||||
$oldChunk = $this->loadChunk($x, $z);
|
||||
$this->setChunk($x, $z, $chunk, false);
|
||||
|
||||
foreach($adjacentChunks as $adjacentChunkHash => $adjacentChunk){
|
||||
World::getXZ($adjacentChunkHash, $xAdjacentChunk, $zAdjacentChunk);
|
||||
$this->setChunk($xAdjacentChunk, $zAdjacentChunk, $adjacentChunk);
|
||||
}
|
||||
|
||||
if(($oldChunk === null or !$oldChunk->isPopulated()) and $chunk->isPopulated()){
|
||||
(new ChunkPopulateEvent($this, $x, $z, $chunk))->call();
|
||||
|
||||
@ -2172,14 +2179,6 @@ class World implements ChunkManager{
|
||||
$promise->resolve($chunk);
|
||||
|
||||
$this->drainPopulationRequestQueue();
|
||||
}elseif($this->isChunkLocked($x, $z)){
|
||||
$this->unlockChunk($x, $z);
|
||||
if($chunk !== null){
|
||||
$this->setChunk($x, $z, $chunk, false);
|
||||
}
|
||||
$this->drainPopulationRequestQueue();
|
||||
}elseif($chunk !== null){
|
||||
$this->setChunk($x, $z, $chunk, false);
|
||||
}
|
||||
Timings::$generationCallback->stopTiming();
|
||||
}
|
||||
|
@ -153,6 +153,7 @@ class PopulationTask extends AsyncTask{
|
||||
FastChunkSerializer::deserializeTerrain($this->chunk) :
|
||||
throw new AssumptionFailedError("Center chunk should never be null");
|
||||
|
||||
$adjacentChunks = [];
|
||||
for($i = 0; $i < 9; ++$i){
|
||||
if($i === 4){
|
||||
continue;
|
||||
@ -162,12 +163,11 @@ class PopulationTask extends AsyncTask{
|
||||
$xx = -1 + $i % 3;
|
||||
$zz = -1 + intdiv($i, 3);
|
||||
|
||||
$c = FastChunkSerializer::deserializeTerrain($c);
|
||||
$world->generateChunkCallback($this->chunkX + $xx, $this->chunkZ + $zz, $c);
|
||||
$adjacentChunks[World::chunkHash($this->chunkX + $xx, $this->chunkZ + $zz)] = FastChunkSerializer::deserializeTerrain($c);
|
||||
}
|
||||
}
|
||||
|
||||
$world->generateChunkCallback($this->chunkX, $this->chunkZ, $chunk);
|
||||
$world->generateChunkCallback($this->chunkX, $this->chunkZ, $chunk, $adjacentChunks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user