Search in sources :

Example 1 with BlockFromToEvent

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

the class BlockLiquid method flow.

private void flow(GlowBlock source, BlockFace direction) {
    // if we're not going down
    BlockFromToEvent fromToEvent = new BlockFromToEvent(source, direction);
    if (fromToEvent.isCancelled()) {
        return;
    }
    byte strength = fromToEvent.getBlock().getState().getRawData();
    if (DOWN != fromToEvent.getFace()) {
        if (Byte.compare(strength, isWater(fromToEvent.getBlock().getType()) || fromToEvent.getBlock().getBiome() == Biome.HELL ? STRENGTH_MIN_WATER : STRENGTH_MIN_LAVA) < 0) {
            // decrease the strength
            strength += 1;
        } else {
            // no strength, can't flow
            return;
        }
    } else {
        // reset the strength if we're going down
        strength = STRENGTH_MAX;
    }
    // flow to the target
    GlowBlock toBlock = (GlowBlock) fromToEvent.getToBlock();
    toBlock.setType(fromToEvent.getBlock().getType(), strength, false);
    toBlock.getWorld().requestPulse(toBlock);
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFromToEvent(org.bukkit.event.block.BlockFromToEvent)

Aggregations

GlowBlock (net.glowstone.block.GlowBlock)1 BlockFromToEvent (org.bukkit.event.block.BlockFromToEvent)1