Search in sources :

Example 1 with GrassSpecies

use of org.bukkit.GrassSpecies in project BKCommonLib by bergerhealer.

the class ParseUtil method parseMaterialData.

/**
     * Tries to parse the text to a data value for a Material
     *
     * @param text to parse
     * @param material to parse the text against
     * @param def to return on failure (hint: use -1)
     * @return Parsed or default value
     */
public static int parseMaterialData(String text, Material material, int def) {
    try {
        return Integer.parseInt(text);
    } catch (NumberFormatException ex) {
        if (material == Material.WOOD) {
            TreeSpecies ts = parseTreeSpecies(text, null);
            if (ts != null) {
                return MaterialUtil.getRawData(ts);
            }
            return def;
        } else {
            MaterialData dat = MaterialUtil.getData(material, 0);
            if (dat instanceof TexturedMaterial) {
                TexturedMaterial tdat = (TexturedMaterial) dat;
                Material mat = parseMaterial(text, null);
                if (mat == null) {
                    return def;
                }
                tdat.setMaterial(mat);
            } else if (dat instanceof Wool) {
                Wool wdat = (Wool) dat;
                DyeColor color = parseEnum(DyeColor.class, text, null);
                if (color == null) {
                    return def;
                }
                wdat.setColor(color);
            } else if (dat instanceof Tree) {
                Tree tdat = (Tree) dat;
                TreeSpecies species = parseTreeSpecies(text, null);
                if (species == null) {
                    return def;
                }
                tdat.setSpecies(species);
            } else if (dat instanceof Leaves) {
                Leaves tdat = (Leaves) dat;
                TreeSpecies species = parseTreeSpecies(text, null);
                if (species == null) {
                    return def;
                }
                tdat.setSpecies(species);
            } else if (dat instanceof LongGrass) {
                LongGrass ldat = (LongGrass) dat;
                GrassSpecies species = parseEnum(GrassSpecies.class, text, null);
                if (species == null) {
                    return def;
                }
                ldat.setSpecies(species);
            } else {
                return def;
            }
            return MaterialUtil.getRawData(dat);
        }
    }
}
Also used : GrassSpecies(org.bukkit.GrassSpecies) TreeSpecies(org.bukkit.TreeSpecies) Material(org.bukkit.Material) DyeColor(org.bukkit.DyeColor)

Example 2 with GrassSpecies

use of org.bukkit.GrassSpecies 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)

Example 3 with GrassSpecies

use of org.bukkit.GrassSpecies in project Glowstone by GlowstoneMC.

the class TallGrassDecorator method decorate.

@Override
public void decorate(World world, Random random, Chunk source) {
    int sourceX = (source.getX() << 4) + random.nextInt(16);
    int sourceZ = (source.getZ() << 4) + random.nextInt(16);
    int sourceY = random.nextInt(Math.abs(world.getHighestBlockYAt(sourceX, sourceZ) << 1));
    // the grass species can change on each decoration pass
    GrassSpecies species = GrassSpecies.NORMAL;
    if (fernDensity > 0 && random.nextFloat() < fernDensity) {
        species = GrassSpecies.FERN_LIKE;
    }
    new TallGrass(new LongGrass(species)).generate(world, random, sourceX, sourceY, sourceZ);
}
Also used : GrassSpecies(org.bukkit.GrassSpecies) TallGrass(net.glowstone.generator.objects.TallGrass) LongGrass(org.bukkit.material.LongGrass)

Aggregations

GrassSpecies (org.bukkit.GrassSpecies)3 LongGrass (org.bukkit.material.LongGrass)2 GlowBlockState (net.glowstone.block.GlowBlockState)1 TallGrass (net.glowstone.generator.objects.TallGrass)1 DyeColor (org.bukkit.DyeColor)1 Material (org.bukkit.Material)1 TreeSpecies (org.bukkit.TreeSpecies)1 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)1 DoublePlant (org.bukkit.material.DoublePlant)1 MaterialData (org.bukkit.material.MaterialData)1 DoublePlantSpecies (org.bukkit.material.types.DoublePlantSpecies)1