Search in sources :

Example 1 with Difficulty

use of org.bukkit.Difficulty in project Glowstone by GlowstoneMC.

the class BlockFire method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (!block.getWorld().getGameRuleMap().getBoolean("doFireTick")) {
        return;
    }
    GlowWorld world = block.getWorld();
    Material type = block.getRelative(BlockFace.DOWN).getType();
    boolean isInfiniteFire;
    switch(type) {
        case NETHERRACK:
            isInfiniteFire = true;
            break;
        case BEDROCK:
            if (world.getEnvironment() == Environment.THE_END) {
                isInfiniteFire = true;
                break;
            }
        default:
            isInfiniteFire = false;
            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 + random.nextInt(3) / 2));
        state.update(true);
    }
    if (!isInfiniteFire) {
        if (!hasNearFlammableBlock(block)) {
            // there's no flammable blocks around, stop fire
            if (age > 3 || block.getRelative(BlockFace.DOWN).isEmpty()) {
                block.breakNaturally();
                world.cancelPulse(block);
            }
        } else if (age == MAX_FIRE_AGE && !block.getRelative(BlockFace.DOWN).isFlammable() && random.nextInt(4) == 0) {
            // if fire reached max age, bottom block is not flammable, 25% chance to stop fire
            block.breakNaturally();
            world.cancelPulse(block);
        } else {
            // 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()), 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) {
                            GlowBlock propagationBlock = world.getBlockAt(block.getLocation().add(x, y, z));
                            int flameResistance = getFlameResistance(propagationBlock);
                            if (flameResistance > 0) {
                                int resistance = (40 + difficultyModifier + flameResistance) / (30 + age);
                                if (isWet) {
                                    resistance /= 2;
                                }
                                if ((!world.hasStorm() || !isRainingAround(propagationBlock)) && resistance > 0 && random.nextInt(y > 1 ? 100 + 100 * (y - 1) : 100) <= resistance) {
                                    BlockIgniteEvent igniteEvent = new BlockIgniteEvent(propagationBlock, IgniteCause.SPREAD, block);
                                    EventFactory.callEvent(igniteEvent);
                                    if (!igniteEvent.isCancelled()) {
                                        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 : Entry(java.util.Map.Entry) GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) Difficulty(org.bukkit.Difficulty) GlowWorld(net.glowstone.GlowWorld) Material(org.bukkit.Material) BlockIgniteEvent(org.bukkit.event.block.BlockIgniteEvent)

Example 2 with Difficulty

use of org.bukkit.Difficulty in project Bukkit by Bukkit.

the class DifficultyCommand method execute.

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender))
        return true;
    if (args.length != 1 || args[0].length() == 0) {
        sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
        return false;
    }
    Difficulty difficulty = Difficulty.getByValue(getDifficultyForString(sender, args[0]));
    if (Bukkit.isHardcore()) {
        difficulty = Difficulty.HARD;
    }
    Bukkit.getWorlds().get(0).setDifficulty(difficulty);
    int levelCount = 1;
    if (Bukkit.getAllowNether()) {
        Bukkit.getWorlds().get(levelCount).setDifficulty(difficulty);
        levelCount++;
    }
    if (Bukkit.getAllowEnd()) {
        Bukkit.getWorlds().get(levelCount).setDifficulty(difficulty);
    }
    Command.broadcastCommandMessage(sender, "Set difficulty to " + difficulty.toString());
    return true;
}
Also used : Difficulty(org.bukkit.Difficulty)

Aggregations

Difficulty (org.bukkit.Difficulty)2 Entry (java.util.Map.Entry)1 GlowWorld (net.glowstone.GlowWorld)1 GlowBlock (net.glowstone.block.GlowBlock)1 GlowBlockState (net.glowstone.block.GlowBlockState)1 Material (org.bukkit.Material)1 BlockIgniteEvent (org.bukkit.event.block.BlockIgniteEvent)1