Search in sources :

Example 1 with CocoaPlant

use of org.bukkit.material.CocoaPlant 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 2 with CocoaPlant

use of org.bukkit.material.CocoaPlant 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 3 with CocoaPlant

use of org.bukkit.material.CocoaPlant in project Glowstone by GlowstoneMC.

the class BlockCocoa method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    state.setType(getMaterial());
    MaterialData data = state.getData();
    if (data instanceof CocoaPlant) {
        CocoaPlant cocoa = (CocoaPlant) data;
        cocoa.setFacingDirection(face.getOppositeFace());
        cocoa.setSize(CocoaPlantSize.SMALL);
    } else {
        warnMaterialData(CocoaPlant.class, data);
    }
}
Also used : MaterialData(org.bukkit.material.MaterialData) CocoaPlant(org.bukkit.material.CocoaPlant)

Example 4 with CocoaPlant

use of org.bukkit.material.CocoaPlant in project Glowstone by GlowstoneMC.

the class CocoaTree method addCocoa.

private void addCocoa(int sourceX, int sourceY, int sourceZ) {
    if (height > 5 && random.nextInt(5) == 0) {
        for (int y = 0; y < 2; y++) {
            for (BlockFace cocoaFace : COCOA_FACES) {
                // rotate the 4 trunk faces
                if (random.nextInt(COCOA_FACES.length - y) == 0) {
                    // higher it is, more chances there is
                    CocoaPlantSize size = COCOA_SIZE[random.nextInt(COCOA_SIZE.length)];
                    Block block = delegate.getBlockState(loc.getWorld(), sourceX, sourceY + height - 5 + y, sourceZ).getBlock().getRelative(cocoaFace);
                    delegate.setTypeAndData(loc.getWorld(), block.getX(), block.getY(), block.getZ(), Material.COCOA, new CocoaPlant(size, cocoaFace.getOppositeFace()));
                }
            }
        }
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) CocoaPlantSize(org.bukkit.material.CocoaPlant.CocoaPlantSize) CocoaPlant(org.bukkit.material.CocoaPlant)

Aggregations

CocoaPlant (org.bukkit.material.CocoaPlant)4 CocoaPlantSize (org.bukkit.material.CocoaPlant.CocoaPlantSize)3 MaterialData (org.bukkit.material.MaterialData)3 GlowBlockState (net.glowstone.block.GlowBlockState)2 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)2 Block (org.bukkit.block.Block)1 BlockFace (org.bukkit.block.BlockFace)1