예제 #1
0
 protected function recalculateBoundingBox()
 {
     $f = 0.1875;
     $damage = $this->getFullDamage();
     $bb = new AxisAlignedBB($this->x, $this->y, $this->z, $this->x + 1, $this->y + 2, $this->z + 1);
     $j = $damage & 0x3;
     $isOpen = ($damage & 0x4) > 0;
     $isRight = ($damage & 0x10) > 0;
     if ($j === 0) {
         if ($isOpen) {
             if (!$isRight) {
                 $bb->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + $f);
             } else {
                 $bb->setBounds($this->x, $this->y, $this->z + 1 - $f, $this->x + 1, $this->y + 1, $this->z + 1);
             }
         } else {
             $bb->setBounds($this->x, $this->y, $this->z, $this->x + $f, $this->y + 1, $this->z + 1);
         }
     } elseif ($j === 1) {
         if ($isOpen) {
             if (!$isRight) {
                 $bb->setBounds($this->x + 1 - $f, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1);
             } else {
                 $bb->setBounds($this->x, $this->y, $this->z, $this->x + $f, $this->y + 1, $this->z + 1);
             }
         } else {
             $bb->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + $f);
         }
     } elseif ($j === 2) {
         if ($isOpen) {
             if (!$isRight) {
                 $bb->setBounds($this->x, $this->y, $this->z + 1 - $f, $this->x + 1, $this->y + 1, $this->z + 1);
             } else {
                 $bb->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + $f);
             }
         } else {
             $bb->setBounds($this->x + 1 - $f, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1);
         }
     } elseif ($j === 3) {
         if ($isOpen) {
             if (!$isRight) {
                 $bb->setBounds($this->x, $this->y, $this->z, $this->x + $f, $this->y + 1, $this->z + 1);
             } else {
                 $bb->setBounds($this->x + 1 - $f, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1);
             }
         } else {
             $bb->setBounds($this->x, $this->y, $this->z + 1 - $f, $this->x + 1, $this->y + 1, $this->z + 1);
         }
     }
     return $bb;
 }
예제 #2
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);
     $this->checkChunks();
     return true;
 }
 protected function recalculateBoundingBox()
 {
     $damage = $this->getDamage();
     $f = 0.1875;
     if (($damage & 0x8) > 0) {
         $bb = new AxisAlignedBB($this->x, $this->y + 1 - $f, $this->z, $this->x + 1, $this->y + 1, $this->z + 1);
     } else {
         $bb = new AxisAlignedBB($this->x, $this->y, $this->z, $this->x + 1, $this->y + $f, $this->z + 1);
     }
     if (($damage & 0x4) > 0) {
         if (($damage & 0x3) === 0) {
             $bb->setBounds($this->x, $this->y, $this->z + 1 - $f, $this->x + 1, $this->y + 1, $this->z + 1);
         } elseif (($damage & 0x3) === 1) {
             $bb->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + $f);
         }
         if (($damage & 0x3) === 2) {
             $bb->setBounds($this->x + 1 - $f, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1);
         }
         if (($damage & 0x3) === 3) {
             $bb->setBounds($this->x, $this->y, $this->z, $this->x + $f, $this->y + 1, $this->z + 1);
         }
     }
     return $bb;
 }
예제 #4
0
 protected function recalculateBoundingBox()
 {
     $damage = $this->getDamage();
     $f = 0.1875;
     if (($damage & self::MASK_UPPER) > 0) {
         $bb = new AxisAlignedBB($this->x, $this->y + 1 - $f, $this->z, $this->x + 1, $this->y + 1, $this->z + 1);
     } else {
         $bb = new AxisAlignedBB($this->x, $this->y, $this->z, $this->x + 1, $this->y + $f, $this->z + 1);
     }
     if (($damage & self::MASK_OPENED) > 0) {
         if (($damage & 0x3) === self::MASK_SIDE_NORTH) {
             $bb->setBounds($this->x, $this->y, $this->z + 1 - $f, $this->x + 1, $this->y + 1, $this->z + 1);
         } elseif (($damage & 0x3) === self::MASK_SIDE_SOUTH) {
             $bb->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + $f);
         }
         if (($damage & 0x3) === self::MASK_SIDE_WEST) {
             $bb->setBounds($this->x + 1 - $f, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1);
         }
         if (($damage & 0x3) === self::MASK_SIDE_EAST) {
             $bb->setBounds($this->x, $this->y, $this->z, $this->x + $f, $this->y + 1, $this->z + 1);
         }
     }
     return $bb;
 }
예제 #5
0
 /**
  * Checks for collision against an AxisAlignedBB
  *
  * @param AxisAlignedBB $bb
  *
  * @return bool
  */
 public function collidesWithBB(AxisAlignedBB $bb)
 {
     $bb2 = $this->getBoundingBox();
     return $bb2 !== null and $bb->intersectsWith($bb2);
 }
예제 #6
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, \true);
         $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;
 }
예제 #7
0
 /**
  * Checks for collision against an AxisAlignedBB
  *
  * @param AxisAlignedBB $bb
  * @param Block[]       $list
  */
 public function collidesWithBB(AxisAlignedBB $bb, &$list = [])
 {
     $bb2 = $this->getBoundingBox();
     if ($bb2 !== null and $bb->intersectsWith($bb2)) {
         $list[] = $bb2;
     }
 }
예제 #8
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;
 }