diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 95712d5d..33fe79be 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -138,7 +138,8 @@ class ServerAPI{ "enable-rcon" => false, "rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10), "auto-save" => true, - "chunk-send-delay-ticks" => 5, + "chunk-send-delay-ticks" => PocketMinecraftServer::$chukSendDelay, + "chunk-loading-radius" => PocketMinecraftServer::$chunkLoadingRadius, ]); Biome::init(); $this->parseProperties(); @@ -154,6 +155,12 @@ class ServerAPI{ MobSpawner::$spawnAnimals = $this->getProperty("spawn-animals"); MobSpawner::$spawnMobs = $this->getProperty("spawn-mobs"); PocketMinecraftServer::$chukSendDelay = $this->getProperty("chunk-send-delay-ticks"); + PocketMinecraftServer::$chunkLoadingRadius = $this->getProperty("chunk-loading-radius"); + + if(PocketMinecraftServer::$chunkLoadingRadius < 4){ + ConsoleAPI::warn("Players may not be able to join if chunk loading radius is less than 4!"); + } + if($this->getProperty("upnp-forwarding") == true){ console("[INFO] [UPnP] Trying to port forward..."); UPnP_PortForward($this->getProperty("server-port")); diff --git a/src/Player.php b/src/Player.php index b33b5c21..885dae1b 100755 --- a/src/Player.php +++ b/src/Player.php @@ -430,8 +430,10 @@ class Player{ $ind = "$X:$Z"; if(isset($this->chunksLoaded[$ind])) unset($this->chunksLoaded[$ind]); if(isset($this->chunksOrder[$ind])) unset($this->chunksOrder[$ind]); - - $this->dataPacket(new UnloadChunkPacket($X, $Z)); + $cp = new UnloadChunkPacket; + $cp->x = $X; + $cp->z = $Z; + $this->dataPacket($cp); } public function orderChunks(){ if(!($this->entity instanceof Entity) or $this->connected === false){ @@ -441,10 +443,10 @@ class Player{ $Z = ((int)$this->entity->z) >> 4; $this->chunksOrder = []; //if($this->level->generatorType != 0) $chunkToUnload = $this->chunksLoaded; - $startX = $this->level->generatorType === 1 ? $X - 4 : 0; - $stopX = $this->level->generatorType === 1 ? $X + 4 : 15; - $startZ = $this->level->generatorType === 1 ? $Z - 4 : 0; - $stopZ = $this->level->generatorType === 1 ? $Z + 4 : 15; + $startX = $this->level->generatorType === 1 ? $X - PocketMinecraftServer::$chunkLoadingRadius : 0; + $stopX = $this->level->generatorType === 1 ? $X + PocketMinecraftServer::$chunkLoadingRadius : 15; + $startZ = $this->level->generatorType === 1 ? $Z - PocketMinecraftServer::$chunkLoadingRadius : 0; + $stopZ = $this->level->generatorType === 1 ? $Z + PocketMinecraftServer::$chunkLoadingRadius : 15; for($x = $startX; $x <= $stopX; ++$x){ for($z = $startZ; $z <= $stopZ; ++$z){ $d = $x . ":" . $z; diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 427cca2e..e9bdd7e0 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -1,7 +1,7 @@ chunkX = $chunkX; - $this->chunkZ = $chunkZ; - } - public function encode() { $this->reset(); diff --git a/src/world/Level.php b/src/world/Level.php index dc26073d..a8707245 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -459,7 +459,7 @@ class Level{ $p = $this->server->clients[$cid] ?? false; if($p instanceof Player){ $dist = abs($xz[0] - (((int)$p->entity->x) >> 4)) + abs($xz[1] - (((int)$p->entity->z) >> 4)); - if($dist > 8){ + if($dist > PocketMinecraftServer::$chunkLoadingRadius*2){ //ConsoleAPI::debug("{$p->player} freeing chunk: {$xz[0]} {$xz[1]}"); $this->freeChunk($xz[0], $xz[1], $p); $p->stopUsingChunk($xz[0], $xz[1]);