From b2700291615637dc338aa080babf1804f140d129 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 31 Oct 2020 22:46:33 +0000 Subject: [PATCH] Rename Chunk::getWritableSubChunk() -> Chunk::getSubChunkChecked() this is not specific to 'writable', it's just an opt-in to checked bounds so that an EmptySubChunk will never be received. --- src/world/format/Chunk.php | 6 +++--- src/world/generator/Flat.php | 2 +- src/world/light/LightPopulationTask.php | 4 ++-- src/world/light/SkyLightUpdate.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php index 95e2afba5..30f95e792 100644 --- a/src/world/format/Chunk.php +++ b/src/world/format/Chunk.php @@ -152,7 +152,7 @@ class Chunk{ * Sets the blockstate at the given coordinate by internal ID. */ public function setFullBlock(int $x, int $y, int $z, int $block) : void{ - $this->getWritableSubChunk($y >> 4)->setFullBlock($x, $y & 0xf, $z, $block); + $this->getSubChunkChecked($y >> 4)->setFullBlock($x, $y & 0xf, $z, $block); $this->dirtyFlags |= self::DIRTY_FLAG_TERRAIN; } @@ -516,9 +516,9 @@ class Chunk{ return $this->subChunks[$y]; } - public function getWritableSubChunk(int $y) : SubChunk{ + public function getSubChunkChecked(int $y) : SubChunk{ if($y < 0 || $y >= $this->subChunks->getSize()){ - throw new \InvalidArgumentException("Cannot get subchunk $y for writing"); + throw new \InvalidArgumentException("Invalid subchunk Y coordinate $y"); } return $this->subChunks[$y]; } diff --git a/src/world/generator/Flat.php b/src/world/generator/Flat.php index 87b8b3fe2..62dcf6590 100644 --- a/src/world/generator/Flat.php +++ b/src/world/generator/Flat.php @@ -156,7 +156,7 @@ class Flat extends Generator{ $count = count($this->structure); for($sy = 0; $sy < $count; $sy += 16){ - $subchunk = $this->chunk->getWritableSubChunk($sy >> 4); + $subchunk = $this->chunk->getSubChunkChecked($sy >> 4); for($y = 0; $y < 16 and isset($this->structure[$y | $sy]); ++$y){ $id = $this->structure[$y | $sy]; diff --git a/src/world/light/LightPopulationTask.php b/src/world/light/LightPopulationTask.php index 896c7a645..b171d06e9 100644 --- a/src/world/light/LightPopulationTask.php +++ b/src/world/light/LightPopulationTask.php @@ -104,10 +104,10 @@ class LightPopulationTask extends AsyncTask{ $blockLightArrays = igbinary_unserialize($this->resultBlockLightArrays); foreach($skyLightArrays as $y => $array){ - $chunk->getWritableSubChunk($y)->setBlockSkyLightArray($array); + $chunk->getSubChunkChecked($y)->setBlockSkyLightArray($array); } foreach($blockLightArrays as $y => $array){ - $chunk->getWritableSubChunk($y)->setBlockLightArray($array); + $chunk->getSubChunkChecked($y)->setBlockLightArray($array); } $chunk->setLightPopulated(); } diff --git a/src/world/light/SkyLightUpdate.php b/src/world/light/SkyLightUpdate.php index 4408a97e5..d6bbdca5f 100644 --- a/src/world/light/SkyLightUpdate.php +++ b/src/world/light/SkyLightUpdate.php @@ -111,10 +111,10 @@ class SkyLightUpdate extends LightUpdate{ $lowestClearSubChunk = ($highestHeightMapPlusOne >> 4) + (($highestHeightMapPlusOne & 0xf) !== 0 ? 1 : 0); $chunkHeight = $chunk->getSubChunks()->count(); for($y = 0; $y < $lowestClearSubChunk && $y < $chunkHeight; $y++){ - $chunk->getWritableSubChunk($y)->setBlockSkyLightArray(LightArray::fill(0)); + $chunk->getSubChunkChecked($y)->setBlockSkyLightArray(LightArray::fill(0)); } for($y = $lowestClearSubChunk, $yMax = $chunkHeight; $y < $yMax; $y++){ - $chunk->getWritableSubChunk($y)->setBlockSkyLightArray(LightArray::fill(15)); + $chunk->getSubChunkChecked($y)->setBlockSkyLightArray(LightArray::fill(15)); } $lightSources = 0;