mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
added ability to customize how many chunks will be loaded
This commit is contained in:
parent
c99382aeb0
commit
85edee8d90
5 changed files with 18 additions and 14 deletions
|
|
@ -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"));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class PocketMinecraftServer{
|
||||
public static $chukSendDelay = 5;
|
||||
public static $chukSendDelay = 5, $chunkLoadingRadius = 4;
|
||||
public $tCnt, $ticks;
|
||||
public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,11 +4,6 @@ class UnloadChunkPacket extends RakNetDataPacket
|
|||
{
|
||||
public $chunkX, $chunkZ;
|
||||
|
||||
public function __construct($chunkX = 0, $chunkZ = 0){
|
||||
$this->chunkX = $chunkX;
|
||||
$this->chunkZ = $chunkZ;
|
||||
}
|
||||
|
||||
public function encode()
|
||||
{
|
||||
$this->reset();
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue