Search in sources :

Example 6 with BlockGrowEvent

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

the class BlockSugarCane method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (!canPlaceAt(block, BlockFace.DOWN)) {
        block.breakNaturally();
        return;
    }
    GlowBlock blockAbove = block.getRelative(BlockFace.UP);
    // check it's the highest block of cactus
    if (blockAbove.isEmpty()) {
        // check the current cane height
        Block blockBelow = block.getRelative(BlockFace.DOWN);
        int height = 1;
        while (blockBelow.getType() == Material.SUGAR_CANE_BLOCK) {
            height++;
            blockBelow = blockBelow.getRelative(BlockFace.DOWN);
        }
        if (height < 3) {
            GlowBlockState state = block.getState();
            if (state.getRawData() < 15) {
                // increase age
                state.setRawData((byte) (state.getRawData() + 1));
                state.update(true);
            } else {
                // grow the sugar cane on the above block
                state.setRawData((byte) 0);
                state.update(true);
                state = blockAbove.getState();
                state.setType(Material.SUGAR_CANE_BLOCK);
                state.setRawData((byte) 0);
                BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
                EventFactory.callEvent(growEvent);
                if (!growEvent.isCancelled()) {
                    state.update(true);
                }
                updatePhysics(blockAbove);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 7 with BlockGrowEvent

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

the class BlockCactus method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    // TODO: Drop entity if the block has near blocks
    GlowBlock blockAbove = block.getRelative(BlockFace.UP);
    // check it's the highest block of cactus
    if (blockAbove.isEmpty()) {
        // check the current cactus height
        Block blockBelow = block.getRelative(BlockFace.DOWN);
        int height = 1;
        while (blockBelow.getType() == Material.CACTUS) {
            height++;
            blockBelow = blockBelow.getRelative(BlockFace.DOWN);
        }
        if (height < 3) {
            GlowBlockState state = block.getState();
            if (state.getRawData() < 15) {
                // increase age
                state.setRawData((byte) (state.getRawData() + 1));
                state.update(true);
            } else {
                // grow the cactus on the above block
                state.setRawData((byte) 0);
                state.update(true);
                state = blockAbove.getState();
                state.setType(Material.CACTUS);
                state.setRawData((byte) 0);
                BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
                EventFactory.callEvent(growEvent);
                if (!growEvent.isCancelled()) {
                    state.update(true);
                }
                updatePhysics(blockAbove);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 8 with BlockGrowEvent

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

the class BlockCrops method grow.

@Override
public void grow(GlowPlayer player, GlowBlock block) {
    GlowBlockState state = block.getState();
    int cropState = block.getData() + random.nextInt(CropState.MEDIUM.ordinal()) + CropState.VERY_SMALL.ordinal();
    if (cropState > CropState.RIPE.ordinal()) {
        cropState = CropState.RIPE.ordinal();
    }
    state.setRawData((byte) cropState);
    BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
    EventFactory.callEvent(growEvent);
    if (!growEvent.isCancelled()) {
        state.update(true);
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 9 with BlockGrowEvent

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

the class BlockStem method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    // in order to grow naturally (vanilla behavior)
    if (block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt((int) (25.0F / getGrowthRateModifier(block)) + 1) == 0) {
        int cropState = block.getData();
        if (cropState >= CropState.RIPE.ordinal()) {
            // check around there's not already a fruit
            if (block.getRelative(BlockFace.EAST).getType() == fruitType || block.getRelative(BlockFace.WEST).getType() == fruitType || block.getRelative(BlockFace.NORTH).getType() == fruitType || block.getRelative(BlockFace.SOUTH).getType() == fruitType) {
                return;
            }
            // produce a fruit if possible
            int n = random.nextInt(4);
            BlockFace face;
            switch(n) {
                case 1:
                    face = BlockFace.WEST;
                    break;
                case 2:
                    face = BlockFace.NORTH;
                    break;
                case 3:
                    face = BlockFace.SOUTH;
                    break;
                default:
                    face = BlockFace.EAST;
            }
            GlowBlock targetBlock = block.getRelative(face);
            GlowBlockState targetBlockState = targetBlock.getState();
            GlowBlock belowTargetBlock = targetBlock.getRelative(BlockFace.DOWN);
            if (targetBlock.getType() == Material.AIR && (belowTargetBlock.getType() == Material.SOIL || belowTargetBlock.getType() == Material.DIRT || belowTargetBlock.getType() == Material.GRASS)) {
                targetBlockState.setType(fruitType);
                if (fruitType == Material.PUMPKIN) {
                    targetBlockState.setData(new Pumpkin(face.getOppositeFace()));
                }
                targetBlockState.update(true);
            }
        } else {
            cropState++;
            GlowBlockState state = block.getState();
            state.setRawData((byte) cropState);
            BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
            EventFactory.callEvent(growEvent);
            if (!growEvent.isCancelled()) {
                state.update(true);
            }
        }
    }
    // we check for insufficient light on the block itself, then drop
    if (block.getLightLevel() < 8) {
        block.breakNaturally();
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) Pumpkin(org.bukkit.material.Pumpkin) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 10 with BlockGrowEvent

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

the class BlockTallGrass method grow.

@Override
public void grow(GlowPlayer player, GlowBlock block) {
    MaterialData data = block.getState().getData();
    if (data instanceof LongGrass) {
        GrassSpecies species = ((LongGrass) data).getSpecies();
        if (species == GrassSpecies.NORMAL || species == GrassSpecies.FERN_LIKE) {
            GlowBlockState headBlockState = block.getRelative(BlockFace.UP).getState();
            if (headBlockState.getType() == Material.AIR) {
                DoublePlantSpecies doublePlantSpecies = species == GrassSpecies.FERN_LIKE ? DoublePlantSpecies.LARGE_FERN : DoublePlantSpecies.DOUBLE_TALLGRASS;
                GlowBlockState blockState = block.getState();
                blockState.setType(Material.DOUBLE_PLANT);
                blockState.setData(new DoublePlant(doublePlantSpecies));
                headBlockState.setType(Material.DOUBLE_PLANT);
                headBlockState.setData(new DoublePlant(DoublePlantSpecies.PLANT_APEX));
                BlockGrowEvent growEvent = new BlockGrowEvent(block, blockState);
                EventFactory.callEvent(growEvent);
                if (!growEvent.isCancelled()) {
                    blockState.update(true);
                    headBlockState.update(true);
                }
            }
        }
    } else {
        warnMaterialData(LongGrass.class, data);
    }
}
Also used : GrassSpecies(org.bukkit.GrassSpecies) DoublePlantSpecies(org.bukkit.material.types.DoublePlantSpecies) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) LongGrass(org.bukkit.material.LongGrass) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent) DoublePlant(org.bukkit.material.DoublePlant)

Aggregations

GlowBlockState (net.glowstone.block.GlowBlockState)11 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)11 GlowBlock (net.glowstone.block.GlowBlock)4 MaterialData (org.bukkit.material.MaterialData)3 Block (org.bukkit.block.Block)2 CocoaPlant (org.bukkit.material.CocoaPlant)2 CocoaPlantSize (org.bukkit.material.CocoaPlant.CocoaPlantSize)2 LongGrass (org.bukkit.material.LongGrass)2 GlowWorld (net.glowstone.GlowWorld)1 FlowerType (net.glowstone.generator.objects.FlowerType)1 GrassSpecies (org.bukkit.GrassSpecies)1 Material (org.bukkit.Material)1 BlockFace (org.bukkit.block.BlockFace)1 DoublePlant (org.bukkit.material.DoublePlant)1 Pumpkin (org.bukkit.material.Pumpkin)1 DoublePlantSpecies (org.bukkit.material.types.DoublePlantSpecies)1