Calculate skylight on chunk population

This commit is contained in:
Shoghi Cervantes
2015-05-06 16:57:49 +02:00
parent 44b5c23ee1
commit fb03df3d06
6 changed files with 72 additions and 4 deletions

View File

@ -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){
}
}