Search in sources :

Example 6 with BlockIgniteEvent

use of cn.nukkit.event.block.BlockIgniteEvent in project Nukkit by Nukkit.

the class BlockFire method tryToCatchBlockOnFire.

private void tryToCatchBlockOnFire(Block block, int bound, int damage) {
    int burnAbility = block.getBurnAbility();
    Random random = ThreadLocalRandom.current();
    if (random.nextInt(bound) < burnAbility) {
        if (random.nextInt(damage + 10) < 5) {
            int meta = damage + random.nextInt(5) / 4;
            if (meta > 15) {
                meta = 15;
            }
            BlockIgniteEvent e = new BlockIgniteEvent(block, this, null, BlockIgniteEvent.BlockIgniteCause.SPREAD);
            this.level.getServer().getPluginManager().callEvent(e);
            if (!e.isCancelled()) {
                this.getLevel().setBlock(block, new BlockFire(meta), true);
                this.getLevel().scheduleUpdate(block, this.tickRate());
            }
        } else {
            BlockBurnEvent ev = new BlockBurnEvent(block);
            this.getLevel().getServer().getPluginManager().callEvent(ev);
            if (!ev.isCancelled()) {
                this.getLevel().setBlock(block, new BlockAir(), true);
            }
        }
        if (block instanceof BlockTNT) {
            ((BlockTNT) block).prime();
        }
    }
}
Also used : Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BlockBurnEvent(cn.nukkit.event.block.BlockBurnEvent) BlockIgniteEvent(cn.nukkit.event.block.BlockIgniteEvent)

Aggregations

BlockIgniteEvent (cn.nukkit.event.block.BlockIgniteEvent)6 Vector3 (cn.nukkit.math.Vector3)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3 Block (cn.nukkit.block.Block)2 BlockFire (cn.nukkit.block.BlockFire)2 Random (java.util.Random)2 Entity (cn.nukkit.entity.Entity)1 BlockBurnEvent (cn.nukkit.event.block.BlockBurnEvent)1 AxisAlignedBB (cn.nukkit.math.AxisAlignedBB)1