mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +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{
|
||||
$result = [];
|
||||
for($xx = 0; $xx <= 2; ++$xx){
|
||||
for($zz = 0; $zz <= 2; ++$zz){
|
||||
$i = $zz * 3 + $xx;
|
||||
if($i === 4){
|
||||
for($xx = -1; $xx <= 1; ++$xx){
|
||||
for($zz = -1; $zz <= 1; ++$zz){
|
||||
if($xx === 0 && $zz === 0){
|
||||
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);
|
||||
$this->setChunk($x, $z, $chunk);
|
||||
|
||||
foreach($adjacentChunks as $adjacentChunkHash => $adjacentChunk){
|
||||
World::getXZ($adjacentChunkHash, $xAdjacentChunk, $zAdjacentChunk);
|
||||
$this->setChunk($xAdjacentChunk, $zAdjacentChunk, $adjacentChunk);
|
||||
foreach($adjacentChunks as $relativeChunkHash => $adjacentChunk){
|
||||
World::getXZ($relativeChunkHash, $relativeX, $relativeZ);
|
||||
$this->setChunk($x + $relativeX, $z + $relativeZ, $adjacentChunk);
|
||||
}
|
||||
|
||||
if(($oldChunk === null or !$oldChunk->isPopulated()) and $chunk->isPopulated()){
|
||||
|
@ -36,7 +36,6 @@ use pocketmine\world\World;
|
||||
use function array_map;
|
||||
use function igbinary_serialize;
|
||||
use function igbinary_unserialize;
|
||||
use function intdiv;
|
||||
|
||||
class PopulationTask extends AsyncTask{
|
||||
private const TLS_KEY_WORLD = "world";
|
||||
@ -92,10 +91,9 @@ class PopulationTask extends AsyncTask{
|
||||
|
||||
/** @var Chunk[] $resultChunks */
|
||||
$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;
|
||||
$resultChunks[$i] = self::setOrGenerateChunk($manager, $generator, $cX, $cZ, $c);
|
||||
foreach($chunks as $relativeChunkHash => $c){
|
||||
World::getXZ($relativeChunkHash, $relativeX, $relativeZ);
|
||||
$resultChunks[$relativeChunkHash] = self::setOrGenerateChunk($manager, $generator, $this->chunkX + $relativeX, $this->chunkZ + $relativeZ, $c);
|
||||
}
|
||||
$chunks = $resultChunks;
|
||||
|
||||
@ -109,8 +107,8 @@ class PopulationTask extends AsyncTask{
|
||||
$this->chunk = FastChunkSerializer::serializeTerrain($chunk);
|
||||
|
||||
$serialChunks = [];
|
||||
foreach($chunks as $i => $c){
|
||||
$serialChunks[$i] = $c->isTerrainDirty() ? FastChunkSerializer::serializeTerrain($c) : null;
|
||||
foreach($chunks as $relativeChunkHash => $c){
|
||||
$serialChunks[$relativeChunkHash] = $c->isTerrainDirty() ? FastChunkSerializer::serializeTerrain($c) : 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);
|
||||
$adjacentChunks = [];
|
||||
foreach($serialAdjacentChunks as $i => $c){
|
||||
foreach($serialAdjacentChunks as $relativeChunkHash => $c){
|
||||
if($c !== null){
|
||||
$xx = -1 + $i % 3;
|
||||
$zz = -1 + intdiv($i, 3);
|
||||
|
||||
$adjacentChunks[World::chunkHash($this->chunkX + $xx, $this->chunkZ + $zz)] = FastChunkSerializer::deserializeTerrain($c);
|
||||
$adjacentChunks[$relativeChunkHash] = FastChunkSerializer::deserializeTerrain($c);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user