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);
}
}
}
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);
}
}
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);
}
Aggregations