Chunk: make setSubChunk() throw exception on invalid Y instead of returning false

This commit is contained in:
Dylan K. Taylor 2019-10-22 21:13:08 +01:00
parent b8c857df64
commit 295d14e0d9

View File

@ -685,12 +685,10 @@ class Chunk{
* @param int $y * @param int $y
* @param SubChunkInterface|null $subChunk * @param SubChunkInterface|null $subChunk
* @param bool $allowEmpty Whether to check if the chunk is empty, and if so replace it with an empty stub * @param bool $allowEmpty Whether to check if the chunk is empty, and if so replace it with an empty stub
*
* @return bool
*/ */
public function setSubChunk(int $y, ?SubChunkInterface $subChunk, bool $allowEmpty = false) : bool{ public function setSubChunk(int $y, ?SubChunkInterface $subChunk, bool $allowEmpty = false) : void{
if($y < 0 or $y >= $this->height){ if($y < 0 or $y >= $this->height){
return false; throw new \InvalidArgumentException("Invalid subchunk Y coordinate $y");
} }
if($subChunk === null or ($subChunk->isEmpty() and !$allowEmpty)){ if($subChunk === null or ($subChunk->isEmpty() and !$allowEmpty)){
$this->subChunks[$y] = EmptySubChunk::getInstance(); $this->subChunks[$y] = EmptySubChunk::getInstance();
@ -698,7 +696,6 @@ class Chunk{
$this->subChunks[$y] = $subChunk; $this->subChunks[$y] = $subChunk;
} }
$this->setDirtyFlag(self::DIRTY_FLAG_TERRAIN, true); $this->setDirtyFlag(self::DIRTY_FLAG_TERRAIN, true);
return true;
} }
/** /**