From c2faff0f22962e4f5008a87df6b1bb0765883084 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 24 Jun 2025 16:58:28 +0300 Subject: [PATCH] added ability to disable light updates --- src/PocketMinecraftServer.php | 9 +++++++-- src/pmf/PMFLevel.php | 8 ++++++-- src/world/Level.php | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index b779896a..2a0afd75 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -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."); diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index af6e0be3..2e56276c 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -394,6 +394,10 @@ class PMFLevel extends PMF{ } 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)){ @@ -508,7 +512,7 @@ class PMFLevel extends PMF{ } public function getBlockLight($x, $y, $z){ - if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127) return 0; + 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; @@ -522,7 +526,7 @@ class PMFLevel extends PMF{ } public function setBlockLight($x, $y, $z, $value){ - if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127) return false; + 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; diff --git a/src/world/Level.php b/src/world/Level.php index 868290c6..ed779bb2 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -532,6 +532,7 @@ class Level{ 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){ @@ -604,6 +605,7 @@ class Level{ * @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;