Search in sources :

Example 1 with BlockGrowEvent

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

the class BlockGrass method grow.

@Override
public void grow(GlowPlayer player, GlowBlock block) {
    GlowWorld world = block.getWorld();
    int i = 0;
    do {
        int j = 0;
        while (true) {
            // if there's available space
            if (block.getRelative(BlockFace.UP).getType() == Material.AIR) {
                GlowBlock b = block.getRelative(BlockFace.UP);
                GlowBlockState blockState = b.getState();
                if (random.nextFloat() < 0.125D) {
                    // sometimes grow random flower
                    // would be better to call a method that choose a random
                    // flower depending on the biome
                    FlowerType[] flowers = FlowerForestPopulator.FLOWERS;
                    Material flower = flowers[random.nextInt(flowers.length)].getType();
                    if (ItemTable.instance().getBlock(flower).canPlaceAt(b, BlockFace.DOWN)) {
                        blockState.setType(flower);
                    }
                } else {
                    Material tallGrass = Material.LONG_GRASS;
                    if (ItemTable.instance().getBlock(tallGrass).canPlaceAt(b, BlockFace.DOWN)) {
                        // grow tall grass if possible
                        blockState.setType(tallGrass);
                        blockState.setData(new LongGrass(GrassSpecies.NORMAL));
                    }
                }
                BlockGrowEvent growEvent = new BlockGrowEvent(b, blockState);
                EventFactory.callEvent(growEvent);
                if (!growEvent.isCancelled()) {
                    blockState.update(true);
                }
            } else if (j < i / 16) {
                // look around for grass block
                int x = block.getX();
                int y = block.getY();
                int z = block.getZ();
                x += random.nextInt(3) - 1;
                y += random.nextInt(3) * random.nextInt(3) / 2;
                z += random.nextInt(3) - 1;
                if (world.getBlockAt(x, y, z).getType() == Material.GRASS) {
                    j++;
                    continue;
                }
            }
            i++;
            break;
        }
    } while (i < 128);
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) FlowerType(net.glowstone.generator.objects.FlowerType) GlowWorld(net.glowstone.GlowWorld) Material(org.bukkit.Material) LongGrass(org.bukkit.material.LongGrass) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 2 with BlockGrowEvent

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

the class BlockCrops method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    GlowBlockState state = block.getState();
    int cropState = block.getData();
    // in order to grow naturally (vanilla behavior)
    if (cropState < CropState.RIPE.ordinal() && block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt((int) (25.0F / getGrowthRateModifier(block)) + 1) == 0) {
        cropState++;
        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);
        }
    }
    // we check for insufficient light on the block itself, then drop
    if (block.getLightLevel() < 8) {
        block.breakNaturally();
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 3 with BlockGrowEvent

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

the class BlockCocoa method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    MaterialData data = block.getState().getData();
    if (data instanceof CocoaPlant) {
        CocoaPlant cocoa = (CocoaPlant) data;
        CocoaPlantSize size = cocoa.getSize();
        if (size != CocoaPlantSize.LARGE && random.nextInt(5) == 0) {
            if (size == CocoaPlantSize.SMALL) {
                cocoa.setSize(CocoaPlantSize.MEDIUM);
            } else if (size == CocoaPlantSize.MEDIUM) {
                cocoa.setSize(CocoaPlantSize.LARGE);
            } else {
                return;
            }
            GlowBlockState state = block.getState();
            state.setData(cocoa);
            BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
            EventFactory.callEvent(growEvent);
            if (!growEvent.isCancelled()) {
                state.update(true);
            }
        }
    } else {
        warnMaterialData(CocoaPlant.class, data);
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) CocoaPlantSize(org.bukkit.material.CocoaPlant.CocoaPlantSize) MaterialData(org.bukkit.material.MaterialData) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent) CocoaPlant(org.bukkit.material.CocoaPlant)

Example 4 with BlockGrowEvent

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

the class BlockCocoa method grow.

@Override
public void grow(GlowPlayer player, GlowBlock block) {
    MaterialData data = block.getState().getData();
    if (data instanceof CocoaPlant) {
        CocoaPlant cocoa = (CocoaPlant) data;
        CocoaPlantSize size = cocoa.getSize();
        if (size == CocoaPlantSize.SMALL) {
            cocoa.setSize(CocoaPlantSize.MEDIUM);
        } else if (size == CocoaPlantSize.MEDIUM) {
            cocoa.setSize(CocoaPlantSize.LARGE);
        } else {
            return;
        }
        GlowBlockState state = block.getState();
        state.setData(cocoa);
        BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
        EventFactory.callEvent(growEvent);
        if (!growEvent.isCancelled()) {
            state.update(true);
        }
    } else {
        warnMaterialData(CocoaPlant.class, data);
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) CocoaPlantSize(org.bukkit.material.CocoaPlant.CocoaPlantSize) MaterialData(org.bukkit.material.MaterialData) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent) CocoaPlant(org.bukkit.material.CocoaPlant)

Example 5 with BlockGrowEvent

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

the class BlockStem 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)

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