pocketmine\entity\Entity::checkChunks PHP Method

checkChunks() protected method

protected checkChunks ( )
    protected function checkChunks()
    {
        if ($this->chunk === null or ($this->chunk->getX() !== $this->x >> 4 or $this->chunk->getZ() !== $this->z >> 4)) {
            if ($this->chunk !== null) {
                $this->chunk->removeEntity($this);
            }
            $this->chunk = $this->level->getChunk($this->x >> 4, $this->z >> 4, true);
            if (!$this->justCreated) {
                $newChunk = $this->level->getChunkPlayers($this->x >> 4, $this->z >> 4);
                foreach ($this->hasSpawned as $player) {
                    if (!isset($newChunk[$player->getLoaderId()])) {
                        $this->despawnFrom($player);
                    } else {
                        unset($newChunk[$player->getLoaderId()]);
                    }
                }
                foreach ($newChunk as $player) {
                    $this->spawnTo($player);
                }
            }
            if ($this->chunk === null) {
                return;
            }
            $this->chunk->addEntity($this);
        }
    }