Search in sources :

Example 1 with Pumpkin

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

the class PumpkinDecorator method populate.

@Override
public void populate(World world, Random random, Chunk source) {
    if (random.nextInt(32) == 0) {
        int sourceX = (source.getX() << 4) + random.nextInt(16);
        int sourceZ = (source.getZ() << 4) + random.nextInt(16);
        int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1);
        for (int i = 0; i < 64; i++) {
            int x = sourceX + random.nextInt(8) - random.nextInt(8);
            int z = sourceZ + random.nextInt(8) - random.nextInt(8);
            int y = sourceY + random.nextInt(4) - random.nextInt(4);
            if (world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.GRASS) {
                BlockState state = world.getBlockAt(x, y, z).getState();
                state.setType(Material.PUMPKIN);
                // random facing
                state.setData(new Pumpkin(FACES[random.nextInt(FACES.length)]));
                state.update(true);
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Pumpkin(org.bukkit.material.Pumpkin)

Example 2 with Pumpkin

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

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

the class BlockPumpkinBase method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (data instanceof Pumpkin) {
        ((Pumpkin) data).setFacingDirection(player.getDirection());
        state.setData(data);
    } else {
        warnMaterialData(Pumpkin.class, data);
    }
}
Also used : Pumpkin(org.bukkit.material.Pumpkin) MaterialData(org.bukkit.material.MaterialData)

Aggregations

Pumpkin (org.bukkit.material.Pumpkin)3 GlowBlock (net.glowstone.block.GlowBlock)1 GlowBlockState (net.glowstone.block.GlowBlockState)1 BlockFace (org.bukkit.block.BlockFace)1 BlockState (org.bukkit.block.BlockState)1 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)1 MaterialData (org.bukkit.material.MaterialData)1