mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 19:02:59 +00:00
Move heightmap calculation logic to SkyLightUpdate
This commit is contained in:
@ -195,71 +195,6 @@ class Chunk{
|
||||
$this->heightMap->set($x, $z, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates the heightmap for the whole chunk.
|
||||
*
|
||||
* @param \SplFixedArray|bool[] $directSkyLightBlockers
|
||||
* @phpstan-param \SplFixedArray<bool> $directSkyLightBlockers
|
||||
*/
|
||||
public function recalculateHeightMap(\SplFixedArray $directSkyLightBlockers) : void{
|
||||
$maxSubChunkY = $this->subChunks->count() - 1;
|
||||
for(; $maxSubChunkY >= 0; $maxSubChunkY--){
|
||||
if(!$this->getSubChunk($maxSubChunkY)->isEmptyFast()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($maxSubChunkY === -1){ //whole column is definitely empty
|
||||
$this->setHeightMapArray(array_fill(0, 256, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$y = null;
|
||||
for($subChunkY = $maxSubChunkY; $subChunkY >= 0; $subChunkY--){
|
||||
$subHighestBlockY = $this->getSubChunk($subChunkY)->getHighestBlockAt($x, $z);
|
||||
if($subHighestBlockY !== -1){
|
||||
$y = ($subChunkY * 16) + $subHighestBlockY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($y === null){ //no blocks in the column
|
||||
$this->setHeightMap($x, $z, 0);
|
||||
}else{
|
||||
for(; $y >= 0; --$y){
|
||||
if($directSkyLightBlockers[$this->getFullBlock($x, $y, $z)]){
|
||||
$this->setHeightMap($x, $z, $y + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates the heightmap for the block column at the specified X/Z chunk coordinates
|
||||
*
|
||||
* @param int $x 0-15
|
||||
* @param int $z 0-15
|
||||
* @param \SplFixedArray|bool[] $directSkyLightBlockers
|
||||
* @phpstan-param \SplFixedArray<bool> $directSkyLightBlockers
|
||||
*
|
||||
* @return int New calculated heightmap value (0-256 inclusive)
|
||||
*/
|
||||
public function recalculateHeightMapColumn(int $x, int $z, \SplFixedArray $directSkyLightBlockers) : int{
|
||||
$y = $this->getHighestBlockAt($x, $z);
|
||||
for(; $y >= 0; --$y){
|
||||
if($directSkyLightBlockers[$this->getFullBlock($x, $y, $z)]){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->setHeightMap($x, $z, $y + 1);
|
||||
return $y + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the biome ID at the specified X/Z chunk block coordinates
|
||||
*
|
||||
|
Reference in New Issue
Block a user