Search in sources :

Example 1 with BlockBurnEvent

use of cn.nukkit.event.block.BlockBurnEvent 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

BlockBurnEvent (cn.nukkit.event.block.BlockBurnEvent)1 BlockIgniteEvent (cn.nukkit.event.block.BlockIgniteEvent)1 Random (java.util.Random)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1