Rename Chunk::getSubChunkChecked() -> getSubChunk()

This commit is contained in:
Dylan K. Taylor 2020-10-31 23:12:03 +00:00
parent e09d78238f
commit 4549522289
7 changed files with 16 additions and 16 deletions

View File

@ -43,7 +43,7 @@ final class ChunkSerializer{
*/
public static function getSubChunkCount(Chunk $chunk) : int{
for($count = $chunk->getSubChunks()->count(); $count > 0; --$count){
if($chunk->getSubChunkChecked($count - 1)->isEmptyFast()){
if($chunk->getSubChunk($count - 1)->isEmptyFast()){
continue;
}
return $count;
@ -56,7 +56,7 @@ final class ChunkSerializer{
$stream = new PacketSerializer();
$subChunkCount = self::getSubChunkCount($chunk);
for($y = 0; $y < $subChunkCount; ++$y){
$layers = $chunk->getSubChunkChecked($y)->getBlockLayers();
$layers = $chunk->getSubChunk($y)->getBlockLayers();
$stream->putByte(8); //version
$stream->putByte(count($layers));

View File

@ -1838,7 +1838,7 @@ class World implements ChunkManager{
return $y >= self::Y_MAX ? 15 : 0;
}
if(($chunk = $this->getChunk($x >> 4, $z >> 4)) !== null){
return $chunk->getSubChunkChecked($y >> 4)->getBlockSkyLightArray()->get($x & 0x0f, $y & 0xf, $z & 0x0f);
return $chunk->getSubChunk($y >> 4)->getBlockSkyLightArray()->get($x & 0x0f, $y & 0xf, $z & 0x0f);
}
return 0; //TODO: this should probably throw instead (light not calculated yet)
}
@ -1853,7 +1853,7 @@ class World implements ChunkManager{
return 0;
}
if(($chunk = $this->getChunk($x >> 4, $z >> 4)) !== null){
return $chunk->getSubChunkChecked($y >> 4)->getBlockLightArray()->get($x & 0x0f, $y & 0xf, $z & 0x0f);
return $chunk->getSubChunk($y >> 4)->getBlockLightArray()->get($x & 0x0f, $y & 0xf, $z & 0x0f);
}
return 0; //TODO: this should probably throw instead (light not calculated yet)
}

View File

@ -145,14 +145,14 @@ class Chunk{
* @return int bitmap, (id << 4) | meta
*/
public function getFullBlock(int $x, int $y, int $z) : int{
return $this->getSubChunkChecked($y >> 4)->getFullBlock($x, $y & 0x0f, $z);
return $this->getSubChunk($y >> 4)->getFullBlock($x, $y & 0x0f, $z);
}
/**
* Sets the blockstate at the given coordinate by internal ID.
*/
public function setFullBlock(int $x, int $y, int $z, int $block) : void{
$this->getSubChunkChecked($y >> 4)->setFullBlock($x, $y & 0xf, $z, $block);
$this->getSubChunk($y >> 4)->setFullBlock($x, $y & 0xf, $z, $block);
$this->dirtyFlags |= self::DIRTY_FLAG_TERRAIN;
}
@ -166,7 +166,7 @@ class Chunk{
*/
public function getHighestBlockAt(int $x, int $z) : int{
for($y = $this->subChunks->count() - 1; $y >= 0; --$y){
$height = $this->getSubChunkChecked($y)->getHighestBlockAt($x, $z) | ($y << 4);
$height = $this->getSubChunk($y)->getHighestBlockAt($x, $z) | ($y << 4);
if($height !== -1){
return $height;
}
@ -204,7 +204,7 @@ class Chunk{
public function recalculateHeightMap(\SplFixedArray $directSkyLightBlockers) : void{
$maxSubChunkY = $this->subChunks->count() - 1;
for(; $maxSubChunkY >= 0; $maxSubChunkY--){
if(!$this->getSubChunkChecked($maxSubChunkY)->isEmptyFast()){
if(!$this->getSubChunk($maxSubChunkY)->isEmptyFast()){
break;
}
}
@ -217,7 +217,7 @@ class Chunk{
for($x = 0; $x < 16; ++$x){
$y = null;
for($subChunkY = $maxSubChunkY; $subChunkY >= 0; $subChunkY--){
$subHighestBlockY = $this->getSubChunkChecked($subChunkY)->getHighestBlockAt($x, $z);
$subHighestBlockY = $this->getSubChunk($subChunkY)->getHighestBlockAt($x, $z);
if($subHighestBlockY !== -1){
$y = ($subChunkY * 16) + $subHighestBlockY;
break;
@ -505,7 +505,7 @@ class Chunk{
$this->dirtyFlags = 0;
}
public function getSubChunkChecked(int $y) : SubChunk{
public function getSubChunk(int $y) : SubChunk{
if($y < 0 || $y >= $this->subChunks->getSize()){
throw new \InvalidArgumentException("Invalid subchunk Y coordinate $y");
}

View File

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

View File

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

View File

@ -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->getSubChunkChecked($y)->setBlockSkyLightArray(LightArray::fill(0));
$chunk->getSubChunk($y)->setBlockSkyLightArray(LightArray::fill(0));
}
for($y = $lowestClearSubChunk, $yMax = $chunkHeight; $y < $yMax; $y++){
$chunk->getSubChunkChecked($y)->setBlockSkyLightArray(LightArray::fill(15));
$chunk->getSubChunk($y)->setBlockSkyLightArray(LightArray::fill(15));
}
$lightSources = 0;

View File

@ -77,7 +77,7 @@ class SubChunkExplorer{
return SubChunkExplorerStatus::INVALID;
}
$this->currentSubChunk = $this->currentChunk->getSubChunkChecked($y >> 4);
$this->currentSubChunk = $this->currentChunk->getSubChunk($y >> 4);
if($this->onSubChunkChangeFunc !== null){
($this->onSubChunkChangeFunc)();
}