SubChunk: rename defaultBlock -> emptyBlockId

this better describes the purpose, which is to identify air.
though, it might make more sense to make air just always have zero as air's runtime ID, since this parameter is apparently making plugin devs think that this is suitable to fill a chunk with a specific block ...
This commit is contained in:
Dylan K. Taylor 2020-11-27 13:33:25 +00:00
parent 4d42f0c3db
commit 4e94025b3b

View File

@ -29,7 +29,7 @@ use function count;
class SubChunk{
/** @var int */
private $defaultBlock;
private $emptyBlockId;
/** @var PalettedBlockArray[] */
private $blockLayers;
@ -43,8 +43,8 @@ class SubChunk{
*
* @param PalettedBlockArray[] $blocks
*/
public function __construct(int $default, array $blocks, ?LightArray $skyLight = null, ?LightArray $blockLight = null){
$this->defaultBlock = $default;
public function __construct(int $emptyBlockId, array $blocks, ?LightArray $skyLight = null, ?LightArray $blockLight = null){
$this->emptyBlockId = $emptyBlockId;
$this->blockLayers = $blocks;
$this->skyLight = $skyLight ?? LightArray::fill(15);
@ -71,14 +71,14 @@ class SubChunk{
public function getFullBlock(int $x, int $y, int $z) : int{
if(count($this->blockLayers) === 0){
return $this->defaultBlock;
return $this->emptyBlockId;
}
return $this->blockLayers[0]->get($x, $y, $z);
}
public function setFullBlock(int $x, int $y, int $z, int $block) : void{
if(count($this->blockLayers) === 0){
$this->blockLayers[] = new PalettedBlockArray($this->defaultBlock);
$this->blockLayers[] = new PalettedBlockArray($this->emptyBlockId);
}
$this->blockLayers[0]->set($x, $y, $z, $block);
}
@ -95,7 +95,7 @@ class SubChunk{
return -1;
}
for($y = 15; $y >= 0; --$y){
if($this->blockLayers[0]->get($x, $y, $z) !== $this->defaultBlock){
if($this->blockLayers[0]->get($x, $y, $z) !== $this->emptyBlockId){
return $y;
}
}
@ -131,7 +131,7 @@ class SubChunk{
$layer->collectGarbage();
foreach($layer->getPalette() as $p){
if($p !== $this->defaultBlock){
if($p !== $this->emptyBlockId){
continue 2;
}
}