public function spawnToAll() { if ($this->chunk === null or $this->closed) { return; } foreach ($this->level->getChunkPlayers($this->chunk->getX(), $this->chunk->getZ()) as $player) { if ($player->isOnline()) { $this->spawnTo($player); } } }
public function setPosition(Vector3 $pos, $force = false) { if ($pos instanceof Position and $pos->getLevel() instanceof Level and $pos->getLevel() !== $this->getLevel()) { if ($this->switchLevel($pos->getLevel()) === false) { return false; } } if (!$this->justCreated and $force !== true) { $ev = new EntityMoveEvent($this, $pos); $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return false; } } $this->x = $pos->x; $this->y = $pos->y; $this->z = $pos->z; $radius = $this->width / 2; $this->boundingBox->setBounds($pos->x - $radius, $pos->y + $this->ySize, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height + $this->ySize, $pos->z + $radius); if ($this->chunk === null or $this->chunk->getX() !== $this->x >> 4 and $this->chunk->getZ() !== $this->z >> 4) { if ($this->chunk instanceof FullChunk) { $this->chunk->removeEntity($this); } $this->getLevel()->loadChunk($this->x >> 4, $this->z >> 4); $this->chunk = $this->getLevel()->getChunkAt($this->x >> 4, $this->z >> 4); if (!$this->justCreated) { $newChunk = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4); foreach ($this->hasSpawned as $player) { if (!isset($newChunk[$player->getID()])) { $this->despawnFrom($player); } else { unset($newChunk[$player->getID()]); } } foreach ($newChunk as $player) { $this->spawnTo($player); } } $this->chunk->addEntity($this); } return true; }
public function setPosition(Vector3 $pos) { if ($this->closed) { return false; } if ($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level) { if ($this->switchLevel($pos->getLevel()) === false) { return false; } } $this->x = $pos->x; $this->y = $pos->y; $this->z = $pos->z; $radius = $this->width / 2; $this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius); if ($this->chunk === null or $this->chunkX !== $this->x >> 4 and $this->chunkZ !== $this->z >> 4) { if ($this->chunk !== null) { $this->chunk->removeEntity($this); } $this->level->loadChunk($this->x >> 4, $this->z >> 4); $this->chunk = $this->level->getChunk($this->x >> 4, $this->z >> 4); $this->chunkX = $this->chunk->getX(); $this->chunkZ = $this->chunk->getZ(); if (!$this->justCreated) { $newChunk = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4); foreach ($this->hasSpawned as $player) { if (!isset($newChunk[$player->getId()])) { $this->despawnFrom($player); } else { unset($newChunk[$player->getId()]); } } foreach ($newChunk as $player) { $this->spawnTo($player); } } $this->chunk->addEntity($this); } return true; }
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->getUsingChunk($this->x >> 4, $this->z >> 4); foreach ($this->hasSpawned as $player) { if (!isset($newChunk[$player->getId()])) { $this->despawnFrom($player); } else { unset($newChunk[$player->getId()]); } } foreach ($newChunk as $player) { $this->spawnTo($player); } } if ($this->chunk === null) { return; } $this->chunk->addEntity($this); } }
public function spawnToAll() { if ($this->chunk === null) { return; } foreach ($this->level->getUsingChunk($this->chunk->getX(), $this->chunk->getZ()) as $player) { if ($player->loggedIn === true) { $this->spawnTo($player); } } }