Added __clone() for Chunk and SubChunk

we need this because the flatworld generator uses clone to produce new chunks, so we don't want the chunks getting fucked up.
This commit is contained in:
Dylan K. Taylor
2020-11-01 16:14:25 +00:00
parent 1d551af54a
commit 315962c12c
4 changed files with 114 additions and 0 deletions

View File

@ -476,6 +476,15 @@ class Chunk{
}
}
public function __clone(){
//we don't bother cloning entities or tiles since it's impractical to do so (too many dependencies)
$this->subChunks = \SplFixedArray::fromArray(array_map(function(SubChunk $subChunk) : SubChunk{
return clone $subChunk;
}, $this->subChunks->toArray()));
$this->heightMap = clone $this->heightMap;
$this->biomeIds = clone $this->biomeIds;
}
/**
* Hashes the given chunk block coordinates into a single integer.
*