mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
commit
de44bd6a0d
72 changed files with 450 additions and 10 deletions
|
|
@ -210,7 +210,11 @@ class ConsoleAPI{
|
|||
case "status":
|
||||
$info = $this->server->debugInfo();
|
||||
if(!($issuer instanceof Player) && $issuer === "console"){
|
||||
return "TPS: {$info["tps"]}, Memory usage: {$info["memory_usage"]} (Peak {$info["memory_peak_usage"]}), Entities: {$info["entities"]}, Events: {$info["events"]}, Handlers: {$info["handlers"]}, Actions: {$info["actions"]}, Garbage: {$info["garbage"]}";
|
||||
$lightUpdates = 0;
|
||||
foreach($this->server->api->level->levels as $level){
|
||||
$lightUpdates += count($level->lightUpdates);
|
||||
}
|
||||
return "TPS: {$info["tps"]}, Memory usage: {$info["memory_usage"]} (Peak {$info["memory_peak_usage"]}), Entities: {$info["entities"]}, Events: {$info["events"]}, Handlers: {$info["handlers"]}, Actions: {$info["actions"]}, Garbage: {$info["garbage"]}, Light updates: {$lightUpdates}";
|
||||
}
|
||||
return "TPS: {$info["tps"]}, Memory usage: {$info["memory_usage"]} (Peak {$info["memory_peak_usage"]})";
|
||||
case "stop":
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -284,8 +284,8 @@ class PlayerAPI{
|
|||
|
||||
$xChunk = $x >> 4;
|
||||
$zChunk = $z >> 4;
|
||||
|
||||
return "$username's coordinates: X: $x ($xChunk), Y: $y, Z: $z ($zChunk), world: $level.\nDirection: $direction";
|
||||
$brightness = $ent->level->getRawBrightness((int)$x, (int)$y, (int)$z);
|
||||
return "$username's coordinates: X: $x ($xChunk), Y: $y, Z: $z ($zChunk), world: $level.\nDirection: $direction Brightness: $brightness";
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class PocketMinecraftServer{
|
|||
|
||||
public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread;
|
||||
public static $FORCE_20_TPS = false, $KEEP_CHUNKS_LOADED = true, $PACKET_READING_LIMIT = 100;
|
||||
|
||||
public static $ENABLE_LIGHT_UPDATES = true;
|
||||
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
|
||||
$this->port = (int) $port;
|
||||
$this->doTick = true;
|
||||
|
|
@ -97,7 +97,8 @@ class PocketMinecraftServer{
|
|||
"keep-items-on-death" => Entity::$keepInventory,
|
||||
"disable-emojis-in-chat" => Player::$disableEmojisInChat,
|
||||
"disable-emojis-on-signs" => Level::$disableEmojisOnSigns,
|
||||
"allow-dropping-single-items" => Player::$allowDroppingSingleItems
|
||||
"allow-dropping-single-items" => Player::$allowDroppingSingleItems,
|
||||
"enable-light-updates" => self::$ENABLE_LIGHT_UPDATES,
|
||||
]);
|
||||
Player::$disableEmojisInChat = $this->extraprops->get("disable-emojis-in-chat");
|
||||
Level::$disableEmojisOnSigns = $this->extraprops->get("disable-emojis-on-signs");
|
||||
|
|
@ -109,6 +110,7 @@ class PocketMinecraftServer{
|
|||
Living::$entityPushing = $this->extraprops->get("enable-mob-pushing");
|
||||
self::$FORCE_20_TPS = $this->extraprops->get("force-20-tps");
|
||||
self::$KEEP_CHUNKS_LOADED = $this->extraprops->get("keep-chunks-loaded");
|
||||
self::$ENABLE_LIGHT_UPDATES = $this->extraprops->get("enable-light-updates");
|
||||
PocketMinecraftServer::$SAVE_PLAYER_DATA = $this->extraprops->get("save-player-data");
|
||||
MobController::$ADVANCED = $this->extraprops->get("experimental-mob-ai");
|
||||
Explosion::$enableExplosions = $this->extraprops->get("enable-explosions");
|
||||
|
|
@ -116,6 +118,9 @@ class PocketMinecraftServer{
|
|||
if(self::$FORCE_20_TPS){
|
||||
ConsoleAPI::warn("Forcing 20 tps. This may result in higher CPU usage!");
|
||||
}
|
||||
if(!self::$ENABLE_LIGHT_UPDATES){
|
||||
ConsoleAPI::warn("Light updates are disabled: this should decrease memory consumption and increase performance, but will prevent all existing light from updating and disable some light-dependant features.");
|
||||
}
|
||||
if($this->extraprops->get("discord-msg")){
|
||||
if($this->extraprops->get("discord-webhook-url") !== "none"){
|
||||
console("[INFO] Discord Logger is enabled.");
|
||||
|
|
|
|||
|
|
@ -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){}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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(){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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(){
|
||||
|
|
|
|||
|
|
@ -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(){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class BookshelfBlock extends SolidBlock{
|
|||
$this->hardness = 7.5;
|
||||
$this->breakTime = 1.5;
|
||||
$this->material = Material::$wood;
|
||||
$this->lightBlock = 255;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -13,5 +13,7 @@ class FurnaceBlock extends BurningFurnaceBlock{
|
|||
$this->name = "Furnace";
|
||||
$this->isActivable = true;
|
||||
$this->material = Material::$stone;
|
||||
$this->lightBlock = 255;
|
||||
$this->lightEmission = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -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(){
|
||||
|
|
|
|||
|
|
@ -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(){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class InfoUpdate2Block extends SolidBlock{
|
|||
$this->hardness = 5;
|
||||
$this->breakTime = 1;
|
||||
$this->material = Material::$dirt;
|
||||
$this->lightBlock = 255;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ class InfoUpdateBlock extends SolidBlock{
|
|||
$this->hardness = 5;
|
||||
$this->breakTime = 1;
|
||||
$this->material = Material::$dirt;
|
||||
$this->lightBlock = 255;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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(){
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class PlanksBlock extends SolidBlock{
|
|||
$this->hardness = 15;
|
||||
$this->breakTime = 2;
|
||||
$this->material = Material::$wood;
|
||||
$this->lightBlock = 255;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class Reserved6Block extends SolidBlock{
|
|||
$this->hardness = 0;
|
||||
$this->breakTime = 0;
|
||||
$this->material = Material::$dirt;
|
||||
$this->lightBlock = 255;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ class SandBlock extends FallableBlock{
|
|||
$this->hardness = 2.5;
|
||||
$this->breakTime = 0.5;
|
||||
$this->material = Material::$sand;
|
||||
$this->lightBlock = 255;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class SpongeBlock extends SolidBlock{
|
|||
$this->hardness = 3;
|
||||
$this->breakTime = 0.6;
|
||||
$this->material = Material::$dirt;
|
||||
$this->lightBlock = 255;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class WoolBlock extends SolidBlock{
|
|||
$this->hardness = 4;
|
||||
$this->breakTime = 0.8;
|
||||
$this->material = Material::$cloth;
|
||||
$this->lightBlock = 255;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -3,14 +3,18 @@
|
|||
define("PMF_CURRENT_LEVEL_VERSION", 0x00);
|
||||
|
||||
class PMFLevel extends PMF{
|
||||
|
||||
const NC_DATA_VERSION = 1;
|
||||
public $isLoaded = true;
|
||||
private $levelData = [];
|
||||
public $hasLight = "";
|
||||
public $locationTable = [];
|
||||
private $log = 4; //must be 4 or else rip world
|
||||
private $payloadOffset = 0;
|
||||
public $chunks = [];
|
||||
public $chunkChange = [];
|
||||
/**
|
||||
* @var Level
|
||||
*/
|
||||
public $level;
|
||||
public function __construct($file, $blank = false){
|
||||
if(is_array($blank)){
|
||||
|
|
@ -82,8 +86,83 @@ class PMFLevel extends PMF{
|
|||
if($locationTable !== false){
|
||||
$this->writeLocationTable();
|
||||
}
|
||||
|
||||
$this->writeNCData();
|
||||
}
|
||||
|
||||
public function writeNCData(){
|
||||
$dir = dirname($this->file);
|
||||
try{
|
||||
$file = fopen("$dir/ncleveldata.pmf", "wb");
|
||||
fwrite($file, chr(self::NC_DATA_VERSION), 1);
|
||||
fwrite($file, $this->hasLight, 16*16);
|
||||
}finally{
|
||||
fclose($file);
|
||||
}
|
||||
}
|
||||
|
||||
public function readNCData(){
|
||||
$this->hasLight = str_repeat("\x00", 16*16);
|
||||
|
||||
$dir = dirname($this->file);
|
||||
$path = "$dir/ncleveldata.pmf";
|
||||
if(!is_file($path)){
|
||||
ConsoleAPI::notice("No NC Level data found! Old world?");
|
||||
return;
|
||||
}
|
||||
try{
|
||||
$file = fopen($path, "rb");
|
||||
$ncdv = ord(fread($file, 1));
|
||||
$v = self::NC_DATA_VERSION;
|
||||
if($ncdv !== $v){
|
||||
ConsoleAPI::notice("NC level data version on server($v) does not match the world($ncdv)! Creating NC level data backup.");
|
||||
$newpath = "$path.bak.".microtime(true);
|
||||
$f = copy($path, $newpath);
|
||||
if($f === false) ConsoleAPI::error("NC level data backup creation failed.");
|
||||
else ConsoleAPI::notice("NC level data backup created. (path: $newpath)");
|
||||
}
|
||||
$this->hasLight = fread($file, 16*16);
|
||||
}finally{
|
||||
fclose($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks was skylight generated for chunk
|
||||
* @param int $X - chunk x
|
||||
* @param int $Z - chunk z
|
||||
*/
|
||||
public function hasSkylight($X, $Z){
|
||||
if($X < 0 || $X > 15 || $Z < 0 || $Z > 15) return false;
|
||||
$index = self::getIndex($X, $Z);
|
||||
return (ord($this->hasLight[$index]) & 2) > 0;
|
||||
}
|
||||
/**
|
||||
* Checks was blocklight generated for chunk
|
||||
* @param int $X - chunk x
|
||||
* @param int $Z - chunk z
|
||||
*/
|
||||
public function hasBlocklight($X, $Z){
|
||||
if($X < 0 || $X > 15 || $Z < 0 || $Z > 15) return false;
|
||||
$index = self::getIndex($X, $Z);
|
||||
return (ord($this->hasLight[$index]) & 1) > 0;
|
||||
}
|
||||
|
||||
public function markHasBlocklight($X, $Z){
|
||||
if($X < 0 || $X > 15 || $Z < 0 || $Z > 15) return false;
|
||||
$index = self::getIndex($X, $Z);
|
||||
$o = ord($this->hasLight[$index]);
|
||||
$this->hasLight[$index] = chr($o | 1);
|
||||
return true;
|
||||
}
|
||||
public function markHasSkylight($X, $Z){
|
||||
if($X < 0 || $X > 15 || $Z < 0 || $Z > 15) return false;
|
||||
$index = self::getIndex($X, $Z);
|
||||
$o = ord($this->hasLight[$index]);
|
||||
$this->hasLight[$index] = chr($o | 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
private function writeLocationTable(){
|
||||
$cnt = pow($this->levelData["width"], 2);
|
||||
@ftruncate($this->fp, $this->payloadOffset);
|
||||
|
|
@ -160,6 +239,7 @@ class PMFLevel extends PMF{
|
|||
}else{
|
||||
$this->payloadOffset = ftell($this->fp);
|
||||
}
|
||||
$this->readNCData();
|
||||
return $this->readLocationTable();
|
||||
}
|
||||
|
||||
|
|
@ -275,13 +355,12 @@ class PMFLevel extends PMF{
|
|||
return $this->chunks[$index][$Y];
|
||||
}
|
||||
|
||||
public $checkLight = [];
|
||||
public function loadChunk($X, $Z){
|
||||
|
||||
$index = self::getIndex($X, $Z);
|
||||
|
||||
if($this->isChunkLoaded($X, $Z)){
|
||||
return true;
|
||||
|
||||
}elseif(!isset($this->locationTable[$index])){
|
||||
return false;
|
||||
}
|
||||
|
|
@ -298,6 +377,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);
|
||||
|
|
@ -307,9 +387,31 @@ class PMFLevel extends PMF{
|
|||
$this->chunks[$index][$Y] = false;
|
||||
}
|
||||
}
|
||||
$this->checkLight[$index] = [$X, $Z];
|
||||
|
||||
@gzclose($chunk);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function forceLightUpdatesIfNeeded(){
|
||||
if(!PocketMinecraftServer::$ENABLE_LIGHT_UPDATES) {
|
||||
$this->checkLight = [];
|
||||
return;
|
||||
}
|
||||
foreach($this->checkLight as $index => [$X, $Z]){
|
||||
$update = false;
|
||||
if(!$this->hasBlocklight($X, $Z)){
|
||||
ConsoleAPI::notice("Chunk $X $Z (Level: {$this->level->getName()} has no blocklight! Forcing light update(it might take a while).");
|
||||
$this->level->updateLight(0, $X*16, 0, $Z*16, $X*16+15, 127, $Z*16+15);
|
||||
$update = true;
|
||||
$this->markHasBlocklight($X, $Z);
|
||||
}
|
||||
|
||||
if($update) while($this->level->updateLights());
|
||||
unset($this->checkLight[$index]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function fillMiniChunk($X, $Z, $Y){
|
||||
if($this->isChunkLoaded($X, $Z) === false){
|
||||
|
|
@ -397,6 +499,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 +511,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 || !PocketMinecraftServer::$ENABLE_LIGHT_UPDATES) 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 || !PocketMinecraftServer::$ENABLE_LIGHT_UPDATES) 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 +684,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;
|
||||
|
|
|
|||
|
|
@ -520,8 +520,200 @@ 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){
|
||||
if(!PocketMinecraftServer::$ENABLE_LIGHT_UPDATES) return;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets block brightness based on skylight, blocklight and subtracts skyDarken.
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
* @param int $z
|
||||
*/
|
||||
public function getRawBrightness(int $x, int $y, int $z){
|
||||
//TODO special way to do it for some blocks
|
||||
|
||||
$bl = $this->level->getBlockLight($x, $y, $z);
|
||||
$l = 0; ///*$this->level->getBrightness(LIGHTLAYER_SKY, $x, $y, $z)*/ (15 - $this->skyDarken); no skylight is implemnted
|
||||
if($bl > $l) $l = $bl;
|
||||
if($l < 0) $l = 0;
|
||||
return $l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules light update. Make sure to check that coordinates are in range.
|
||||
* @param int $layer - light layer(0 - block, 15 - sky(not implemented as of now)).
|
||||
* @param int $minX - must be in range (0, 255). Must be less than maxX.
|
||||
* @param int $minY - must be in range (0, 127). Must be less than maxY.
|
||||
* @param int $minZ - must be in range (0, 255). Must be less than maxZ.
|
||||
* @param int $maxX - must be in range (0, 255). Must be more than minX.
|
||||
* @param int $maxY - must be in range (0, 127). Must be more than minY.
|
||||
* @param int $maxZ - must be in range (0, 255). Must be more than minZ.
|
||||
*/
|
||||
public function updateLight($layer, $minX, $minY, $minZ, $maxX, $maxY, $maxZ){
|
||||
if(!PocketMinecraftServer::$ENABLE_LIGHT_UPDATES) return;
|
||||
/*$max = 5; //no idea is it needed for block light
|
||||
$sz = $this->lightUpdateIndx;
|
||||
if($sz < $max) $max = $sz;
|
||||
for($i = 0; $i < $max; ++$i){
|
||||
$upd = $this->lightUpdates[$i];
|
||||
$llayer = $upd >> 48;
|
||||
|
||||
if($layer == $llayer){
|
||||
$maZ = $upd & 0xff;
|
||||
$maY = ($upd >> 8) & 0xff;
|
||||
$maX = ($upd >> 16) & 0xff;
|
||||
$miZ = ($upd >> 24) & 0xff;
|
||||
$miY = ($upd >> 32) & 0xff;
|
||||
$miX = ($upd >> 40) & 0xff;
|
||||
if($miX <= $minX && $miY <= $minY && $miZ <= $minZ && $maX >= $maxX && $maY >= $maxY && $maZ >= $maxZ){
|
||||
//console("light happen is scheduled to happen already");
|
||||
return;
|
||||
}
|
||||
if($miX-1 > $minX || $miY-1 > $minY || $miZ-1 > $minZ || $maX+1 < $maxX || $maY+1 < $maxY || $maZ+1 < $maxZ){
|
||||
continue;
|
||||
}
|
||||
if($miX < $minX) $minX = $miX;
|
||||
if($miY < $minY) $minY = $miY;
|
||||
if($miZ < $minZ) $minZ = $miZ;
|
||||
if($maX > $maxX) $maxX = $maX;
|
||||
if($maY > $maxY) $maxY = $maY;
|
||||
if($maZ > $maxZ) $maxZ = $maZ;
|
||||
|
||||
if((($maxZ-$minZ)*($maX-$minY)*($maxX-$minX) - ($maX-$miX)*($maZ-$miZ)*($maY-$miY)) > 2){
|
||||
continue;
|
||||
}
|
||||
|
||||
$indx = $i;
|
||||
goto update_light_in_array;
|
||||
}
|
||||
}*/
|
||||
$indx = ++$this->lightUpdateIndx;
|
||||
/*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;
|
||||
}
|
||||
|
||||
update_light_in_array:
|
||||
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[$indx] = $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){
|
||||
$this->level->forceLightUpdatesIfNeeded();
|
||||
|
||||
if(!$this->stopTime) ++$this->time;
|
||||
for($cX = 0; $cX < 16; ++$cX){
|
||||
for($cZ = 0; $cZ < 16; ++$cZ){
|
||||
|
|
@ -647,6 +839,7 @@ class Level{
|
|||
}
|
||||
|
||||
$this->queuedBlockUpdates = [];
|
||||
$this->updateLights();
|
||||
}
|
||||
|
||||
public function isBoundingBoxOnFire(AxisAlignedBB $bb){
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class MobSpawner{
|
|||
$zMob = $z + mt_rand(-3, 3);
|
||||
|
||||
|
||||
$y = $this->getSafeY($xMob, $zMob, $grassOnly, $type >= 32 && $type <= 36 && $type != 35);
|
||||
$y = $this->getSafeY($xMob, $zMob, $grassOnly, $type >= 32 && $type <= 36 && $type != 35, $type >= 32 && $type <= 36);
|
||||
if(!$y || $y < 0){
|
||||
continue;
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ class MobSpawner{
|
|||
];
|
||||
}
|
||||
|
||||
protected function getSafeY($x, $z, $grassOnly = false, $highMob = false){ //first safe block //TODO check boundingbox
|
||||
protected function getSafeY($x, $z, $grassOnly = false, $highMob = false, $isMonster = false){ //first safe block //TODO check boundingbox
|
||||
$allowed = [];
|
||||
for($y = 0; $y < 128; ++$y){
|
||||
$b = $this->level->level->getBlockID($x, $y, $z);
|
||||
|
|
@ -136,6 +136,9 @@ class MobSpawner{
|
|||
(StaticBlock::getIsSolid($b1) && (!$grassOnly || $b1 === GRASS) &&
|
||||
(!$highMob || !StaticBlock::getIsSolid($b2) && !StaticBlock::getIsLiquid($b2)))
|
||||
){
|
||||
if($isMonster && ($rb = $this->level->getRawBrightness($x, $y, $z)) > 8){ //dont spawn if too bright
|
||||
continue;
|
||||
}
|
||||
$allowed[] = $y;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue