pocketmine\entity\Lightning::spawnToAll PHP Method

spawnToAll() public method

public spawnToAll ( )
    public function spawnToAll()
    {
        parent::spawnToAll();
        if ($this->getLevel()->getServer()->lightningFire) {
            $fire = ItemItem::get(ItemItem::FIRE)->getBlock();
            $oldBlock = $this->getLevel()->getBlock($this);
            if ($oldBlock instanceof Liquid) {
            } elseif ($oldBlock->isSolid()) {
                $v3 = new Vector3($this->x, $this->y + 1, $this->z);
            } else {
                $v3 = new Vector3($this->x, $this->y, $this->z);
            }
            if (isset($v3)) {
                $this->getLevel()->setBlock($v3, $fire);
            }
            foreach ($this->level->getNearbyEntities($this->boundingBox->grow(4, 3, 4), $this) as $entity) {
                if ($entity instanceof Player) {
                    $damage = mt_rand(8, 20);
                    $ev = new EntityDamageByEntityEvent($this, $entity, EntityDamageByEntityEvent::CAUSE_LIGHTNING, $damage);
                    if ($entity->attack($ev->getFinalDamage(), $ev) === true) {
                        $ev->useArmors();
                    }
                    $entity->setOnFire(mt_rand(3, 8));
                }
                if ($entity instanceof Creeper) {
                    $entity->setPowered(true, $this);
                }
            }
        }
    }

Usage Example

Ejemplo n.º 1
0
 public function addLightning(Vector3 $pos, $autoRemoveTime = 3)
 {
     $nbt = new CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $pos->getX()), new DoubleTag("", $pos->getY()), new DoubleTag("", $pos->getZ())]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]);
     $chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, false);
     $lightning = new Lightning($chunk, $nbt);
     $lightning->spawnToAll();
     $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask([$lightning, "close"]), $autoRemoveTime * 20);
 }
All Usage Examples Of pocketmine\entity\Lightning::spawnToAll