use of org.bukkit.material.LongGrass 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);
}
use of org.bukkit.material.LongGrass in project Glowstone by GlowstoneMC.
the class PlainsPopulator method populateOnGround.
@Override
public void populateOnGround(World world, Random random, Chunk chunk) {
int sourceX = chunk.getX() << 4;
int sourceZ = chunk.getZ() << 4;
int flowerAmount = 15;
int tallGrassAmount = 5;
if (noiseGen.noise(sourceX + 8, sourceZ + 8, 0.5D, 2.0D) >= -0.8D) {
flowerAmount = 4;
tallGrassAmount = 10;
for (int i = 0; i < 7; i++) {
int x = sourceX + random.nextInt(16);
int z = sourceZ + random.nextInt(16);
int y = random.nextInt(world.getHighestBlockYAt(x, z) + 32);
new DoubleTallPlant(DoublePlantSpecies.DOUBLE_TALLGRASS).generate(world, random, x, y, z);
}
}
FlowerType flower = FlowerType.DANDELION;
if (noiseGen.noise(sourceX + 8, sourceZ + 8, 0.5D, 2.0D) < -0.8D) {
flower = TULIPS[random.nextInt(TULIPS.length)];
} else if (random.nextInt(3) > 0) {
flower = FLOWERS[random.nextInt(FLOWERS.length)];
}
for (int i = 0; i < flowerAmount; i++) {
int x = sourceX + random.nextInt(16);
int z = sourceZ + random.nextInt(16);
int y = random.nextInt(world.getHighestBlockYAt(x, z) + 32);
new Flower(flower).generate(world, random, x, y, z);
}
for (int i = 0; i < tallGrassAmount; i++) {
int x = sourceX + random.nextInt(16);
int z = sourceZ + random.nextInt(16);
int y = random.nextInt(world.getHighestBlockYAt(x, z) << 1);
new TallGrass(new LongGrass(GrassSpecies.NORMAL)).generate(world, random, x, y, z);
}
super.populateOnGround(world, random, chunk);
}
use of org.bukkit.material.LongGrass 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.material.LongGrass in project Glowstone by GlowstoneMC.
the class DeadBushDecorator 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(world.getHighestBlockYAt(sourceX, sourceZ) << 1);
while ((world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty() || world.getBlockAt(sourceX, sourceY, sourceZ).getType() == Material.LEAVES) && sourceY > 0) {
sourceY--;
}
for (int i = 0; i < 4; 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).isEmpty()) {
Block blockBelow = world.getBlockAt(x, y - 1, z);
for (Material soil : SOIL_TYPES) {
if (soil == blockBelow.getType()) {
BlockState state = world.getBlockAt(x, y, z).getState();
state.setType(Material.DEAD_BUSH);
state.setData(new LongGrass(GrassSpecies.DEAD));
state.update(true);
break;
}
}
}
}
}
use of org.bukkit.material.LongGrass 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