예제 #1
0
 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);
     }
 }
예제 #2
0
 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;
 }
예제 #3
0
 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;
 }