Search in sources :

Example 1 with BlockSpreadEvent

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

the class BlockMushroom method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (random.nextInt(25) == 0) {
        GlowWorld world = block.getWorld();
        int x, y, z;
        int i = 0;
        for (x = block.getX() - 4; x <= block.getX() + 4; x++) {
            for (z = block.getZ() - 4; z <= block.getZ() + 4; z++) {
                for (y = block.getY() - 1; y <= block.getY() + 1; y++) {
                    if (world.getBlockAt(x, y, z).getType() == mushroomType) {
                        if (++i > 4) {
                            return;
                        }
                    }
                }
            }
        }
        int nX, nY, nZ;
        nX = block.getX() + random.nextInt(3) - 1;
        nY = block.getY() + random.nextInt(2) - random.nextInt(2);
        nZ = block.getZ() + random.nextInt(3) - 1;
        x = block.getX();
        y = block.getY();
        z = block.getZ();
        for (i = 0; i < 4; i++) {
            if (world.getBlockAt(nX, nY, nZ).getType() == Material.AIR && canPlaceAt(world.getBlockAt(nX, nY, nZ), BlockFace.DOWN)) {
                x = nX;
                y = nY;
                z = nZ;
            }
            nX = x + random.nextInt(3) - 1;
            nY = y + random.nextInt(2) - random.nextInt(2);
            nZ = z + random.nextInt(3) - 1;
        }
        if (world.getBlockAt(nX, nY, nZ).getType() == Material.AIR && canPlaceAt(world.getBlockAt(nX, nY, nZ), BlockFace.DOWN)) {
            GlowBlockState state = world.getBlockAt(nX, nY, nZ).getState();
            state.setType(mushroomType);
            BlockSpreadEvent spreadEvent = new BlockSpreadEvent(state.getBlock(), block, state);
            EventFactory.callEvent(spreadEvent);
            if (!spreadEvent.isCancelled()) {
                state.update(true);
            }
        }
    }
    // it is stated in the wiki
    if (!canPlaceAt(block, BlockFace.DOWN)) {
        block.breakNaturally();
    }
}
Also used : BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) GlowBlockState(net.glowstone.block.GlowBlockState) GlowWorld(net.glowstone.GlowWorld)

Example 2 with BlockSpreadEvent

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

the class BlockVine method putVine.

private void putVine(GlowBlock block, Vine vine, GlowBlock fromBlock) {
    GlowBlockState state = block.getState();
    state.setType(Material.VINE);
    state.setData(vine);
    if (fromBlock != null) {
        BlockSpreadEvent spreadEvent = new BlockSpreadEvent(block, fromBlock, state);
        EventFactory.callEvent(spreadEvent);
        if (!spreadEvent.isCancelled()) {
            state.update(true);
        }
    } else {
        state.update(true);
    }
}
Also used : BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) GlowBlockState(net.glowstone.block.GlowBlockState)

Example 3 with BlockSpreadEvent

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

the class BlockWater method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    super.updateBlock(block);
    if (block.getLightFromBlocks() <= 11 - block.getMaterialValues().getLightOpacity()) {
        if (block.getRelative(BlockFace.UP).isEmpty() && hasNearSolidBlock(block) && GlowBiomeClimate.isCold(block)) {
            GlowBlockState state = block.getState();
            state.setType(Material.ICE);
            state.setData(new MaterialData(Material.ICE));
            BlockSpreadEvent spreadEvent = new BlockSpreadEvent(state.getBlock(), block, state);
            EventFactory.callEvent(spreadEvent);
            if (!spreadEvent.isCancelled()) {
                state.update(true);
            }
        }
    }
}
Also used : BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Example 4 with BlockSpreadEvent

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

the class BlockGrass method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    GlowBlock blockAbove = block.getRelative(BlockFace.UP);
    if (blockAbove.getLightLevel() < 4 && blockAbove.getMaterialValues().getLightOpacity() > 2) {
        // grass 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();
        // grass 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.getChunk().isLoaded() && targetAbove.getChunk().isLoaded() && 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.GRASS);
                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 5 with BlockSpreadEvent

use of org.bukkit.event.block.BlockSpreadEvent 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)

Aggregations

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