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