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);
unset($newChunk[$this->getLoaderId()]);
/** @var Player[] $reload */
$reload = [];
foreach ($this->hasSpawned as $player) {
if (!isset($newChunk[$player->getLoaderId()])) {
$this->despawnFrom($player);
} else {
unset($newChunk[$player->getLoaderId()]);
$reload[] = $player;
}
}
foreach ($newChunk as $player) {
$this->spawnTo($player);
}
}
if ($this->chunk === null) {
return;
}
$this->chunk->addEntity($this);
}
}