Implemented sky light generation-time population and updating, obsolete and close #160

This commit is contained in:
Dylan K. Taylor
2017-04-18 13:05:01 +01:00
parent 5e6a0e7ba0
commit dab73d8950
13 changed files with 417 additions and 154 deletions

View File

@ -54,6 +54,8 @@ class Block extends Position implements BlockIds, Metadatable{
public static $hardness = null;
/** @var \SplFixedArray */
public static $transparent = null;
/** @var \SplFixedArray */
public static $diffusesSkyLight = null;
protected $id;
protected $meta = 0;
@ -70,6 +72,7 @@ class Block extends Position implements BlockIds, Metadatable{
self::$solid = new \SplFixedArray(256);
self::$hardness = new \SplFixedArray(256);
self::$transparent = new \SplFixedArray(256);
self::$diffusesSkyLight = new \SplFixedArray(256);
self::$list[self::AIR] = Air::class;
self::$list[self::STONE] = Stone::class;
self::$list[self::GRASS] = Grass::class;
@ -254,31 +257,20 @@ class Block extends Position implements BlockIds, Metadatable{
for($data = 0; $data < 16; ++$data){
self::$fullList[($id << 4) | $data] = new $class($data);
}
self::$solid[$id] = $block->isSolid();
self::$transparent[$id] = $block->isTransparent();
self::$hardness[$id] = $block->getHardness();
self::$light[$id] = $block->getLightLevel();
if($block->isSolid()){
if($block->isTransparent()){
if($block instanceof Liquid or $block instanceof Ice){
self::$lightFilter[$id] = 2;
}else{
self::$lightFilter[$id] = 1;
}
}else{
self::$lightFilter[$id] = 15;
}
}else{
self::$lightFilter[$id] = 1;
}
}else{
self::$lightFilter[$id] = 1;
$block = new UnknownBlock($id);
for($data = 0; $data < 16; ++$data){
self::$fullList[($id << 4) | $data] = new UnknownBlock($id, $data);
}
}
self::$solid[$id] = $block->isSolid();
self::$transparent[$id] = $block->isTransparent();
self::$hardness[$id] = $block->getHardness();
self::$light[$id] = $block->getLightLevel();
self::$lightFilter[$id] = $block->getLightFilter() + 1;
self::$diffusesSkyLight[$id] = $block->diffusesSkyLight();
}
}
}
@ -419,6 +411,29 @@ class Block extends Position implements BlockIds, Metadatable{
return 0;
}
/**
* Returns the amount of light this block will filter out when light passes through this block.
* This value is used in light spread calculation.
*
* @return int 0-15
*/
public function getLightFilter() : int{
return 15;
}
/**
* Returns whether this block will diffuse sky light passing through it vertically.
* Diffusion means that full-strength sky light passing through this block will not be reduced, but will start being filtered below the block.
* Examples of this behaviour include leaves and cobwebs.
*
* Light-diffusing blocks are included by the heightmap.
*
* @return bool
*/
public function diffusesSkyLight() : bool{
return false;
}
/**
* AKA: Block->isPlaceable
*

View File

@ -57,4 +57,8 @@ class Cobweb extends Flowable{
//TODO: correct drops
return [];
}
public function diffusesSkyLight() : bool{
return true;
}
}

View File

@ -40,6 +40,10 @@ class Ice extends Transparent{
return 0.5;
}
public function getLightFilter() : int{
return 2;
}
public function getToolType(){
return Tool::TYPE_PICKAXE;
}

View File

@ -60,6 +60,10 @@ class Leaves extends Transparent{
return $names[$this->meta & 0x03];
}
public function diffusesSkyLight() : bool{
return true;
}
private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){
++$check;
$index = $pos->x . "." . $pos->y . "." . $pos->z;

View File

@ -27,4 +27,8 @@ abstract class Transparent extends Block{
public function isTransparent(){
return true;
}
public function getLightFilter() : int{
return 0;
}
}

View File

@ -37,6 +37,10 @@ class Water extends Liquid{
return "Water";
}
public function getLightFilter() : int{
return 2;
}
public function onEntityCollide(Entity $entity){
$entity->resetFallDistance();
if($entity->fireTicks > 0){