Search in sources :

Example 6 with BlockFadeEvent

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

the class BlockMycel method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    GlowBlock blockAbove = block.getRelative(BlockFace.UP);
    if (blockAbove.getLightLevel() < 4 && blockAbove.getMaterialValues().getLightOpacity() > 2) {
        // mycel block turns into dirt block
        GlowBlockState state = block.getState();
        state.setType(Material.DIRT);
        BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
        EventFactory.callEvent(fadeEvent);
        if (!fadeEvent.isCancelled()) {
            state.update(true);
        }
    } else if (blockAbove.getLightLevel() >= 9) {
        GlowWorld world = block.getWorld();
        int sourceX = block.getX();
        int sourceY = block.getY();
        int sourceZ = block.getZ();
        // mycel spread randomly around
        for (int i = 0; i < 4; i++) {
            int x = sourceX + random.nextInt(3) - 1;
            int z = sourceZ + random.nextInt(3) - 1;
            int y = sourceY + random.nextInt(5) - 3;
            GlowBlock targetBlock = world.getBlockAt(x, y, z);
            GlowBlock targetAbove = targetBlock.getRelative(BlockFace.UP);
            if (targetBlock.getType() == Material.DIRT && // only spread on normal dirt
            targetBlock.getData() == 0 && targetAbove.getMaterialValues().getLightOpacity() <= 2 && targetAbove.getLightLevel() >= 4) {
                GlowBlockState state = targetBlock.getState();
                state.setType(Material.MYCEL);
                state.setRawData((byte) 0);
                BlockSpreadEvent spreadEvent = new BlockSpreadEvent(targetBlock, block, state);
                EventFactory.callEvent(spreadEvent);
                if (!spreadEvent.isCancelled()) {
                    state.update(true);
                }
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFadeEvent(org.bukkit.event.block.BlockFadeEvent) BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) GlowBlockState(net.glowstone.block.GlowBlockState) GlowWorld(net.glowstone.GlowWorld)

Example 7 with BlockFadeEvent

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

the class BlockIce method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (block.getLightFromBlocks() > 11 - block.getMaterialValues().getLightOpacity()) {
        Material type = block.getWorld().getEnvironment() == Environment.NETHER ? Material.AIR : Material.STATIONARY_WATER;
        GlowBlockState state = block.getState();
        state.setType(type);
        state.setData(new MaterialData(type));
        BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
        EventFactory.callEvent(fadeEvent);
        if (!fadeEvent.isCancelled()) {
            state.update(true);
        }
    }
}
Also used : BlockFadeEvent(org.bukkit.event.block.BlockFadeEvent) GlowBlockState(net.glowstone.block.GlowBlockState) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData)

Aggregations

GlowBlockState (net.glowstone.block.GlowBlockState)7 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)7 MaterialData (org.bukkit.material.MaterialData)3 GlowWorld (net.glowstone.GlowWorld)2 GlowBlock (net.glowstone.block.GlowBlock)2 BlockSpreadEvent (org.bukkit.event.block.BlockSpreadEvent)2 Material (org.bukkit.Material)1