pocketmine\math\Vector3::length PHP Method

length() public method

public length ( )
    public function length()
    {
        return sqrt($this->lengthSquared());
    }

Usage Example

Beispiel #1
0
 /**
  * @return bool
  */
 public function explodeA() : bool
 {
     if ($this->size < 0.1) {
         return false;
     }
     $vector = new Vector3(0, 0, 0);
     $vBlock = new Vector3(0, 0, 0);
     $mRays = intval($this->rays - 1);
     for ($i = 0; $i < $this->rays; ++$i) {
         for ($j = 0; $j < $this->rays; ++$j) {
             for ($k = 0; $k < $this->rays; ++$k) {
                 if ($i === 0 or $i === $mRays or $j === 0 or $j === $mRays or $k === 0 or $k === $mRays) {
                     $vector->setComponents($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1);
                     $vector->setComponents($vector->x / ($len = $vector->length()) * $this->stepLen, $vector->y / $len * $this->stepLen, $vector->z / $len * $this->stepLen);
                     $pointerX = $this->source->x;
                     $pointerY = $this->source->y;
                     $pointerZ = $this->source->z;
                     for ($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75) {
                         $x = (int) $pointerX;
                         $y = (int) $pointerY;
                         $z = (int) $pointerZ;
                         $vBlock->x = $pointerX >= $x ? $x : $x - 1;
                         $vBlock->y = $pointerY >= $y ? $y : $y - 1;
                         $vBlock->z = $pointerZ >= $z ? $z : $z - 1;
                         if ($vBlock->y < 0 or $vBlock->y > 127) {
                             break;
                         }
                         $block = $this->level->getBlock($vBlock);
                         if ($block->getId() !== 0) {
                             $blastForce -= ($block->getResistance() / 5 + 0.3) * $this->stepLen;
                             if ($blastForce > 0) {
                                 if (!isset($this->affectedBlocks[$index = Level::blockHash($block->x, $block->y, $block->z)])) {
                                     $this->affectedBlocks[$index] = $block;
                                 }
                             }
                         }
                         $pointerX += $vector->x;
                         $pointerY += $vector->y;
                         $pointerZ += $vector->z;
                     }
                 }
             }
         }
     }
     return true;
 }
All Usage Examples Of pocketmine\math\Vector3::length