diff --git a/src/Entity.php b/src/Entity.php index d49ac1abf..42cdd91f0 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -325,6 +325,19 @@ abstract class Entity extends Position{ } $this->chunkIndex = $index; $this->level->loadChunk($this->x >> 4, $this->z >> 4); + + $newChunk = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4); + foreach($this->hasSpawned as $CID => $player){ + if(!isset($newChunk[$CID])){ + $this->despawnFrom($player); + }else{ + unset($newChunk[$CID]); + } + } + foreach($newChunk as $player){ + $this->spawnTo($player); + } + $this->level->chunkEntities[$this->chunkIndex][$this->id] = $this; } $this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius); diff --git a/src/Player.php b/src/Player.php index 10e4e5e8c..c15b05505 100644 --- a/src/Player.php +++ b/src/Player.php @@ -265,12 +265,12 @@ class Player extends PlayerEntity{ if(!isset($this->chunksLoaded[$index])){ $this->chunksLoaded[$index] = 0xff; } + $Yndex = $this->chunksLoaded[$index]; + $this->chunksLoaded[$index] = 0; //Load them all $X = null; $Z = null; PMFLevel::getXZ($index, $X, $Z); $this->level->useChunk($X, $Z, $this); - $Yndex = $this->chunksLoaded[$index]; - $this->chunksLoaded[$index] = 0; //Load them all $pk = new ChunkDataPacket; $pk->chunkX = $X; $pk->chunkZ = $Z; diff --git a/src/world/Level.php b/src/world/Level.php index c46260d26..57441bd74 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -62,10 +62,14 @@ class Level{ $this->__destruct(); } + public function getUsingChunk($X, $Z){ + return isset($this->usedChunks[$index]) ? $this->usedChunks[$index]:array(); + } + public function useChunk($X, $Z, Player $player){ $index = PMFLevel::getIndex($X, $Z); $this->loadChunk($X, $Z); - $this->usedChunks[$index][$player->CID] = true; + $this->usedChunks[$index][$player->CID] = $player; } public function freeAllChunks(Player $player){