From 835360745159dd3913af4659e7cf52458ef5077d Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 30 May 2024 03:26:49 +0300 Subject: [PATCH] readded ability to keep chunks unloaded, fixed entities falling on farmland --- src/API/LevelAPI.php | 10 +++++++--- src/PocketMinecraftServer.php | 6 ++++-- src/astarnavigator/TileNavigator.php | 2 +- src/material/block/nonfull/FarmlandBlock.php | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index dc65c6a8..b07f9d6a 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -40,12 +40,16 @@ class LevelAPI{ console("[ERROR] Could not load level \"" . $name . "\""); return false; } - for($X = 0; $X < 16; ++$X){ - for($Z = 0; $Z < 16; ++$Z){ - $level->loadChunk($X, $Z); + + if(PocketMinecraftServer::$KEEP_CHUNKS_LOADED){ + for($X = 0; $X < 16; ++$X){ + for($Z = 0; $Z < 16; ++$Z){ + $level->loadChunk($X, $Z); + } } } + $entities = new Config($path . "entities.yml", CONFIG_YAML); if(file_exists($path . "tileEntities.yml")){ @rename($path . "tileEntities.yml", $path . "tiles.yml"); diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 2ec5ebee..ae69bd93 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -11,7 +11,7 @@ class PocketMinecraftServer{ private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0; public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread; - public static $FORCE_20_TPS = false; + public static $FORCE_20_TPS = false, $KEEP_CHUNKS_LOADED = true; function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){ $this->port = (int) $port; $this->doTick = true; @@ -90,13 +90,15 @@ class PocketMinecraftServer{ "16x16x16_chunk_sending" => false, "experimental-mob-ai" => false, "force-20-tps" => false, - "enable-mob-pushing" => Living::$entityPushing + "enable-mob-pushing" => Living::$entityPushing, + "keep-chunks-loaded" => self::$KEEP_CHUNKS_LOADED ]); Player::$smallChunks = $this->extraprops->get("16x16x16_chunk_sending"); Living::$despawnMobs = $this->extraprops->get("despawn-mobs"); Living::$despawnTimer = $this->extraprops->get("mob-despawn-ticks"); 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"); 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"); diff --git a/src/astarnavigator/TileNavigator.php b/src/astarnavigator/TileNavigator.php index 85c3b8a9..98ce61e3 100644 --- a/src/astarnavigator/TileNavigator.php +++ b/src/astarnavigator/TileNavigator.php @@ -184,7 +184,7 @@ class TileNavigator } if($closestToTarget != null){ - return $this->reconstructPath($path, $closestToTarget); + return $this->reconstructPath($path, $closestToTarget); } return null; diff --git a/src/material/block/nonfull/FarmlandBlock.php b/src/material/block/nonfull/FarmlandBlock.php index b7d1fb20..7efa4cc0 100644 --- a/src/material/block/nonfull/FarmlandBlock.php +++ b/src/material/block/nonfull/FarmlandBlock.php @@ -17,7 +17,7 @@ class FarmlandBlock extends TransparentBlock{ } public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ - return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 0.9375, $z + 1)]; + return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)]; } public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){