diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php index 13a84742b..23367ef7e 100644 --- a/src/world/format/Chunk.php +++ b/src/world/format/Chunk.php @@ -41,8 +41,6 @@ class Chunk{ public const COORD_BIT_SIZE = SubChunk::COORD_BIT_SIZE; public const COORD_MASK = SubChunk::COORD_MASK; - private int $modificationCount; - /** @var int */ private $terrainDirtyFlags = 0; @@ -69,7 +67,7 @@ class Chunk{ /** * @param SubChunk[] $subChunks */ - public function __construct(array $subChunks, BiomeArray $biomeIds, bool $terrainPopulated, int $modificationCount = 0){ + public function __construct(array $subChunks, BiomeArray $biomeIds, bool $terrainPopulated){ $this->subChunks = new \SplFixedArray(Chunk::MAX_SUBCHUNKS); foreach($this->subChunks as $y => $null){ @@ -81,7 +79,6 @@ class Chunk{ $this->biomeIds = $biomeIds; $this->terrainPopulated = $terrainPopulated; - $this->modificationCount = $modificationCount; } /** @@ -110,7 +107,6 @@ class Chunk{ public function setFullBlock(int $x, int $y, int $z, int $block) : void{ $this->getSubChunk($y >> SubChunk::COORD_BIT_SIZE)->setFullBlock($x, $y & SubChunk::COORD_MASK, $z, $block); $this->terrainDirtyFlags |= self::DIRTY_FLAG_TERRAIN; - $this->modificationCount++; } /** @@ -174,7 +170,6 @@ class Chunk{ public function setBiomeId(int $x, int $z, int $biomeId) : void{ $this->biomeIds->set($x, $z, $biomeId); $this->terrainDirtyFlags |= self::DIRTY_FLAG_BIOMES; - $this->modificationCount++; } public function isLightPopulated() : ?bool{ @@ -192,7 +187,6 @@ class Chunk{ public function setPopulated(bool $value = true) : void{ $this->terrainPopulated = $value; $this->terrainDirtyFlags |= self::DIRTY_FLAG_TERRAIN; - $this->modificationCount++; } public function addTile(Tile $tile) : void{ @@ -275,24 +269,16 @@ class Chunk{ }else{ $this->terrainDirtyFlags &= ~$flag; } - $this->modificationCount++; } public function setTerrainDirty() : void{ $this->terrainDirtyFlags = ~0; - $this->modificationCount++; } public function clearTerrainDirtyFlags() : void{ $this->terrainDirtyFlags = 0; } - /** - * Returns the modcount for this chunk. Any saveable change to the chunk will cause this number to be incremented, - * so you can use this to detect when the chunk has been modified. - */ - public function getModificationCount() : int{ return $this->modificationCount; } - public function getSubChunk(int $y) : SubChunk{ if($y < 0 || $y >= $this->subChunks->getSize()){ throw new \InvalidArgumentException("Invalid subchunk Y coordinate $y"); diff --git a/src/world/format/io/FastChunkSerializer.php b/src/world/format/io/FastChunkSerializer.php index 0f3db73d1..bb8bec687 100644 --- a/src/world/format/io/FastChunkSerializer.php +++ b/src/world/format/io/FastChunkSerializer.php @@ -51,8 +51,6 @@ final class FastChunkSerializer{ */ public static function serializeTerrain(Chunk $chunk) : string{ $stream = new BinaryStream(); - $stream->putLong($chunk->getModificationCount()); - $stream->putByte( ($chunk->isPopulated() ? self::FLAG_POPULATED : 0) ); @@ -90,7 +88,6 @@ final class FastChunkSerializer{ */ public static function deserializeTerrain(string $data) : Chunk{ $stream = new BinaryStream($data); - $modificationCounter = $stream->getLong(); $flags = $stream->getByte(); $terrainPopulated = (bool) ($flags & self::FLAG_POPULATED); @@ -118,6 +115,6 @@ final class FastChunkSerializer{ $biomeIds = new BiomeArray($stream->get(256)); - return new Chunk($subChunks, $biomeIds, $terrainPopulated, $modificationCounter); + return new Chunk($subChunks, $biomeIds, $terrainPopulated); } } diff --git a/src/world/generator/PopulationTask.php b/src/world/generator/PopulationTask.php index fe5f6fc8a..0e35961be 100644 --- a/src/world/generator/PopulationTask.php +++ b/src/world/generator/PopulationTask.php @@ -81,7 +81,6 @@ class PopulationTask extends AsyncTask{ fn(?string $serialized) => $serialized !== null ? FastChunkSerializer::deserializeTerrain($serialized) : null, $serialChunks ); - $oldModCounts = array_map(fn(?Chunk $chunk) => $chunk !== null ? $chunk->getModificationCount() : null, $chunks); self::setOrGenerateChunk($manager, $generator, $this->chunkX, $this->chunkZ, $chunk); @@ -105,7 +104,7 @@ class PopulationTask extends AsyncTask{ $serialChunks = []; foreach($chunks as $i => $c){ - $serialChunks[$i] = $oldModCounts[$i] !== $c->getModificationCount() ? FastChunkSerializer::serializeTerrain($c) : null; + $serialChunks[$i] = $c->isTerrainDirty() ? FastChunkSerializer::serializeTerrain($c) : null; } $this->adjacentChunks = igbinary_serialize($serialChunks) ?? throw new AssumptionFailedError("igbinary_serialize() returned null"); }