pocketmine\level\Explosion::explodeA PHP Method

explodeA() public method

public explodeA ( ) : boolean
return boolean
    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;
    }

Usage Example

Example #1
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if (!$this->hadCollision and $this->isCritical) {
         $this->level->addParticle(new CriticalParticle($this->add($this->width / 2 + mt_rand(-100, 100) / 500, $this->height / 2 + mt_rand(-100, 100) / 500, $this->width / 2 + mt_rand(-100, 100) / 500)));
     } elseif ($this->onGround) {
         $this->isCritical = false;
     }
     if ($this->age > 1200 or $this->isCollided) {
         $hasUpdate = true;
         if ($this->isCollided and $this->canExplode) {
             $this->server->getPluginManager()->callEvent($ev = new ExplosionPrimeEvent($this, 2.8));
             if (!$ev->isCancelled()) {
                 $explosion = new Explosion($this, $ev->getForce(), $this->shootingEntity);
                 if ($ev->isBlockBreaking()) {
                     $explosion->explodeA();
                 }
                 $explosion->explodeB();
             }
         }
         $this->kill();
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
All Usage Examples Of pocketmine\level\Explosion::explodeA