mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
World: fixed every chunk having terrain saved at least once, even if unmodified
setPopulated() sets dirty flags on the chunk, causing the autosave sweep to think they've been changed when they haven't. We now pass terrainPopulated to the constructor to avoid this ambiguity recurring in the future.
This commit is contained in:
parent
42ede30e77
commit
b8519d1af4
@ -69,7 +69,7 @@ class Chunk{
|
||||
/**
|
||||
* @param SubChunk[] $subChunks
|
||||
*/
|
||||
public function __construct(array $subChunks = [], ?BiomeArray $biomeIds = null, ?HeightArray $heightMap = null){
|
||||
public function __construct(array $subChunks = [], ?BiomeArray $biomeIds = null, ?HeightArray $heightMap = null, bool $terrainPopulated = false){
|
||||
$this->subChunks = new \SplFixedArray(Chunk::MAX_SUBCHUNKS);
|
||||
|
||||
foreach($this->subChunks as $y => $null){
|
||||
@ -79,6 +79,8 @@ class Chunk{
|
||||
$val = ($this->subChunks->getSize() * SubChunk::EDGE_LENGTH);
|
||||
$this->heightMap = $heightMap ?? new HeightArray(array_fill(0, 256, $val));
|
||||
$this->biomeIds = $biomeIds ?? BiomeArray::fill(BiomeIds::OCEAN);
|
||||
|
||||
$this->terrainPopulated = $terrainPopulated;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,10 +115,6 @@ final class FastChunkSerializer{
|
||||
|
||||
$biomeIds = new BiomeArray($stream->get(256));
|
||||
|
||||
$chunk = new Chunk($subChunks, $biomeIds);
|
||||
$chunk->setPopulated($terrainPopulated);
|
||||
$chunk->clearTerrainDirtyFlags();
|
||||
|
||||
return $chunk;
|
||||
return new Chunk($subChunks, $biomeIds, null, $terrainPopulated);
|
||||
}
|
||||
}
|
||||
|
@ -404,20 +404,23 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
|
||||
}
|
||||
}
|
||||
|
||||
$chunk = new Chunk(
|
||||
$subChunks,
|
||||
$biomeArray
|
||||
);
|
||||
|
||||
//TODO: tile ticks, biome states (?)
|
||||
|
||||
$finalisationChr = $this->db->get($index . self::TAG_STATE_FINALISATION);
|
||||
if($finalisationChr !== false){
|
||||
$finalisation = ord($finalisationChr);
|
||||
$chunk->setPopulated($finalisation === self::FINALISATION_DONE);
|
||||
$terrainPopulated = $finalisation === self::FINALISATION_DONE;
|
||||
}else{ //older versions didn't have this tag
|
||||
$chunk->setPopulated();
|
||||
$terrainPopulated = true;
|
||||
}
|
||||
|
||||
//TODO: tile ticks, biome states (?)
|
||||
|
||||
$chunk = new Chunk(
|
||||
$subChunks,
|
||||
$biomeArray,
|
||||
null,
|
||||
$terrainPopulated
|
||||
);
|
||||
|
||||
if($hasBeenUpgraded){
|
||||
$chunk->setTerrainDirty(); //trigger rewriting chunk to disk if it was converted from an older format
|
||||
}
|
||||
|
@ -88,13 +88,13 @@ trait LegacyAnvilChunkTrait{
|
||||
$biomeArray = $makeBiomeArray($biomesTag->getValue());
|
||||
}
|
||||
|
||||
$result = new Chunk(
|
||||
$subChunks,
|
||||
$biomeArray
|
||||
);
|
||||
$result->setPopulated($chunk->getByte("TerrainPopulated", 0) !== 0);
|
||||
return new ChunkData(
|
||||
$result,
|
||||
new Chunk(
|
||||
$subChunks,
|
||||
$biomeArray,
|
||||
null,
|
||||
$chunk->getByte("TerrainPopulated", 0) !== 0
|
||||
),
|
||||
($entitiesTag = $chunk->getTag("Entities")) instanceof ListTag ? self::getCompoundList("Entities", $entitiesTag) : [],
|
||||
($tilesTag = $chunk->getTag("TileEntities")) instanceof ListTag ? self::getCompoundList("TileEntities", $tilesTag) : [],
|
||||
);
|
||||
|
@ -82,10 +82,13 @@ class McRegion extends RegionWorldProvider{
|
||||
$biomeIds = $makeBiomeArray($biomesTag->getValue());
|
||||
}
|
||||
|
||||
$result = new Chunk($subChunks, $biomeIds);
|
||||
$result->setPopulated($chunk->getByte("TerrainPopulated", 0) !== 0);
|
||||
return new ChunkData(
|
||||
$result,
|
||||
new Chunk(
|
||||
$subChunks,
|
||||
$biomeIds,
|
||||
null,
|
||||
$chunk->getByte("TerrainPopulated", 0) !== 0
|
||||
),
|
||||
($entitiesTag = $chunk->getTag("Entities")) instanceof ListTag ? self::getCompoundList("Entities", $entitiesTag) : [],
|
||||
($tilesTag = $chunk->getTag("TileEntities")) instanceof ListTag ? self::getCompoundList("TileEntities", $tilesTag) : [],
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user