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:
Dylan K. Taylor 2021-10-25 19:49:35 +01:00
parent 42ede30e77
commit b8519d1af4
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
5 changed files with 28 additions and 24 deletions

View File

@ -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;
}
/**

View File

@ -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);
}
}

View File

@ -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
}

View File

@ -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) : [],
);

View File

@ -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) : [],
);