mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Implemented light population, added Level->getFullLight()
This commit is contained in:
parent
d139e5f342
commit
b3c3f896a3
@ -543,6 +543,7 @@ class Block extends Position implements Metadatable{
|
||||
public $isPlaceable = true;
|
||||
public $hasPhysics = false;
|
||||
public $isFullBlock = true;
|
||||
public $lightLevel = 0;
|
||||
public $x = 0;
|
||||
public $y = 0;
|
||||
public $z = 0;
|
||||
|
@ -26,6 +26,9 @@ use pocketmine\level\Level;
|
||||
use pocketmine\Player;
|
||||
|
||||
class BrownMushroom extends Flowable{
|
||||
|
||||
public $lightLevel = 1;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::BROWN_MUSHROOM, 0, "Brown Mushroom");
|
||||
$this->hardness = 0;
|
||||
|
@ -32,6 +32,9 @@ use pocketmine\tile\Furnace;
|
||||
use pocketmine\tile\Tile;
|
||||
|
||||
class BurningFurnace extends Solid{
|
||||
|
||||
public $lightLevel = 13;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::BURNING_FURNACE, $meta, "Burning Furnace");
|
||||
$this->isActivable = true;
|
||||
|
@ -24,6 +24,9 @@ namespace pocketmine\block;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
|
||||
class EndPortal extends Solid{
|
||||
|
||||
public $lightLevel = 1;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::END_PORTAL, $meta, "End Portal");
|
||||
$this->hardness = 18000000;
|
||||
|
@ -32,6 +32,7 @@ use pocketmine\Server;
|
||||
class Fire extends Flowable{
|
||||
|
||||
public $hasEntityCollision = true;
|
||||
public $lightLevel = 15;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::FIRE, $meta, "Fire");
|
||||
|
@ -23,6 +23,9 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class GlowingObsidian extends Solid{
|
||||
|
||||
public $lightLevel = 12;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::GLOWING_OBSIDIAN, $meta, "Glowing Obsidian");
|
||||
}
|
||||
|
@ -25,6 +25,9 @@ use pocketmine\item\Item;
|
||||
use pocketmine\level\Level;
|
||||
|
||||
class GlowingRedstoneOre extends Solid{
|
||||
|
||||
public $lightLevel = 9;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
|
||||
$this->hardness = 15;
|
||||
|
@ -24,6 +24,9 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Glowstone extends Transparent{
|
||||
|
||||
public $lightLevel = 15;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::GLOWSTONE_BLOCK, 0, "Glowstone");
|
||||
$this->hardness = 1.5;
|
||||
|
@ -31,6 +31,8 @@ use pocketmine\Server;
|
||||
|
||||
class Lava extends Liquid{
|
||||
|
||||
public $lightLevel = 15;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::LAVA, $meta, "Lava");
|
||||
$this->hardness = 0;
|
||||
|
@ -25,6 +25,9 @@ use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
class LitPumpkin extends Solid{
|
||||
|
||||
public $lightLevel = 15;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::LIT_PUMPKIN, "Jack o'Lantern");
|
||||
$this->hardness = 5;
|
||||
|
@ -26,6 +26,9 @@ use pocketmine\level\Level;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Torch extends Flowable{
|
||||
|
||||
public $lightLevel = 15;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::TORCH, $meta, "Torch");
|
||||
$this->hardness = 0;
|
||||
|
@ -881,6 +881,20 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
*/
|
||||
|
||||
public function getFullLight(Vector3 $pos){
|
||||
$chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, true);
|
||||
$level = 0;
|
||||
if($chunk instanceof FullChunk){
|
||||
$level = $chunk->getBlockSkyLight($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f);
|
||||
//TODO: decrease light level by time of day
|
||||
if($level < 15){
|
||||
$level = max($chunk->getBlockLight($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f));
|
||||
}
|
||||
}
|
||||
|
||||
return $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Block object on the Vector3 location
|
||||
*
|
||||
@ -911,6 +925,67 @@ class Level implements ChunkManager, Metadatable{
|
||||
return $this->blockCache[$index] = Block::get($blockId, $meta, $this->temporalPosition->setComponents($pos->x, $pos->y, $pos->z));
|
||||
}
|
||||
|
||||
public function updateAllLight(Vector3 $pos){
|
||||
$this->updateBlockSkyLight($pos);
|
||||
$this->updateBlockLight($pos);
|
||||
}
|
||||
|
||||
public function updateBlockSkyLight(Vector3 $pos){
|
||||
$block = ($pos instanceof Block) ? $pos : $this->getBlock($pos);
|
||||
|
||||
$current = $this->getBlockSkyLightAt($pos->x, $pos->y, $pos->z);
|
||||
$decrease = ($block->isSolid and !$block->isTransparent) ? 15 : 0;
|
||||
|
||||
$calculatedLight = $this->computeBlockSkyLight($block, $current, $decrease);
|
||||
|
||||
if($calculatedLight !== $current){
|
||||
$this->setBlockSkyLightAt($block->x, $block->y, $block->z, $calculatedLight);
|
||||
for($side = 0; $side <= 5; ++$side){
|
||||
$this->updateBlockSkyLight($block->getSide($side));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateBlockLight(Vector3 $pos){
|
||||
$block = ($pos instanceof Block) ? $pos : $this->getBlock($pos);
|
||||
|
||||
$current = $this->getBlockLightAt($pos->x, $pos->y, $pos->z);
|
||||
$decrease = ($block->isSolid and !$block->isTransparent) ? 15 : 1;
|
||||
|
||||
$calculatedLight = $this->computeBlockLight($block, $block->lightLevel, $decrease);
|
||||
|
||||
if($calculatedLight !== $current){
|
||||
$this->setBlockLightAt($block->x, $block->y, $block->z, $calculatedLight);
|
||||
for($side = 0; $side <= 5; ++$side){
|
||||
$this->updateBlockLight($block->getSide($side));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function computeBlockLight(Vector3 $pos, $current, $decrease){
|
||||
return max(
|
||||
$current,
|
||||
$this->getBlockLightAt($pos->x - 1, $pos->y, $pos->z) - $decrease,
|
||||
$this->getBlockLightAt($pos->x + 1, $pos->y, $pos->z) - $decrease,
|
||||
$this->getBlockLightAt($pos->x, $pos->y - 1, $pos->z) - $decrease,
|
||||
$this->getBlockLightAt($pos->x, $pos->y + 1, $pos->z) - $decrease,
|
||||
$this->getBlockLightAt($pos->x, $pos->y, $pos->z - 1) - $decrease,
|
||||
$this->getBlockLightAt($pos->x, $pos->y, $pos->z + 1) - $decrease
|
||||
);
|
||||
}
|
||||
|
||||
protected function computeBlockSkyLight(Vector3 $pos, $current, $decrease){
|
||||
return max(
|
||||
$current,
|
||||
$this->getBlockSkyLightAt($pos->x - 1, $pos->y, $pos->z) - $decrease,
|
||||
$this->getBlockSkyLightAt($pos->x + 1, $pos->y, $pos->z) - $decrease,
|
||||
$this->getBlockSkyLightAt($pos->x, $pos->y - 1, $pos->z) - $decrease,
|
||||
$this->getBlockSkyLightAt($pos->x, $pos->y + 1, $pos->z) - $decrease,
|
||||
$this->getBlockSkyLightAt($pos->x, $pos->y, $pos->z - 1) - $decrease,
|
||||
$this->getBlockSkyLightAt($pos->x, $pos->y, $pos->z + 1) - $decrease
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets on Vector3 the data from a Block object,
|
||||
* does block updates and puts the changes to the send queue.
|
||||
@ -973,6 +1048,8 @@ class Level implements ChunkManager, Metadatable{
|
||||
}*/
|
||||
|
||||
if($update === true){
|
||||
$this->updateAllLight($block);
|
||||
|
||||
$this->updateAround($pos);
|
||||
$this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block));
|
||||
if(!$ev->isCancelled()){
|
||||
|
Loading…
x
Reference in New Issue
Block a user