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.
This commit is contained in:
Dylan K. Taylor 2020-10-31 22:46:33 +00:00
parent 5701e733cc
commit b270029161
4 changed files with 8 additions and 8 deletions

View File

@ -152,7 +152,7 @@ class Chunk{
* Sets the blockstate at the given coordinate by internal ID. * Sets the blockstate at the given coordinate by internal ID.
*/ */
public function setFullBlock(int $x, int $y, int $z, int $block) : void{ 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; $this->dirtyFlags |= self::DIRTY_FLAG_TERRAIN;
} }
@ -516,9 +516,9 @@ class Chunk{
return $this->subChunks[$y]; return $this->subChunks[$y];
} }
public function getWritableSubChunk(int $y) : SubChunk{ public function getSubChunkChecked(int $y) : SubChunk{
if($y < 0 || $y >= $this->subChunks->getSize()){ 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]; return $this->subChunks[$y];
} }

View File

@ -156,7 +156,7 @@ class Flat extends Generator{
$count = count($this->structure); $count = count($this->structure);
for($sy = 0; $sy < $count; $sy += 16){ 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){ for($y = 0; $y < 16 and isset($this->structure[$y | $sy]); ++$y){
$id = $this->structure[$y | $sy]; $id = $this->structure[$y | $sy];

View File

@ -104,10 +104,10 @@ class LightPopulationTask extends AsyncTask{
$blockLightArrays = igbinary_unserialize($this->resultBlockLightArrays); $blockLightArrays = igbinary_unserialize($this->resultBlockLightArrays);
foreach($skyLightArrays as $y => $array){ foreach($skyLightArrays as $y => $array){
$chunk->getWritableSubChunk($y)->setBlockSkyLightArray($array); $chunk->getSubChunkChecked($y)->setBlockSkyLightArray($array);
} }
foreach($blockLightArrays as $y => $array){ foreach($blockLightArrays as $y => $array){
$chunk->getWritableSubChunk($y)->setBlockLightArray($array); $chunk->getSubChunkChecked($y)->setBlockLightArray($array);
} }
$chunk->setLightPopulated(); $chunk->setLightPopulated();
} }

View File

@ -111,10 +111,10 @@ class SkyLightUpdate extends LightUpdate{
$lowestClearSubChunk = ($highestHeightMapPlusOne >> 4) + (($highestHeightMapPlusOne & 0xf) !== 0 ? 1 : 0); $lowestClearSubChunk = ($highestHeightMapPlusOne >> 4) + (($highestHeightMapPlusOne & 0xf) !== 0 ? 1 : 0);
$chunkHeight = $chunk->getSubChunks()->count(); $chunkHeight = $chunk->getSubChunks()->count();
for($y = 0; $y < $lowestClearSubChunk && $y < $chunkHeight; $y++){ 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++){ for($y = $lowestClearSubChunk, $yMax = $chunkHeight; $y < $yMax; $y++){
$chunk->getWritableSubChunk($y)->setBlockSkyLightArray(LightArray::fill(15)); $chunk->getSubChunkChecked($y)->setBlockSkyLightArray(LightArray::fill(15));
} }
$lightSources = 0; $lightSources = 0;