From 6ba62666c37f06a3ae942e231b26c32a094ac9e4 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sun, 14 Jan 2024 06:43:48 +0300 Subject: [PATCH] fixed multiworld --- src/Player.php | 8 +++++--- src/entity/Entity.php | 4 ++++ src/world/Level.php | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Player.php b/src/Player.php index 212ce852..5481cfbb 100755 --- a/src/Player.php +++ b/src/Player.php @@ -205,8 +205,11 @@ class Player{ $this->level->freeAllChunks($this); unset($this->level->players[$this->CID]); + unset($this->level->entityListPositioned["{$this->entity->chunkX} {$this->entity->chunkZ}"][$this->eid]); + unset($this->level->entityList[$this->eid]); $this->level = $pos->level; - + $this->entity->level = $this->level; + $this->level->entityList[$this->entity->eid] = $this->entity; $this->level->players[$this->CID] = $this; $this->chunksLoaded = []; $this->server->api->entity->spawnToAll($this->entity); @@ -1369,7 +1372,6 @@ class Player{ } public function entityTick(){ if($this->isSleeping) ++$this->sleepingTime; - $this->handlePacketQueues(); } public function handleDataPacket(RakNetDataPacket $packet){ if($this->connected === false){ @@ -1572,7 +1574,7 @@ class Player{ console("[INFO] " . FORMAT_AQUA . $this->username . FORMAT_RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->eid . " at (" . $this->entity->level->getName() . ", " . round($this->entity->x, 2) . ", " . round($this->entity->y, 2) . ", " . round($this->entity->z, 2) . ")"); - return false; //return false so it will not be updated by tickerFunction + break; case ProtocolInfo::READY_PACKET: if($this->loggedIn === false){ break; diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 80fe53df..a52f1fd6 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -86,6 +86,10 @@ class Entity extends Position public $enableAutojump = false; public $yOffset = 0.0; public $noClip = false; + + public $chunkX = 0; + public $chunkZ = 0; + function __construct(Level $level, $eid, $class, $type = 0, $data = array()) { $this->random = new Random(); diff --git a/src/world/Level.php b/src/world/Level.php index 87a2dbe1..7029b0ee 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -355,6 +355,8 @@ class Level{ } public function onTick(PocketMinecraftServer $server, $currentTime){ + safe_var_dump($this->players); + console($this->getName()); if(!$this->stopTime) ++$this->time; for($cX = 0; $cX < 16; ++$cX){ for($cZ = 0; $cZ < 16; ++$cZ){ @@ -385,7 +387,6 @@ class Level{ } $curChunkX = (int)$e->x >> 4; $curChunkZ = (int)$e->z >> 4; - if($e->class === ENTITY_MOB && !$e->isPlayer()){ ++$this->totalMobsAmount; } @@ -397,7 +398,17 @@ class Level{ if($e instanceof Entity){ $newChunkX = (int)$e->x >> 4; $newChunkZ = (int)$e->z >> 4; - + if($e->chunkX != $newChunkX || $e->chunkZ != $newChunkZ){ + $oldIndex = "{$e->chunkX} {$e->chunkZ}"; + unset($this->entityListPositioned[$oldIndex][$e->eid]); + + if($e->level == $this){ + $e->chunkX = $newChunkX; + $e->chunkZ = $newChunkZ; + $newIndex = "$newChunkX $newChunkZ"; + $this->entityListPositioned[$newIndex][$e->eid] = $e->eid; + } + } if($e->level != $this && isset($this->entityListPositioned["$curChunkX $curChunkZ"])){ unset($this->entityListPositioned["$curChunkX $curChunkZ"][$e->eid]); }else if($curChunkX != $newChunkX || $curChunkZ != $newChunkZ){