mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-04 17:06:16 +00:00
Calculate skylight on chunk population
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
|
||||
namespace pocketmine\level\format\generic;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\level\format\FullChunk;
|
||||
use pocketmine\level\format\LevelProvider;
|
||||
@ -156,6 +157,12 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
$this->hasChanged = false;
|
||||
|
||||
}
|
||||
|
||||
if(!$this->isLightPopulated()){
|
||||
$this->recalculateHeightMap();
|
||||
$this->populateSkyLight();
|
||||
$this->setLightPopulated();
|
||||
}
|
||||
}
|
||||
|
||||
public function getX(){
|
||||
@ -230,6 +237,27 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
}
|
||||
}
|
||||
|
||||
public function populateSkyLight(){
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$top = $this->getHeightMap($x, $z);
|
||||
for($y = 127; $y > $top; --$y){
|
||||
$this->setBlockSkyLight($x, $y, $z, 15);
|
||||
}
|
||||
|
||||
for($y = $top; $y >= 0; --$y){
|
||||
if(Block::$solid[$this->getBlockId($x, $y, $z)]){
|
||||
break;
|
||||
}
|
||||
|
||||
$this->setBlockSkyLight($x, $y, $z, 15);
|
||||
}
|
||||
|
||||
$this->setHeightMap($x, $z, $this->getHighestBlockAt($x, $z, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getHighestBlockAt($x, $z, $cache = true){
|
||||
if($cache){
|
||||
$h = $this->getHeightMap($x, $z);
|
||||
@ -377,4 +405,12 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
return $this->toBinary();
|
||||
}
|
||||
|
||||
public function isLightPopulated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setLightPopulated($value = 1){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user