From 7eec621f9052424daf5c77e4dfff30df24149431 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 16 Dec 2023 10:11:48 +0300 Subject: [PATCH] better drop, added new setting from nc0.10 --- src/API/ServerAPI.php | 9 ++- src/Player.php | 24 ++----- src/PocketMinecraftServer.php | 2 +- src/entity/Entity.php | 72 ++++++++++--------- src/entity/Living.php | 15 ++-- src/world/Level.php | 2 +- src/world/generator/ExperimentalGenerator.php | 4 +- 7 files changed, 63 insertions(+), 65 deletions(-) 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 c438ef71..88d7bd58 100755 --- a/src/Player.php +++ b/src/Player.php @@ -449,34 +449,20 @@ class Player{ $this->prevChunkX = $X; $this->prevChunkZ = $Z; $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; - //if($this->level->generatorType != 0) unset($chunkToUnload[$d]); - //if($x < 0 || $x > 15 || $z < 0 || $z > 15) continue; if(!isset($this->chunksLoaded[$d])){ $this->chunksOrder[$d] = abs($x - $X) + abs($z - $Z); } } } asort($this->chunksOrder); - /*arsort($chunkToUnload); - if($this->level->generatorType != 0){ - foreach($chunkToUnload as $chunk => $useless){ - $chunkI = explode(":", $chunk); - $cX = $chunkI[0]; - $cZ = $chunkI[1]; - //console("Unloading chunk $cX:$cZ"); - unset($this->chunksLoaded[$chunk]); - $this->level->freeChunk($cX, $cZ, $this); - $this->dataPacket(new UnloadChunkPacket($cX, $cZ)); - } - }*/ $this->reload = true; diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 34cc16c9..3d7f1f89 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -1,7 +1,7 @@ random = new Random(); @@ -354,19 +356,20 @@ class Entity extends Position $hasUpdate = Entity::$updateOnTick ? $this->class === ENTITY_MOB : false; // force true for mobs $time = microtime(true); if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === true and $this->player->blocked !== true && ! $this->dead){ + $myBB = $this->boundingBox->grow(1, 0.5, 1); foreach($this->server->api->entity->getRadius($this, 2, ENTITY_ITEM) as $item){ //TODO vanilla method of searching/radius - if(!$item->closed && $item->spawntime > 0 && ($time - $item->spawntime) >= 0.6){ - if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array( - "eid" => $this->player->eid, - "player" => $this->player, - "entity" => $item, - "block" => $item->type, - "meta" => $item->meta, - "target" => $item->eid - )) !== false){ - $item->close(); - // $item->spawntime = 0; - // $this->server->schedule(15, array($item, "close")); + if(!$item->closed && $item->spawntime > 0 && $item->delayBeforePickup == 0){ + if($item->boundingBox->intersectsWith($myBB)){ + if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array( + "eid" => $this->player->eid, + "player" => $this->player, + "entity" => $item, + "block" => $item->type, + "meta" => $item->meta, + "target" => $item->eid + )) !== false){ + $item->close(); + } } } } @@ -492,8 +495,7 @@ class Entity extends Position return $hasUpdate; } - - + public function updateEntityMovement(){} public function isInVoid(){ return $this->y < -1.6; @@ -571,6 +573,7 @@ class Entity extends Position } } if(!$this->isPlayer()){ + $this->updateEntityMovement(); $update = false; if($this->speedX > -self::MIN_POSSIBLE_SPEED && $this->speedX < self::MIN_POSSIBLE_SPEED){ $this->speedX = 0; @@ -669,9 +672,6 @@ class Entity extends Position $this->speedY -= $this->inWater ? 0.02 : $this->gravity; // TODO: fix packet spam $update = true; } elseif($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){ - // $this->speedX = 0; - // $this->speedY = 0; - // $this->speedZ = 0; $this->server->api->handle("entity.move", $this); $update = true; }elseif ($this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch || $this->lastHeadYaw != $this->headYaw) { @@ -720,19 +720,9 @@ class Entity extends Position $hasUpdate = true; } } - if($this->knockbackTime > 0){ - --$this->knockbackTime; - } - if($this->moveTime > 0){ - -- $this->moveTime; - } - if($this->lookTime > 0){ - -- $this->lookTime; - } - if($this->idleTime > 0){ - -- $this->idleTime; - } + $this->counterUpdate(); + if($this->lastHeadYaw != $this->headYaw){ $this->sendHeadYaw(); } @@ -747,7 +737,25 @@ class Entity extends Position $this->needsUpdate = $hasUpdate; $this->lastUpdate = $now; } - + + public function counterUpdate(){ + if($this->knockbackTime > 0){ + --$this->knockbackTime; + } + if($this->moveTime > 0){ + -- $this->moveTime; + } + if($this->lookTime > 0){ + -- $this->lookTime; + } + if($this->idleTime > 0){ + -- $this->idleTime; + } + if($this->delayBeforePickup > 0){ + --$this->delayBeforePickup; + } + } + public function updateMovement() { if($this->closed === true){ diff --git a/src/entity/Living.php b/src/entity/Living.php index 5f4e3c79..be0ab9fd 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -30,22 +30,22 @@ abstract class Living extends Entity implements Damageable, Pathfindable{ unset($this->ai); unset($this->parent); } - - public function update(){ - if($this->closed) return; + public function updateEntityMovement(){ if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) { $this->ai->updateTasks(); } $this->ai->mobController->rotateTick(); + //$this->ai->mobController->movementTick(); + + /*if(self::$entityPushing){ + $this->collideHandler(); + }*/ if($this->onGround){ //if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){ // $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10); //} - $this->pathFollower->followPath(); + //$this->pathFollower->followPath(); } - - - parent::update(); } public function sendMoveUpdate(){ @@ -53,6 +53,5 @@ abstract class Living extends Entity implements Damageable, Pathfindable{ return; } parent::sendMoveUpdate(); - } } diff --git a/src/world/Level.php b/src/world/Level.php index ccf43a52..524af4f2 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -448,7 +448,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]); diff --git a/src/world/generator/ExperimentalGenerator.php b/src/world/generator/ExperimentalGenerator.php index 35c1f5b6..bd8e407a 100644 --- a/src/world/generator/ExperimentalGenerator.php +++ b/src/world/generator/ExperimentalGenerator.php @@ -54,7 +54,7 @@ class ExperimentalGenerator implements NewLevelGenerator{ public function init(Level $level, Random $random){ $this->level = $level; - $this->random = $random;//new MersenneTwister(); + $this->random = $random; $this->random->setSeed($this->level->level->getSeed()); $this->noiseBase = new NoiseGeneratorPerlin($this->random, 4); $this->selector = new BiomeSelector($this->random, BiomeSelector::$biomes[BIOME_PLAINS]); @@ -154,8 +154,6 @@ class ExperimentalGenerator implements NewLevelGenerator{ $chunk .= (($noiseValue > 0) ? "\x01" : (($y <= $this->waterHeight) ? "\x09" : "\x00")); } $chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; - //$chunk .= str_repeat("\xff", 16); - //$chunk .= str_repeat("\xff", 16); $chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //light $chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //more light }