Further refactors to prepare for y=-64 lower limit

This commit is contained in:
Dylan K. Taylor
2021-03-18 00:08:16 +00:00
parent b844c4266d
commit eb9a68edee
17 changed files with 101 additions and 51 deletions

View File

@ -131,17 +131,17 @@ class Chunk{
* @param int $x 0-15
* @param int $z 0-15
*
* @return int 0-255, or -1 if there are no blocks in the column
* @return int|null 0-255, or null if there are no blocks in the column
*/
public function getHighestBlockAt(int $x, int $z) : int{
public function getHighestBlockAt(int $x, int $z) : ?int{
for($y = $this->subChunks->count() - 1; $y >= 0; --$y){
$height = $this->getSubChunk($y)->getHighestBlockAt($x, $z) | ($y << 4);
if($height !== -1){
return $height;
$height = $this->getSubChunk($y)->getHighestBlockAt($x, $z);
if($height !== null){
return $height | ($y << 4);
}
}
return -1;
return null;
}
/**

View File

@ -96,9 +96,9 @@ class SubChunk{
return $this->blockLayers;
}
public function getHighestBlockAt(int $x, int $z) : int{
public function getHighestBlockAt(int $x, int $z) : ?int{
if(count($this->blockLayers) === 0){
return -1;
return null;
}
for($y = 15; $y >= 0; --$y){
if($this->blockLayers[0]->get($x, $y, $z) !== $this->emptyBlockId){
@ -106,7 +106,7 @@ class SubChunk{
}
}
return -1; //highest block not in this subchunk
return null; //highest block not in this subchunk
}
public function getBlockSkyLightArray() : LightArray{

View File

@ -36,10 +36,15 @@ interface WorldProvider{
*/
public function __construct(string $path);
/**
* Returns the lowest buildable Y coordinate of this world
*/
public function getWorldMinY() : int;
/**
* Gets the build height limit of this world
*/
public function getWorldHeight() : int;
public function getWorldMaxY() : int;
public function getPath() : string;

View File

@ -132,7 +132,11 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
return new BedrockWorldData($this->getPath() . DIRECTORY_SEPARATOR . "level.dat");
}
public function getWorldHeight() : int{
public function getWorldMinY() : int{
return 0;
}
public function getWorldMaxY() : int{
return 256;
}

View File

@ -51,7 +51,11 @@ class Anvil extends RegionWorldProvider{
return 19133;
}
public function getWorldHeight() : int{
public function getWorldMinY() : int{
return 0;
}
public function getWorldMaxY() : int{
//TODO: add world height options
return 256;
}

View File

@ -106,7 +106,11 @@ class McRegion extends RegionWorldProvider{
return 19132;
}
public function getWorldHeight() : int{
public function getWorldMinY() : int{
return 0;
}
public function getWorldMaxY() : int{
//TODO: add world height options
return 128;
}

View File

@ -50,7 +50,11 @@ class PMAnvil extends RegionWorldProvider{
return -1; //Not a PC format, only PocketMine-MP
}
public function getWorldHeight() : int{
public function getWorldMinY() : int{
return 0;
}
public function getWorldMaxY() : int{
return 256;
}
}