Search in sources :

Example 1 with BlockFire

use of cn.nukkit.block.BlockFire in project Nukkit by Nukkit.

the class EntityLightning method onUpdate.

@Override
public boolean onUpdate(int currentTick) {
    if (this.closed) {
        return false;
    }
    int tickDiff = currentTick - this.lastUpdate;
    if (tickDiff <= 0 && !this.justCreated) {
        return true;
    }
    this.lastUpdate = currentTick;
    this.entityBaseTick(tickDiff);
    if (this.state == 2) {
        this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_THUNDER, 93, -1);
        this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_EXPLODE, 93, -1);
    }
    this.state--;
    if (this.state < 0) {
        if (this.liveTime == 0) {
            this.close();
            return false;
        } else if (this.state < -ThreadLocalRandom.current().nextInt(10)) {
            this.liveTime--;
            this.state = 1;
            if (this.isEffect && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK)) {
                Block block = this.getLevelBlock();
                if (block.getId() == Block.AIR || block.getId() == Block.TALL_GRASS) {
                    BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING);
                    getServer().getPluginManager().callEvent(e);
                    if (!e.isCancelled()) {
                        Block fire = new BlockFire();
                        this.level.setBlock(block, fire);
                        this.getLevel().scheduleUpdate(fire, fire.tickRate());
                    }
                }
            }
        }
    }
    if (this.state >= 0) {
        if (this.isEffect) {
            AxisAlignedBB bb = getBoundingBox().grow(3, 3, 3);
            bb.setMaxX(bb.getMaxX() + 6);
            for (Entity entity : this.level.getCollidingEntities(bb, this)) {
                entity.onStruckByLightning(this);
            }
        }
    }
    return true;
}
Also used : AxisAlignedBB(cn.nukkit.math.AxisAlignedBB) Entity(cn.nukkit.entity.Entity) Block(cn.nukkit.block.Block) BlockIgniteEvent(cn.nukkit.event.block.BlockIgniteEvent) BlockFire(cn.nukkit.block.BlockFire)

Example 2 with BlockFire

use of cn.nukkit.block.BlockFire in project Nukkit by Nukkit.

the class EntityLightning method initEntity.

@Override
protected void initEntity() {
    super.initEntity();
    this.setHealth(4);
    this.setMaxHealth(4);
    this.state = 2;
    this.liveTime = ThreadLocalRandom.current().nextInt(3) + 1;
    if (isEffect && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK) && (this.server.getDifficulty() >= 2)) {
        Block block = this.getLevelBlock();
        if (block.getId() == 0 || block.getId() == Block.TALL_GRASS) {
            BlockFire fire = new BlockFire();
            fire.x = block.x;
            fire.y = block.y;
            fire.z = block.z;
            fire.level = level;
            this.getLevel().setBlock(fire, fire, true);
            if (fire.isBlockTopFacingSurfaceSolid(fire.down()) || fire.canNeighborBurn()) {
                BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING);
                getServer().getPluginManager().callEvent(e);
                if (!e.isCancelled()) {
                    level.setBlock(fire, fire, true);
                    level.scheduleUpdate(fire, fire.tickRate() + ThreadLocalRandom.current().nextInt(10));
                }
            }
        }
    }
}
Also used : Block(cn.nukkit.block.Block) BlockIgniteEvent(cn.nukkit.event.block.BlockIgniteEvent) BlockFire(cn.nukkit.block.BlockFire)

Aggregations

Block (cn.nukkit.block.Block)2 BlockFire (cn.nukkit.block.BlockFire)2 BlockIgniteEvent (cn.nukkit.event.block.BlockIgniteEvent)2 Entity (cn.nukkit.entity.Entity)1 AxisAlignedBB (cn.nukkit.math.AxisAlignedBB)1