Search in sources :

Example 1 with BlockIgniteEvent

use of org.bukkit.event.block.BlockIgniteEvent in project MagicPlugin by elBukkit.

the class BlockController method onBlockIgnite.

@EventHandler
public void onBlockIgnite(BlockIgniteEvent event) {
    BlockIgniteEvent.IgniteCause cause = event.getCause();
    if (cause == BlockIgniteEvent.IgniteCause.ENDER_CRYSTAL || cause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) {
        return;
    }
    Entity entity = event.getIgnitingEntity();
    UndoList entityList = controller.getEntityUndo(entity);
    if (entityList != null) {
        entityList.add(event.getBlock());
        return;
    }
    Block ignitingBlock = event.getIgnitingBlock();
    Block targetBlock = event.getBlock();
    if (ignitingBlock != null) {
        UndoList undoList = controller.getPendingUndo(ignitingBlock.getLocation());
        if (undoList != null) {
            undoList.add(event.getBlock());
            return;
        }
    }
    UndoList undoList = controller.getPendingUndo(targetBlock.getLocation());
    if (undoList != null) {
        undoList.add(targetBlock);
    }
}
Also used : Entity(org.bukkit.entity.Entity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) BlockIgniteEvent(org.bukkit.event.block.BlockIgniteEvent) EventHandler(org.bukkit.event.EventHandler)

Example 2 with BlockIgniteEvent

use of org.bukkit.event.block.BlockIgniteEvent in project Glowstone by GlowstoneMC.

the class BlockLava method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    super.updateBlock(block);
    if (!block.getWorld().getGameRuleMap().getBoolean(GameRules.DO_FIRE_TICK)) {
        return;
    }
    int n = ThreadLocalRandom.current().nextInt(3);
    if (n == 0) {
        for (int i = 0; i < 3; i++) {
            GlowBlock b = (GlowBlock) block.getLocation().add(-1 + ThreadLocalRandom.current().nextInt(3), 0, -1 + ThreadLocalRandom.current().nextInt(3)).getBlock();
            GlowBlock aboveB = b.getRelative(BlockFace.UP);
            if (aboveB.isEmpty() && b.isFlammable()) {
                BlockIgniteEvent igniteEvent = new BlockIgniteEvent(aboveB, IgniteCause.LAVA, block);
                EventFactory.getInstance().callEvent(igniteEvent);
                if (!igniteEvent.isCancelled()) {
                    GlowBlockState state = aboveB.getState();
                    state.setType(Material.FIRE);
                    state.update(true);
                }
            }
        }
    } else {
        for (int i = 0; i < n; i++) {
            GlowBlock b = (GlowBlock) block.getLocation().add(-1 + ThreadLocalRandom.current().nextInt(3), 1, -1 + ThreadLocalRandom.current().nextInt(3)).getBlock();
            if (b.isEmpty()) {
                if (hasNearFlammableBlock(b)) {
                    BlockIgniteEvent igniteEvent = new BlockIgniteEvent(b, IgniteCause.LAVA, block);
                    EventFactory.getInstance().callEvent(igniteEvent);
                    if (!igniteEvent.isCancelled()) {
                        GlowBlockState state = b.getState();
                        state.setType(Material.FIRE);
                        state.update(true);
                    }
                    break;
                }
            } else if (b.getType().isSolid()) {
                break;
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) BlockIgniteEvent(org.bukkit.event.block.BlockIgniteEvent)

Example 3 with BlockIgniteEvent

use of org.bukkit.event.block.BlockIgniteEvent in project Glowstone by GlowstoneMC.

the class BlockFire method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (!block.getWorld().getGameRuleMap().getBoolean(GameRules.DO_FIRE_TICK)) {
        return;
    }
    GlowWorld world = block.getWorld();
    Material type = block.getRelative(BlockFace.DOWN).getType();
    boolean isInfiniteFire = false;
    switch(type) {
        case NETHERRACK:
        case MAGMA_BLOCK:
            isInfiniteFire = true;
            break;
        case BEDROCK:
            if (world.getEnvironment() == Environment.THE_END) {
                isInfiniteFire = true;
            }
            break;
        default:
            break;
    }
    if (!isInfiniteFire && world.hasStorm() && isRainingAround(block)) {
        // if it's raining around, stop fire
        block.breakNaturally();
        return;
    }
    // increase fire age
    GlowBlockState state = block.getState();
    int age = state.getRawData();
    if (age < MAX_FIRE_AGE) {
        // increase fire age
        state.setRawData((byte) (age + ThreadLocalRandom.current().nextInt(3) / 2));
        state.update(true);
    }
    if (isInfiniteFire) {
        return;
    }
    if (!hasNearFlammableBlock(block)) {
        // there's no flammable blocks around, stop fire
        if (age > 3 || block.getRelative(BlockFace.DOWN).isEmpty()) {
            block.breakNaturally();
            world.cancelPulse(block);
        }
        return;
    }
    if (age == MAX_FIRE_AGE && !block.getRelative(BlockFace.DOWN).isFlammable() && ThreadLocalRandom.current().nextInt(4) == 0) {
        // if fire reached max age, bottom block is not flammable, 25% chance to stop fire
        block.breakNaturally();
        world.cancelPulse(block);
        return;
    }
    // fire propagation / block burning
    // burn blocks around
    boolean isWet = GlowBiomeClimate.isWet(block);
    for (Entry<BlockFace, Integer> entry : BURNRESISTANCE_MAP.entrySet()) {
        burnBlock(block.getRelative(entry.getKey()), block, entry.getValue() - (isWet ? 50 : 0), age);
    }
    Difficulty difficulty = world.getDifficulty();
    int difficultyModifier;
    switch(difficulty) {
        case EASY:
            difficultyModifier = 7;
            break;
        case NORMAL:
            difficultyModifier = 14;
            break;
        case HARD:
            difficultyModifier = 21;
            break;
        default:
            difficultyModifier = 0;
            break;
    }
    // try to propagate fire in a 3x3x6 box
    for (int x = -1; x <= 1; x++) {
        for (int z = -1; z <= 1; z++) {
            for (int y = -1; y <= 4; y++) {
                if (x == 0 && z == 0 && y == 0) {
                    continue;
                }
                GlowBlock propagationBlock = world.getBlockAt(block.getLocation().add(x, y, z));
                int flameResistance = getFlameResistance(propagationBlock);
                if (flameResistance <= 0) {
                    continue;
                }
                int resistance = (40 + difficultyModifier + flameResistance) / (30 + age);
                if (isWet) {
                    resistance /= 2;
                }
                if ((world.hasStorm() && isRainingAround(propagationBlock)) || resistance <= 0 || ThreadLocalRandom.current().nextInt(y > 1 ? 100 + 100 * (y - 1) : 100) > resistance) {
                    continue;
                }
                BlockIgniteEvent igniteEvent = new BlockIgniteEvent(propagationBlock, IgniteCause.SPREAD, block);
                EventFactory.getInstance().callEvent(igniteEvent);
                if (igniteEvent.isCancelled()) {
                    continue;
                }
                if (propagationBlock.getType() == Material.TNT) {
                    BlockTnt.igniteBlock(propagationBlock, false);
                } else {
                    int increasedAge = increaseFireAge(age);
                    state = propagationBlock.getState();
                    state.setType(Material.FIRE);
                    state.setRawData((byte) (increasedAge > MAX_FIRE_AGE ? MAX_FIRE_AGE : increasedAge));
                    state.update(true);
                    world.requestPulse(propagationBlock);
                }
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) BlockFace(org.bukkit.block.BlockFace) Difficulty(org.bukkit.Difficulty) GlowWorld(net.glowstone.GlowWorld) Material(org.bukkit.Material) BlockIgniteEvent(org.bukkit.event.block.BlockIgniteEvent)

Example 4 with BlockIgniteEvent

use of org.bukkit.event.block.BlockIgniteEvent in project Glowstone by GlowstoneMC.

the class GlowLightningStrike method setBlockOnFire.

private void setBlockOnFire(GlowBlock block) {
    if (block.isEmpty() && block.getRelative(BlockFace.DOWN).isFlammable()) {
        BlockIgniteEvent igniteEvent = new BlockIgniteEvent(block, IgniteCause.LIGHTNING, this);
        EventFactory.getInstance().callEvent(igniteEvent);
        if (!igniteEvent.isCancelled()) {
            BlockState state = block.getState();
            state.setType(Material.FIRE);
            state.update(true);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockIgniteEvent(org.bukkit.event.block.BlockIgniteEvent)

Example 5 with BlockIgniteEvent

use of org.bukkit.event.block.BlockIgniteEvent in project Glowstone by GlowstoneMC.

the class ItemFlintAndSteel method setBlockOnFire.

private boolean setBlockOnFire(GlowPlayer player, GlowBlock clicked, BlockFace face, ItemStack holding, Vector clickedLoc) {
    GlowBlock fireBlock = clicked.getRelative(face);
    if (fireBlock.getType() != Material.AIR) {
        return true;
    }
    if (!clicked.isFlammable() && clicked.getRelative(BlockFace.DOWN).getType() == Material.AIR) {
        return true;
    }
    BlockIgniteEvent event = EventFactory.callEvent(new BlockIgniteEvent(fireBlock, IgniteCause.FLINT_AND_STEEL, player, null));
    if (event.isCancelled()) {
        player.setItemInHand(holding);
        return false;
    }
    // clone holding to avoid decreasing of the item's amount
    ItemTable.instance().getBlock(Material.FIRE).rightClickBlock(player, clicked, face, holding.clone(), clickedLoc);
    return true;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockIgniteEvent(org.bukkit.event.block.BlockIgniteEvent)

Aggregations

BlockIgniteEvent (org.bukkit.event.block.BlockIgniteEvent)8 GlowBlock (net.glowstone.block.GlowBlock)5 GlowBlockState (net.glowstone.block.GlowBlockState)2 Material (org.bukkit.Material)2 Block (org.bukkit.block.Block)2 BlockState (org.bukkit.block.BlockState)2 EventHandler (org.bukkit.event.EventHandler)2 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)1 GlowWorld (net.glowstone.GlowWorld)1 Difficulty (org.bukkit.Difficulty)1 BlockFace (org.bukkit.block.BlockFace)1 Entity (org.bukkit.entity.Entity)1 FallingBlock (org.bukkit.entity.FallingBlock)1