block light

This commit is contained in:
GameHerobrine 2025-06-23 01:24:00 +03:00
parent fd5b103df7
commit d1a724c143
66 changed files with 266 additions and 1 deletions

View file

@ -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);

View file

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

View file

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

View file

@ -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);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,6 +7,7 @@ class BookshelfBlock extends SolidBlock{
$this->hardness = 7.5;
$this->breakTime = 1.5;
$this->material = Material::$wood;
$this->lightBlock = 255;
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -13,5 +13,7 @@ class FurnaceBlock extends BurningFurnaceBlock{
$this->name = "Furnace";
$this->isActivable = true;
$this->material = Material::$stone;
$this->lightBlock = 255;
$this->lightEmission = 0;
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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(

View file

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

View file

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

View file

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

View file

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

View file

@ -14,6 +14,7 @@ class PlanksBlock extends SolidBlock{
$this->hardness = 15;
$this->breakTime = 2;
$this->material = Material::$wood;
$this->lightBlock = 255;
}
}

View file

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

View file

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

View file

@ -8,6 +8,7 @@ class Reserved6Block extends SolidBlock{
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$dirt;
$this->lightBlock = 255;
}
}

View file

@ -7,6 +7,7 @@ class SandBlock extends FallableBlock{
$this->hardness = 2.5;
$this->breakTime = 0.5;
$this->material = Material::$sand;
$this->lightBlock = 255;
}
}

View file

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

View file

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

View file

@ -7,6 +7,7 @@ class SpongeBlock extends SolidBlock{
$this->hardness = 3;
$this->breakTime = 0.6;
$this->material = Material::$dirt;
$this->lightBlock = 255;
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -29,6 +29,7 @@ class WoolBlock extends SolidBlock{
$this->hardness = 4;
$this->breakTime = 0.8;
$this->material = Material::$cloth;
$this->lightBlock = 255;
}
}

View file

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

View file

@ -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;

View file

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