Chunk: make all parameters of __construct() mandatory and non-nullable

having the constructor fill in defaults for these invariably causes bugs.
This commit is contained in:
Dylan K. Taylor
2021-10-25 20:22:50 +01:00
parent d53347454b
commit baba25953f
7 changed files with 16 additions and 6 deletions

View File

@ -68,7 +68,7 @@ class Chunk{
/**
* @param SubChunk[] $subChunks
*/
public function __construct(array $subChunks = [], ?BiomeArray $biomeIds = null, bool $terrainPopulated = false){
public function __construct(array $subChunks, BiomeArray $biomeIds, bool $terrainPopulated){
$this->subChunks = new \SplFixedArray(Chunk::MAX_SUBCHUNKS);
foreach($this->subChunks as $y => $null){
@ -77,7 +77,7 @@ class Chunk{
$val = ($this->subChunks->getSize() * SubChunk::EDGE_LENGTH);
$this->heightMap = HeightArray::fill($val); //TODO: what about lazily initializing this?
$this->biomeIds = $biomeIds ?? BiomeArray::fill(BiomeIds::OCEAN);
$this->biomeIds = $biomeIds;
$this->terrainPopulated = $terrainPopulated;
}