mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 04:17:07 +00:00
Use standard chunkHash() to index population chunks
This commit is contained in:
parent
4dc13ab3da
commit
65ef9f786a
@ -2082,13 +2082,12 @@ class World implements ChunkManager{
|
|||||||
*/
|
*/
|
||||||
public function getAdjacentChunks(int $x, int $z) : array{
|
public function getAdjacentChunks(int $x, int $z) : array{
|
||||||
$result = [];
|
$result = [];
|
||||||
for($xx = 0; $xx <= 2; ++$xx){
|
for($xx = -1; $xx <= 1; ++$xx){
|
||||||
for($zz = 0; $zz <= 2; ++$zz){
|
for($zz = -1; $zz <= 1; ++$zz){
|
||||||
$i = $zz * 3 + $xx;
|
if($xx === 0 && $zz === 0){
|
||||||
if($i === 4){
|
|
||||||
continue; //center chunk
|
continue; //center chunk
|
||||||
}
|
}
|
||||||
$result[$i] = $this->loadChunk($x + $xx - 1, $z + $zz - 1);
|
$result[World::chunkHash($xx, $zz)] = $this->loadChunk($x + $xx, $z + $zz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2927,9 +2926,9 @@ class World implements ChunkManager{
|
|||||||
$oldChunk = $this->loadChunk($x, $z);
|
$oldChunk = $this->loadChunk($x, $z);
|
||||||
$this->setChunk($x, $z, $chunk);
|
$this->setChunk($x, $z, $chunk);
|
||||||
|
|
||||||
foreach($adjacentChunks as $adjacentChunkHash => $adjacentChunk){
|
foreach($adjacentChunks as $relativeChunkHash => $adjacentChunk){
|
||||||
World::getXZ($adjacentChunkHash, $xAdjacentChunk, $zAdjacentChunk);
|
World::getXZ($relativeChunkHash, $relativeX, $relativeZ);
|
||||||
$this->setChunk($xAdjacentChunk, $zAdjacentChunk, $adjacentChunk);
|
$this->setChunk($x + $relativeX, $z + $relativeZ, $adjacentChunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($oldChunk === null or !$oldChunk->isPopulated()) and $chunk->isPopulated()){
|
if(($oldChunk === null or !$oldChunk->isPopulated()) and $chunk->isPopulated()){
|
||||||
|
@ -36,7 +36,6 @@ use pocketmine\world\World;
|
|||||||
use function array_map;
|
use function array_map;
|
||||||
use function igbinary_serialize;
|
use function igbinary_serialize;
|
||||||
use function igbinary_unserialize;
|
use function igbinary_unserialize;
|
||||||
use function intdiv;
|
|
||||||
|
|
||||||
class PopulationTask extends AsyncTask{
|
class PopulationTask extends AsyncTask{
|
||||||
private const TLS_KEY_WORLD = "world";
|
private const TLS_KEY_WORLD = "world";
|
||||||
@ -92,10 +91,9 @@ class PopulationTask extends AsyncTask{
|
|||||||
|
|
||||||
/** @var Chunk[] $resultChunks */
|
/** @var Chunk[] $resultChunks */
|
||||||
$resultChunks = []; //this is just to keep phpstan's type inference happy
|
$resultChunks = []; //this is just to keep phpstan's type inference happy
|
||||||
foreach($chunks as $i => $c){
|
foreach($chunks as $relativeChunkHash => $c){
|
||||||
$cX = (-1 + $i % 3) + $this->chunkX;
|
World::getXZ($relativeChunkHash, $relativeX, $relativeZ);
|
||||||
$cZ = (-1 + intdiv($i, 3)) + $this->chunkZ;
|
$resultChunks[$relativeChunkHash] = self::setOrGenerateChunk($manager, $generator, $this->chunkX + $relativeX, $this->chunkZ + $relativeZ, $c);
|
||||||
$resultChunks[$i] = self::setOrGenerateChunk($manager, $generator, $cX, $cZ, $c);
|
|
||||||
}
|
}
|
||||||
$chunks = $resultChunks;
|
$chunks = $resultChunks;
|
||||||
|
|
||||||
@ -109,8 +107,8 @@ class PopulationTask extends AsyncTask{
|
|||||||
$this->chunk = FastChunkSerializer::serializeTerrain($chunk);
|
$this->chunk = FastChunkSerializer::serializeTerrain($chunk);
|
||||||
|
|
||||||
$serialChunks = [];
|
$serialChunks = [];
|
||||||
foreach($chunks as $i => $c){
|
foreach($chunks as $relativeChunkHash => $c){
|
||||||
$serialChunks[$i] = $c->isTerrainDirty() ? FastChunkSerializer::serializeTerrain($c) : null;
|
$serialChunks[$relativeChunkHash] = $c->isTerrainDirty() ? FastChunkSerializer::serializeTerrain($c) : null;
|
||||||
}
|
}
|
||||||
$this->adjacentChunks = igbinary_serialize($serialChunks) ?? throw new AssumptionFailedError("igbinary_serialize() returned null");
|
$this->adjacentChunks = igbinary_serialize($serialChunks) ?? throw new AssumptionFailedError("igbinary_serialize() returned null");
|
||||||
}
|
}
|
||||||
@ -147,12 +145,9 @@ class PopulationTask extends AsyncTask{
|
|||||||
*/
|
*/
|
||||||
$serialAdjacentChunks = igbinary_unserialize($this->adjacentChunks);
|
$serialAdjacentChunks = igbinary_unserialize($this->adjacentChunks);
|
||||||
$adjacentChunks = [];
|
$adjacentChunks = [];
|
||||||
foreach($serialAdjacentChunks as $i => $c){
|
foreach($serialAdjacentChunks as $relativeChunkHash => $c){
|
||||||
if($c !== null){
|
if($c !== null){
|
||||||
$xx = -1 + $i % 3;
|
$adjacentChunks[$relativeChunkHash] = FastChunkSerializer::deserializeTerrain($c);
|
||||||
$zz = -1 + intdiv($i, 3);
|
|
||||||
|
|
||||||
$adjacentChunks[World::chunkHash($this->chunkX + $xx, $this->chunkZ + $zz)] = FastChunkSerializer::deserializeTerrain($c);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user