diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index a4d77bd0..b9fcb543 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -18,6 +18,7 @@ class LevelAPI{ $this->server->api->console->register("save-on", "", [$this, "commandHandler"]); $this->server->api->console->register("save-off", "", [$this, "commandHandler"]); $this->server->api->console->register("setwspawn", "Set the spawn position for your current world. ", [$this, "commandHandler"]); + $this->default = $this->server->api->getProperty("level-name"); if($this->loadLevel($this->default) === false){ $this->generateLevel($this->default, $this->server->seed); diff --git a/src/Player.php b/src/Player.php index 24e62794..cf6fc528 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1737,6 +1737,7 @@ class Player{ } public function entityTick(){ + if($this->isSleeping) ++$this->sleepingTime; if($this->server->difficulty == 0 && $this->entity->counter % (20 * 15) == 0){ if($this->entity->health < 20 && $this->entity->health > 0){ diff --git a/src/material/Block.php b/src/material/Block.php index 49e1af41..21527a26 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -160,6 +160,10 @@ abstract class Block extends Position{ public $y = 0; public $z = 0; public $slipperiness; + + public $lightEmission = 0; + public $lightBlock = 0; + public static function interact(Level $level, $x, $y, $z, Player $player){} public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){} diff --git a/src/material/StaticBlock.php b/src/material/StaticBlock.php index 73082ecd..30080e17 100644 --- a/src/material/StaticBlock.php +++ b/src/material/StaticBlock.php @@ -22,10 +22,13 @@ class StaticBlock public static $destroyTime = []; public static $slipperiness = []; public static $boundingBoxes = []; + public static $lightBlock = []; + public static $lightEmission = []; public static $minXs = [], $minYs = [], $minZs = [], $maxXs = [], $maxYs = [], $maxZs = []; public static function init(){ self::$NULL_BOUNDS = new AxisAlignedBB(0, 0, 0, 0, 0, 0); + for($i = 0; $i < 256; ++$i) self::$lightBlock[$i] = self::$lightEmission[$i] = 0; foreach(Block::$class as $nonstaticname){ /**@var Block $b*/ $b = new $nonstaticname(); @@ -43,6 +46,8 @@ class StaticBlock self::$hardness[$b->getID()] = $b->getHardness(); self::$destroyTime[$b->getID()] = $b->breakTime; self::$material[$b->getID()] = $b->material; + self::$lightBlock[$b->getID()] = $b->lightBlock; + self::$lightEmission[$b->getID()] = $b->lightEmission; self::$prealloc[$b->getID()] = $b; $b::$blockID = $b->getID(); FireBlock::setFlammabilityAndCatchingChance($b->getID(), 0, 0); diff --git a/src/material/block/attachable/TorchBlock.php b/src/material/block/attachable/TorchBlock.php index 87d7cc36..bbd181cc 100644 --- a/src/material/block/attachable/TorchBlock.php +++ b/src/material/block/attachable/TorchBlock.php @@ -7,6 +7,7 @@ class TorchBlock extends FlowableBlock implements LightingBlock{ $this->hardness = 0; $this->breakTime = 0; $this->material = Material::$decoration; + $this->lightEmission = 14; } public function getMaxLightValue(){ diff --git a/src/material/block/liquid/LavaBlock.php b/src/material/block/liquid/LavaBlock.php index 3fbe9c65..7167bae4 100644 --- a/src/material/block/liquid/LavaBlock.php +++ b/src/material/block/liquid/LavaBlock.php @@ -8,6 +8,8 @@ class LavaBlock extends LiquidBlockDynamic implements LightingBlock{ $this->hardness = 500; //0 in vanilla $this->breakTime = -1; //in vanilla it is 0, but you cant interact with the block so it is not possible to destroy it $this->material = Material::$lava; + $this->lightEmission = 15; + $this->lightBlock = 255; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/liquid/StillLavaBlock.php b/src/material/block/liquid/StillLavaBlock.php index b4dff404..5fb354ac 100644 --- a/src/material/block/liquid/StillLavaBlock.php +++ b/src/material/block/liquid/StillLavaBlock.php @@ -8,6 +8,8 @@ class StillLavaBlock extends LiquidBlockStatic{ $this->hardness = 500; $this->breakTime = -1; //in vanilla it is 100, but you cant interact with the block so it is not possible to destroy it $this->material = Material::$lava; + $this->lightEmission = 15; + $this->lightBlock = 255; } public static function getTickDelay(){ diff --git a/src/material/block/liquid/StillWaterBlock.php b/src/material/block/liquid/StillWaterBlock.php index 5072cd5b..14682827 100644 --- a/src/material/block/liquid/StillWaterBlock.php +++ b/src/material/block/liquid/StillWaterBlock.php @@ -14,6 +14,7 @@ class StillWaterBlock extends LiquidBlockStatic{ $this->hardness = 500; $this->breakTime = -1; //in vanilla it is 100, but you cant interact with the block so it is not possible to destroy it $this->material = Material::$water; + $this->lightBlock = 3; } public static function getTickDelay(){ diff --git a/src/material/block/liquid/WaterBlock.php b/src/material/block/liquid/WaterBlock.php index 1b090e21..c55bada5 100644 --- a/src/material/block/liquid/WaterBlock.php +++ b/src/material/block/liquid/WaterBlock.php @@ -9,6 +9,7 @@ class WaterBlock extends LiquidBlockDynamic{ $this->hardness = 500; $this->breakTime = -1; //in vanilla it is 100, but you cant interact with the block so it is not possible to destroy it $this->material = Material::$water; + $this->lightBlock = 3; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/misc/FireBlock.php b/src/material/block/misc/FireBlock.php index 9e04dd86..99fc63cc 100644 --- a/src/material/block/misc/FireBlock.php +++ b/src/material/block/misc/FireBlock.php @@ -13,6 +13,7 @@ class FireBlock extends FlowableBlock implements LightingBlock{ $this->hardness = 0; $this->breakTime = 0; $this->material = Material::$fire; + $this->lightEmission = 15; } public static function getAABB(Level $level, $x, $y, $z){ return null; diff --git a/src/material/block/misc/NetherReactorBlock.php b/src/material/block/misc/NetherReactorBlock.php index 1d62a1ff..f7250d94 100644 --- a/src/material/block/misc/NetherReactorBlock.php +++ b/src/material/block/misc/NetherReactorBlock.php @@ -9,6 +9,7 @@ class NetherReactorBlock extends SolidBlock{ $this->hardness = 15; $this->breakTime = 3; $this->material = Material::$metal; + $this->lightBlock = 255; } public function onActivate(Item $item, Player $player){ diff --git a/src/material/block/misc/TNTBlock.php b/src/material/block/misc/TNTBlock.php index 3afbb6ab..19d847f8 100644 --- a/src/material/block/misc/TNTBlock.php +++ b/src/material/block/misc/TNTBlock.php @@ -8,6 +8,7 @@ class TNTBlock extends SolidBlock{ $this->breakTime = 0; $this->isActivable = true; $this->material = Material::$explosive; + $this->lightBlock = 255; } public function onActivate(Item $item, Player $player){ diff --git a/src/material/block/nonfull/CobwebBlock.php b/src/material/block/nonfull/CobwebBlock.php index 133bceee..010b1e37 100644 --- a/src/material/block/nonfull/CobwebBlock.php +++ b/src/material/block/nonfull/CobwebBlock.php @@ -9,6 +9,7 @@ class CobwebBlock extends FlowableBlock{ $this->hardness = 30; $this->breakTime = 4; $this->material = Material::$web; + $this->lightBlock = 1; } public static function getAABB(Level $level, $x, $y, $z){ diff --git a/src/material/block/ore/CoalOreBlock.php b/src/material/block/ore/CoalOreBlock.php index 1831be50..5dd90323 100644 --- a/src/material/block/ore/CoalOreBlock.php +++ b/src/material/block/ore/CoalOreBlock.php @@ -7,6 +7,7 @@ class CoalOreBlock extends SolidBlock{ $this->hardness = 15; $this->breakTime = 3.0; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/ore/DiamondOreBlock.php b/src/material/block/ore/DiamondOreBlock.php index 42d73d60..29929b78 100644 --- a/src/material/block/ore/DiamondOreBlock.php +++ b/src/material/block/ore/DiamondOreBlock.php @@ -7,6 +7,7 @@ class DiamondOreBlock extends SolidBlock{ $this->hardness = 15; $this->breakTime = 3; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/ore/GlowingRedstoneOreBlock.php b/src/material/block/ore/GlowingRedstoneOreBlock.php index 6a415480..20a92197 100644 --- a/src/material/block/ore/GlowingRedstoneOreBlock.php +++ b/src/material/block/ore/GlowingRedstoneOreBlock.php @@ -7,6 +7,8 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{ $this->hardness = 15; $this->breakTime = 3; $this->material = Material::$stone; + $this->lightBlock = 255; + $this->lightEmission = 9; } public static function onRandomTick(Level $level, $x, $y, $z){ diff --git a/src/material/block/ore/GoldOreBlock.php b/src/material/block/ore/GoldOreBlock.php index f494bc4b..5209b379 100644 --- a/src/material/block/ore/GoldOreBlock.php +++ b/src/material/block/ore/GoldOreBlock.php @@ -7,6 +7,7 @@ class GoldOreBlock extends SolidBlock{ $this->hardness = 15; $this->breakTime = 3.0; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/ore/IronOreBlock.php b/src/material/block/ore/IronOreBlock.php index 693ca0ca..020dec82 100644 --- a/src/material/block/ore/IronOreBlock.php +++ b/src/material/block/ore/IronOreBlock.php @@ -7,6 +7,7 @@ class IronOreBlock extends SolidBlock{ $this->hardness = 15; $this->breakTime = 3.0; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/ore/LapisOreBlock.php b/src/material/block/ore/LapisOreBlock.php index 10c61e8a..a60ef015 100644 --- a/src/material/block/ore/LapisOreBlock.php +++ b/src/material/block/ore/LapisOreBlock.php @@ -7,6 +7,7 @@ class LapisOreBlock extends SolidBlock{ $this->hardness = 15; $this->breakTime = 3.0; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/ore/RedstoneOreBlock.php b/src/material/block/ore/RedstoneOreBlock.php index 962651a5..3f0b260c 100644 --- a/src/material/block/ore/RedstoneOreBlock.php +++ b/src/material/block/ore/RedstoneOreBlock.php @@ -7,6 +7,7 @@ class RedstoneOreBlock extends SolidBlock{ $this->hardness = 15; $this->breakTime = 3; $this->material = Material::$stone; + $this->lightBlock = 255; } public static function interact(Level $level, $x, $y, $z, Player $player){ diff --git a/src/material/block/plant/BrownMushroomBlock.php b/src/material/block/plant/BrownMushroomBlock.php index eb2edf11..e252640c 100644 --- a/src/material/block/plant/BrownMushroomBlock.php +++ b/src/material/block/plant/BrownMushroomBlock.php @@ -7,6 +7,7 @@ class BrownMushroomBlock extends FlowableBlock{ $this->hardness = 0; $this->breakTime = 0; $this->material = Material::$plant; + $this->lightEmission = 1; } public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ diff --git a/src/material/block/solid/BedrockBlock.php b/src/material/block/solid/BedrockBlock.php index 4799553b..70d8035c 100644 --- a/src/material/block/solid/BedrockBlock.php +++ b/src/material/block/solid/BedrockBlock.php @@ -8,6 +8,7 @@ class BedrockBlock extends SolidBlock{ $this->hardness = 18000000; $this->breakTime = -1; $this->material = Material::$stone; + $this->lightBlock = 255; } public function isBreakable(Item $item, Player $player){ diff --git a/src/material/block/solid/BookshelfBlock.php b/src/material/block/solid/BookshelfBlock.php index 80955d9e..fdd93bfc 100644 --- a/src/material/block/solid/BookshelfBlock.php +++ b/src/material/block/solid/BookshelfBlock.php @@ -7,6 +7,7 @@ class BookshelfBlock extends SolidBlock{ $this->hardness = 7.5; $this->breakTime = 1.5; $this->material = Material::$wood; + $this->lightBlock = 255; } } \ No newline at end of file diff --git a/src/material/block/solid/BricksBlock.php b/src/material/block/solid/BricksBlock.php index cea18904..f0657c6d 100644 --- a/src/material/block/solid/BricksBlock.php +++ b/src/material/block/solid/BricksBlock.php @@ -7,6 +7,7 @@ class BricksBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 2; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/BurningFurnaceBlock.php b/src/material/block/solid/BurningFurnaceBlock.php index 50944933..030b7b63 100644 --- a/src/material/block/solid/BurningFurnaceBlock.php +++ b/src/material/block/solid/BurningFurnaceBlock.php @@ -8,6 +8,8 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{ $this->hardness = 17.5; $this->breakTime = 3.5; $this->material = Material::$stone; + $this->lightBlock = 255; + $this->lightEmission = 13; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/solid/ClayBlock.php b/src/material/block/solid/ClayBlock.php index e1c88681..a059962a 100644 --- a/src/material/block/solid/ClayBlock.php +++ b/src/material/block/solid/ClayBlock.php @@ -7,6 +7,7 @@ class ClayBlock extends SolidBlock{ $this->hardness = 3; $this->breakTime = 0.6; $this->material = Material::$clay; + $this->lightBlock = 255; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/CoalBlock.php b/src/material/block/solid/CoalBlock.php index 6c7a11e2..6a8191ef 100644 --- a/src/material/block/solid/CoalBlock.php +++ b/src/material/block/solid/CoalBlock.php @@ -7,6 +7,7 @@ class CoalBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 5; $this->material = Material::$metal; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/CobblestoneBlock.php b/src/material/block/solid/CobblestoneBlock.php index 96bc7172..7ba03d99 100644 --- a/src/material/block/solid/CobblestoneBlock.php +++ b/src/material/block/solid/CobblestoneBlock.php @@ -7,6 +7,7 @@ class CobblestoneBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 2; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/DiamondBlock.php b/src/material/block/solid/DiamondBlock.php index 9fc92a18..eaa0131d 100644 --- a/src/material/block/solid/DiamondBlock.php +++ b/src/material/block/solid/DiamondBlock.php @@ -7,6 +7,7 @@ class DiamondBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 5; $this->material = Material::$metal; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/DirtBlock.php b/src/material/block/solid/DirtBlock.php index fef766f0..87f2eb74 100644 --- a/src/material/block/solid/DirtBlock.php +++ b/src/material/block/solid/DirtBlock.php @@ -8,6 +8,7 @@ class DirtBlock extends SolidBlock{ $this->hardness = 2.5; $this->breakTime = 0.5; $this->material = Material::$dirt; + $this->lightBlock = 255; } public function onActivate(Item $item, Player $player){ diff --git a/src/material/block/solid/DoubleSlabBlock.php b/src/material/block/solid/DoubleSlabBlock.php index c455099d..0bac086d 100755 --- a/src/material/block/solid/DoubleSlabBlock.php +++ b/src/material/block/solid/DoubleSlabBlock.php @@ -18,6 +18,7 @@ class DoubleSlabBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 2; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/DoubleWoodSlabBlock.php b/src/material/block/solid/DoubleWoodSlabBlock.php index 62aa3c40..848c7b87 100644 --- a/src/material/block/solid/DoubleWoodSlabBlock.php +++ b/src/material/block/solid/DoubleWoodSlabBlock.php @@ -14,6 +14,7 @@ class DoubleWoodSlabBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 2; $this->material = Material::$wood; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/FurnaceBlock.php b/src/material/block/solid/FurnaceBlock.php index 3f8253e2..8fe0cdf9 100644 --- a/src/material/block/solid/FurnaceBlock.php +++ b/src/material/block/solid/FurnaceBlock.php @@ -13,5 +13,7 @@ class FurnaceBlock extends BurningFurnaceBlock{ $this->name = "Furnace"; $this->isActivable = true; $this->material = Material::$stone; + $this->lightBlock = 255; + $this->lightEmission = 0; } } \ No newline at end of file diff --git a/src/material/block/solid/GlowingObsidianBlock.php b/src/material/block/solid/GlowingObsidianBlock.php index cefcb5c5..b2e143db 100644 --- a/src/material/block/solid/GlowingObsidianBlock.php +++ b/src/material/block/solid/GlowingObsidianBlock.php @@ -7,6 +7,8 @@ class GlowingObsidianBlock extends SolidBlock implements LightingBlock{ $this->hardness = 6000; $this->breakTime = 10; $this->material = Material::$stone; + $this->lightBlock = 255; + $this->lightEmission = 13; } public function getMaxLightValue(){ diff --git a/src/material/block/solid/GlowstoneBlock.php b/src/material/block/solid/GlowstoneBlock.php index f746e6c4..e123d491 100644 --- a/src/material/block/solid/GlowstoneBlock.php +++ b/src/material/block/solid/GlowstoneBlock.php @@ -7,6 +7,8 @@ class GlowstoneBlock extends TransparentBlock implements LightingBlock{ $this->hardness = 1.5; $this->breakTime = 0.3; $this->material = Material::$glass; + $this->lightBlock = 255; + $this->lightEmission = 15; } public function getMaxLightValue(){ diff --git a/src/material/block/solid/GoldBlock.php b/src/material/block/solid/GoldBlock.php index 6c623e93..eff8f97d 100644 --- a/src/material/block/solid/GoldBlock.php +++ b/src/material/block/solid/GoldBlock.php @@ -7,6 +7,7 @@ class GoldBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 3; $this->material = Material::$metal; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/GrassBlock.php b/src/material/block/solid/GrassBlock.php index 10945978..f3b49baa 100644 --- a/src/material/block/solid/GrassBlock.php +++ b/src/material/block/solid/GrassBlock.php @@ -8,6 +8,7 @@ class GrassBlock extends SolidBlock{ $this->hardness = 3; $this->breakTime = 0.6; $this->material = Material::$dirt; + $this->lightBlock = 255; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/GravelBlock.php b/src/material/block/solid/GravelBlock.php index 4842e512..2ac020a3 100644 --- a/src/material/block/solid/GravelBlock.php +++ b/src/material/block/solid/GravelBlock.php @@ -7,6 +7,7 @@ class GravelBlock extends FallableBlock{ $this->hardness = 3; $this->breakTime = 0.6; $this->material = Material::$sand; + $this->lightBlock = 255; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/HayBaleBlock.php b/src/material/block/solid/HayBaleBlock.php index eb748749..86dacd51 100644 --- a/src/material/block/solid/HayBaleBlock.php +++ b/src/material/block/solid/HayBaleBlock.php @@ -7,6 +7,7 @@ class HayBaleBlock extends SolidBlock{ $this->hardness = 2.5; $this->breakTime = 0.5; $this->material = Material::$dirt; + $this->lightBlock = 255; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/solid/IceBlock.php b/src/material/block/solid/IceBlock.php index 81d6f82f..52079e10 100644 --- a/src/material/block/solid/IceBlock.php +++ b/src/material/block/solid/IceBlock.php @@ -8,6 +8,7 @@ class IceBlock extends TransparentBlock{ $this->breakTime = 0.5; $this->slipperiness = 0.98; $this->material = Material::$ice; + $this->lightBlock = 3; } public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ diff --git a/src/material/block/solid/InvisibleBedrockBlock.php b/src/material/block/solid/InvisibleBedrockBlock.php index 02724952..5ef1f20f 100755 --- a/src/material/block/solid/InvisibleBedrockBlock.php +++ b/src/material/block/solid/InvisibleBedrockBlock.php @@ -8,6 +8,7 @@ class InvisibleBedrockBlock extends SolidBlock{ $this->hardness = 18000000; $this->breakTime = -1; $this->material = Material::$stone; + $this->lightBlock = 255; } public function isBreakable(Item $item, Player $player){ diff --git a/src/material/block/solid/IronBlock.php b/src/material/block/solid/IronBlock.php index 2d14ffc4..1b576ba2 100644 --- a/src/material/block/solid/IronBlock.php +++ b/src/material/block/solid/IronBlock.php @@ -7,6 +7,7 @@ class IronBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 5; $this->material = Material::$metal; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/LapisBlock.php b/src/material/block/solid/LapisBlock.php index 21fe55cb..07346192 100644 --- a/src/material/block/solid/LapisBlock.php +++ b/src/material/block/solid/LapisBlock.php @@ -7,6 +7,7 @@ class LapisBlock extends SolidBlock{ $this->hardness = 15; $this->breakTime = 3.0; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/LeavesBlock.php b/src/material/block/solid/LeavesBlock.php index 1f6e2480..ee2e6a59 100644 --- a/src/material/block/solid/LeavesBlock.php +++ b/src/material/block/solid/LeavesBlock.php @@ -17,6 +17,7 @@ class LeavesBlock extends TransparentBlock{ $this->hardness = 1; $this->breakTime = 0.2; $this->material = Material::$leaves; + $this->lightBlock = 1; } public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ diff --git a/src/material/block/solid/LitPumpkinBlock.php b/src/material/block/solid/LitPumpkinBlock.php index 642caf8d..2303db16 100644 --- a/src/material/block/solid/LitPumpkinBlock.php +++ b/src/material/block/solid/LitPumpkinBlock.php @@ -15,6 +15,8 @@ class LitPumpkinBlock extends SolidBlock implements LightingBlock{ $this->hardness = 5; $this->breakTime = 1.0; $this->material = Material::$vegetable; + $this->lightBlock = 255; + $this->lightEmission = 15; } public function getMaxLightValue(){ diff --git a/src/material/block/solid/MelonBlock.php b/src/material/block/solid/MelonBlock.php index 690b43c2..71596b2a 100644 --- a/src/material/block/solid/MelonBlock.php +++ b/src/material/block/solid/MelonBlock.php @@ -7,6 +7,7 @@ class MelonBlock extends TransparentBlock{ $this->hardness = 5; $this->breakTime = 1; $this->material = Material::$vegetable; + $this->lightBlock = 255; } public function getDrops(Item $item, Player $player){ return array( diff --git a/src/material/block/solid/MossStoneBlock.php b/src/material/block/solid/MossStoneBlock.php index 181ee302..e1bb1436 100644 --- a/src/material/block/solid/MossStoneBlock.php +++ b/src/material/block/solid/MossStoneBlock.php @@ -7,6 +7,7 @@ class MossStoneBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 2; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/NetherBricksBlock.php b/src/material/block/solid/NetherBricksBlock.php index f58002d7..f2eec4a5 100644 --- a/src/material/block/solid/NetherBricksBlock.php +++ b/src/material/block/solid/NetherBricksBlock.php @@ -7,6 +7,7 @@ class NetherBricksBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 2; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/NetherrackBlock.php b/src/material/block/solid/NetherrackBlock.php index 203e7b4f..ff6b510a 100644 --- a/src/material/block/solid/NetherrackBlock.php +++ b/src/material/block/solid/NetherrackBlock.php @@ -7,6 +7,7 @@ class NetherrackBlock extends SolidBlock{ $this->hardness = 2; $this->breakTime = 0.4; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/ObsidianBlock.php b/src/material/block/solid/ObsidianBlock.php index 466201ab..6a7b369d 100644 --- a/src/material/block/solid/ObsidianBlock.php +++ b/src/material/block/solid/ObsidianBlock.php @@ -7,6 +7,7 @@ class ObsidianBlock extends SolidBlock{ $this->hardness = 6000; $this->breakTime = 10; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/PlanksBlock.php b/src/material/block/solid/PlanksBlock.php index c4cc531e..e321f4c7 100644 --- a/src/material/block/solid/PlanksBlock.php +++ b/src/material/block/solid/PlanksBlock.php @@ -14,6 +14,7 @@ class PlanksBlock extends SolidBlock{ $this->hardness = 15; $this->breakTime = 2; $this->material = Material::$wood; + $this->lightBlock = 255; } } \ No newline at end of file diff --git a/src/material/block/solid/PumpkinBlock.php b/src/material/block/solid/PumpkinBlock.php index 92002b14..56c66e72 100644 --- a/src/material/block/solid/PumpkinBlock.php +++ b/src/material/block/solid/PumpkinBlock.php @@ -7,6 +7,7 @@ class PumpkinBlock extends SolidBlock{ $this->hardness = 5; $this->breakTime = 1; $this->material = Material::$vegetable; + $this->lightBlock = 255; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/solid/QuartzBlock.php b/src/material/block/solid/QuartzBlock.php index 3640f18b..00fb68b3 100644 --- a/src/material/block/solid/QuartzBlock.php +++ b/src/material/block/solid/QuartzBlock.php @@ -14,6 +14,7 @@ class QuartzBlock extends SolidBlock{ $this->breakTime = 0.8; $this->hardness = 4; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/Reserved6Block.php b/src/material/block/solid/Reserved6Block.php index 3c86f0a0..133f763c 100644 --- a/src/material/block/solid/Reserved6Block.php +++ b/src/material/block/solid/Reserved6Block.php @@ -8,6 +8,7 @@ class Reserved6Block extends SolidBlock{ $this->hardness = 0; $this->breakTime = 0; $this->material = Material::$dirt; + $this->lightBlock = 255; } } \ No newline at end of file diff --git a/src/material/block/solid/SandBlock.php b/src/material/block/solid/SandBlock.php index 4c9ee6d1..16623ef1 100644 --- a/src/material/block/solid/SandBlock.php +++ b/src/material/block/solid/SandBlock.php @@ -7,6 +7,7 @@ class SandBlock extends FallableBlock{ $this->hardness = 2.5; $this->breakTime = 0.5; $this->material = Material::$sand; + $this->lightBlock = 255; } } \ No newline at end of file diff --git a/src/material/block/solid/SandstoneBlock.php b/src/material/block/solid/SandstoneBlock.php index 1a0d4bab..33a752b5 100644 --- a/src/material/block/solid/SandstoneBlock.php +++ b/src/material/block/solid/SandstoneBlock.php @@ -13,6 +13,7 @@ class SandstoneBlock extends SolidBlock{ $this->hardness = 4; $this->breakTime = 0.8; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/SnowBlock.php b/src/material/block/solid/SnowBlock.php index d41d2148..92addfae 100644 --- a/src/material/block/solid/SnowBlock.php +++ b/src/material/block/solid/SnowBlock.php @@ -7,6 +7,7 @@ class SnowBlock extends SolidBlock{ $this->hardness = 1; $this->breakTime = 0.2; $this->material = Material::$snow; + $this->lightBlock = 255; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/SpongeBlock.php b/src/material/block/solid/SpongeBlock.php index 58702087..ac5275e1 100644 --- a/src/material/block/solid/SpongeBlock.php +++ b/src/material/block/solid/SpongeBlock.php @@ -7,6 +7,7 @@ class SpongeBlock extends SolidBlock{ $this->hardness = 3; $this->breakTime = 0.6; $this->material = Material::$dirt; + $this->lightBlock = 255; } } diff --git a/src/material/block/solid/StoneBlock.php b/src/material/block/solid/StoneBlock.php index 55ee212c..e18b1acb 100644 --- a/src/material/block/solid/StoneBlock.php +++ b/src/material/block/solid/StoneBlock.php @@ -7,6 +7,7 @@ class StoneBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 1.5; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/StoneBricksBlock.php b/src/material/block/solid/StoneBricksBlock.php index 1b856076..cc83158f 100644 --- a/src/material/block/solid/StoneBricksBlock.php +++ b/src/material/block/solid/StoneBricksBlock.php @@ -14,6 +14,7 @@ class StoneBricksBlock extends SolidBlock{ $this->hardness = 30; $this->breakTime = 1.5; $this->material = Material::$stone; + $this->lightBlock = 255; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/solid/StonecutterBlock.php b/src/material/block/solid/StonecutterBlock.php index fc307d70..63a4d296 100644 --- a/src/material/block/solid/StonecutterBlock.php +++ b/src/material/block/solid/StonecutterBlock.php @@ -8,6 +8,7 @@ class StonecutterBlock extends SolidBlock{ $this->breakTime = 2.5; $this->hardness = 2.5*5; $this->material = Material::$stone; + $this->lightBlock = 255; } public function onActivate(Item $item, Player $player){ diff --git a/src/material/block/solid/WoodBlock.php b/src/material/block/solid/WoodBlock.php index 04a26316..c9d2fafa 100644 --- a/src/material/block/solid/WoodBlock.php +++ b/src/material/block/solid/WoodBlock.php @@ -19,6 +19,7 @@ class WoodBlock extends SolidBlock{ $this->hardness = 10; $this->breakTime = 2.0; $this->material = Material::$wood; + $this->lightBlock = 255; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/solid/WoolBlock.php b/src/material/block/solid/WoolBlock.php index 52b91735..c0e6e7f2 100644 --- a/src/material/block/solid/WoolBlock.php +++ b/src/material/block/solid/WoolBlock.php @@ -29,6 +29,7 @@ class WoolBlock extends SolidBlock{ $this->hardness = 4; $this->breakTime = 0.8; $this->material = Material::$cloth; + $this->lightBlock = 255; } } \ No newline at end of file diff --git a/src/material/block/solid/WorkbenchBlock.php b/src/material/block/solid/WorkbenchBlock.php index 5f80c000..3148a223 100644 --- a/src/material/block/solid/WorkbenchBlock.php +++ b/src/material/block/solid/WorkbenchBlock.php @@ -8,6 +8,7 @@ class WorkbenchBlock extends SolidBlock{ $this->hardness = 12.5; $this->breakTime = 2.5; $this->material = Material::$wood; + $this->lightBlock = 255; } public function onActivate(Item $item, Player $player){ diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index f00388e6..0902c409 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -3,7 +3,6 @@ define("PMF_CURRENT_LEVEL_VERSION", 0x00); class PMFLevel extends PMF{ - public $isLoaded = true; private $levelData = []; public $locationTable = []; @@ -298,6 +297,7 @@ class PMFLevel extends PMF{ for($Y = 0; $Y < $this->levelData["height"]; ++$Y){ $t = 1 << $Y; if(($info[0] & $t) === $t){ + //TODO do something with skylight // 4096 + 2048 + 2048, Block Data, Meta, Light if(strlen($this->chunks[$index][$Y] = gzread($chunk, 8192)) < 8192){ console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents", true, true, 2); @@ -397,6 +397,7 @@ class PMFLevel extends PMF{ }else{ $this->chunks[$index][$Y][$bind] = chr($block); if($block > 0) StaticBlock::getBlock($block)::onPlace($this->level, $x, $y, $z); + $this->level->updateLight(0, $x, $y, $z, $x, $y, $z); } if(!isset($this->chunkChange[$index][$Y])){ @@ -408,6 +409,56 @@ class PMFLevel extends PMF{ return true; } + public function getBlockLight($x, $y, $z){ + if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127) return 0; + $X = $x >> 4; + $Z = $z >> 4; + $Y = $y >> 4; + $index = self::getIndex($X, $Z); + if(!isset($this->chunks[$index]) || $this->chunks[$index] === false || ($this->chunks[$index][$Y] === false)) return 0; + $aX = $x & 0xf; + $aZ = $z & 0xf; + $aY = $y & 0xf; + $m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 24 + ($aX << 5) + ($aZ << 9))]); + return $y & 1 ? $m >> 4 : $m & 0x0F; + } + + public function setBlockLight($x, $y, $z, $value){ + if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127) return false; + $X = $x >> 4; + $Z = $z >> 4; + $Y = $y >> 4; + $value &= 0x0F; + + $index = self::getIndex($X, $Z); + if(!isset($this->chunks[$index]) || $this->chunks[$index] === false){ + if($this->loadChunk($X, $Z) === false) return false; + }elseif($this->chunks[$index][$Y] === false){ + $this->fillMiniChunk($X, $Z, $Y); + } + + $aX = $x & 0xf; + $aZ = $z & 0xf; + $aY = $y & 0xf; + $mindex = (int) (($aY >> 1) + 24 + ($aX << 5) + ($aZ << 9)); + $old_m = ord($this->chunks[$index][$Y][$mindex]); + if(($y & 1) === 0) $m = ($old_m & 0xF0) | $value; + else $m = ($value << 4) | ($old_m & 0x0F); + + if($old_m != $m){ + $this->chunks[$index][$Y][$mindex] = chr($m); + + if(!isset($this->chunkChange[$index][$Y])){ + $this->chunkChange[$index][$Y] = 1; + }else{ + ++$this->chunkChange[$index][$Y]; + } + $this->chunkChange[$index][-1] = true; + return true; + } + return false; + } + public function getBlockDamage($x, $y, $z){ if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127){ return 0; @@ -531,6 +582,7 @@ class PMFLevel extends PMF{ $this->chunkChange[$index][-1] = true; if($block > 0) StaticBlock::getBlock($block)::onPlace($this->level, $x, $y, $z); + $this->level->updateLight(0, $x, $y, $z, $x, $y, $z); return true; } return false; diff --git a/src/world/Level.php b/src/world/Level.php index fcd621a1..990d6782 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -520,7 +520,140 @@ class Level{ } $this->addBlockToSendQueue($x, $y, $z, $id, $meta); } + /** + * Contains light updates. Light update is an integer that contains min/max block coords and light layer + * Format: 0011ffeeddccbbaa + * 00 - unused(8th byte) + * 11 - light layer(currently must be 0(block), future: 15(sky)) + * ff, ee, dd - minX, minY, minZ + * cc, bb, aa - maxX, maxY, maxZ + * @var int[] + */ + public $lightUpdates = []; + public $lightUpdateIndx = -1; + public function handleBlockLightUpdate($minX, $minY, $minZ, $maxX, $maxY, $maxZ){ + for($x = $minX; $x <= $maxX; ++$x){ + for($z = $minZ; $z <= $maxZ; ++$z){ + for($y = $minY; $y <= $maxY; ++$y){ + $brightness = $this->level->getBlockLight($x, $y, $z); + $blockID = $this->level->getBlockID($x, $y, $z); + $lightBlock = StaticBlock::$lightBlock[$blockID]; + if($lightBlock == 0) $lightBlock = 1; + $lightEmission = StaticBlock::$lightEmission[$blockID]; + $newBrightness = 0; + if($lightBlock <= 14 || $lightEmission != 0){ + $xNegBright = $this->level->getBlockLight($x-1, $y, $z); + $xPosBright = $this->level->getBlockLight($x+1, $y, $z); + $yNegBright = $this->level->getBlockLight($x, $y-1, $z); + $yPosBright = $this->level->getBlockLight($x, $y+1, $z); + $zNegBright = $this->level->getBlockLight($x, $y, $z-1); + $zPosBright = $this->level->getBlockLight($x, $y, $z+1); + + $v15 = $xNegBright; + if($xPosBright > $v15) $v15 = $xPosBright; + if($yNegBright > $v15) $v15 = $yNegBright; + if($yPosBright > $v15) $v15 = $yPosBright; + if($zNegBright > $v15) $v15 = $zNegBright; + if($zPosBright > $v15) $v15 = $zPosBright; + + $newBrightness = $v15 - $lightBlock; + if($newBrightness < 0) $newBrightness = 0; + if($lightEmission > $newBrightness) $newBrightness = $lightEmission; + } + + if($brightness != $newBrightness){ + $this->level->setBlockLight($x, $y, $z, $newBrightness); + $v4 = $newBrightness - 1; + if($v4 < 0) $v4 = 0; + $this->updateLightIfOtherThan(0, $x-1, $y, $z, $v4); + $this->updateLightIfOtherThan(0, $x, $y-1, $z, $v4); + $this->updateLightIfOtherThan(0, $x, $y, $z-1, $v4); + if($x+1 >= $maxX) $this->updateLightIfOtherThan(0, $x+1, $y, $z, $v4); + if($y+1 >= $maxY) $this->updateLightIfOtherThan(0, $x, $y+1, $z, $v4); + if($z+1 >= $maxZ) $this->updateLightIfOtherThan(0, $x, $y, $z+1, $v4); + } + } + } + } + } + public function updateLight($layer, $minX, $minY, $minZ, $maxX, $maxY, $maxZ){ + /*$max = 5; TODO: expand lightupdate + $sz = $this->lightUpdateIndx; + if($sz < $max) $max = $sz; + for($i = 0; $i < $max; ++$i){ + $update = $this->lightUpdates[$i]; + if($update->layer == $layer && ($r = $update->expand($minX, $minY, $minZ, $maxX, $maxY, $maxZ))){ + --$this->lightUpdatesCount; + } + }*/ + + if($maxX < $minX){ + $s = $minX; + $minX = $maxX; + $maxX = $s; + } + if($maxY < $minY){ + $s = $minY; + $minY = $maxY; + $maxY = $s; + } + if($maxZ < $minZ){ + $s = $minZ; + $minZ = $maxZ; + $maxZ = $s; + } + if($minX < 0) $minX = 0; + if($minX > 255) $minX = 255; + if($minY < 0) $minY = 0; + if($minY > 127) $minY = 127; + if($minZ < 0) $minZ = 0; + if($minZ > 255) $minZ = 255; + + if($maxX < 0) $minX = 0; + if($maxX > 255) $minX = 255; + if($maxY < 0) $minY = 0; + if($maxY > 127) $minY = 127; + if($maxZ < 0) $maxZ = 0; + if($maxZ > 255) $maxZ = 255; + + $update = ($layer << 48) | ($minX << 40) | ($minY << 32) | ($minZ << 24) | ($maxX << 16) | ($maxY << 8) | ($maxZ); + $this->lightUpdates[++$this->lightUpdateIndx] = $update; + } + + public function updateLightIfOtherThan($layer, $x, $y, $z, $level){ + if($y < 0 || $y > 127 || $x < 0 || $x > 255 || $z < 0 || $z > 255) return; + if($layer == 0){ + $blockID = $this->level->getBlockID($x, $y, $z); + $emission = StaticBlock::$lightEmission[$blockID]; + if($emission > $level) $level = $emission; + + if($this->level->getBlockLight($x, $y, $z) != $level){ + $this->updateLight($layer, $x, $y, $z, $x, $y, $z); + } + } + } + public function updateLights(){ + if($this->lightUpdateIndx < 0) return false; + $limit = 500; + do{ + $upd = $this->lightUpdates[$this->lightUpdateIndx]; + unset($this->lightUpdates[$this->lightUpdateIndx]); + --$this->lightUpdateIndx; + $maxZ = $upd & 0xff; + $maxY = ($upd >> 8) & 0xff; + $maxX = ($upd >> 16) & 0xff; + $minZ = ($upd >> 24) & 0xff; + $minY = ($upd >> 32) & 0xff; + $minX = ($upd >> 40) & 0xff; + $layer = $upd >> 48; + if($layer == 0) $this->handleBlockLightUpdate($minX, $minY, $minZ, $maxX, $maxY, $maxZ); + else console("wha"); + if(!--$limit) return true; + }while($this->lightUpdateIndx >= 0); + if(count($this->lightUpdates) > 0) return true; + return false; + } public function onTick(PocketMinecraftServer $server, $currentTime){ if(!$this->stopTime) ++$this->time; for($cX = 0; $cX < 16; ++$cX){ @@ -647,6 +780,7 @@ class Level{ } $this->queuedBlockUpdates = []; + $this->updateLights(); } public function isBoundingBoxOnFire(AxisAlignedBB $bb){