use of org.bukkit.material.DoublePlant in project Glowstone by GlowstoneMC.
the class Lake method generate.
public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
sourceY -= (int) MAX_HEIGHT / 2;
byte[] lakeMap = new byte[MAX_BLOCKS];
for (int n = 0; n < random.nextInt(4) + 4; n++) {
double sizeX = random.nextDouble() * 6.0D + 3;
double sizeY = random.nextDouble() * 4.0D + 2;
double sizeZ = random.nextDouble() * 6.0D + 3;
double dX = random.nextDouble() * (MAX_DIAMETER - sizeX - 2) + 1 + sizeX / 2.0D;
double dY = random.nextDouble() * (MAX_HEIGHT - sizeY - 4) + 2 + sizeY / 2.0D;
double dZ = random.nextDouble() * (MAX_DIAMETER - sizeZ - 2) + 1 + sizeZ / 2.0D;
for (int x = 1; x < (int) MAX_DIAMETER - 1; x++) {
for (int z = 1; z < (int) MAX_DIAMETER - 1; z++) {
for (int y = 1; y < (int) MAX_HEIGHT - 1; y++) {
double nX = (x - dX) / (sizeX / 2.0D);
nX *= nX;
double nY = (y - dY) / (sizeY / 2.0D);
nY *= nY;
double nZ = (z - dZ) / (sizeZ / 2.0D);
nZ *= nZ;
if (nX + nY + nZ < 1.0D) {
setLakeBlock(lakeMap, x, y, z);
}
}
}
}
}
if (!canPlace(lakeMap, world, sourceX, sourceY, sourceZ)) {
return;
}
Biome biome = world.getBiome(sourceX + 8 + (int) MAX_DIAMETER / 2, sourceZ + 8 + (int) MAX_DIAMETER / 2);
boolean mycelBiome = Arrays.asList(MYCEL_BIOMES).contains(biome);
for (int x = 0; x < (int) MAX_DIAMETER; x++) {
for (int z = 0; z < (int) MAX_DIAMETER; z++) {
for (int y = 0; y < (int) MAX_HEIGHT; y++) {
if (isLakeBlock(lakeMap, x, y, z)) {
Material type = this.type;
Block block = world.getBlockAt(sourceX + x, sourceY + y, sourceZ + z);
Block blockAbove = block.getRelative(BlockFace.UP);
if (block.getType() == Material.DIRT && (blockAbove.getType() == Material.LOG || blockAbove.getType() == Material.LOG_2) || block.getType() == Material.LOG || block.getType() == Material.LOG_2) {
continue;
}
if (y >= (int) MAX_HEIGHT / 2) {
type = Material.AIR;
for (Material mat : PLANT_TYPES) {
if (blockAbove.getType() == mat) {
if (mat == Material.DOUBLE_PLANT) {
Block blockAboveBlock = blockAbove.getRelative(BlockFace.UP);
if (blockAboveBlock.getState().getData() instanceof DoublePlant && ((DoublePlant) blockAboveBlock.getState().getData()).getSpecies() == DoublePlantSpecies.PLANT_APEX) {
blockAboveBlock.setType(Material.AIR);
}
}
blockAbove.setType(Material.AIR);
break;
}
}
if (this.type == Material.STATIONARY_WATER && (block.getType() == Material.ICE || block.getType() == Material.PACKED_ICE)) {
type = block.getType();
}
} else if (y == MAX_HEIGHT / 2 - 1) {
if (type == Material.STATIONARY_WATER && GlowBiomeClimate.isCold(world.getBiome(sourceX + x, sourceZ + z), sourceX + x, y, sourceZ + z)) {
type = Material.ICE;
}
}
block.setType(type);
}
}
}
}
for (int x = 0; x < (int) MAX_DIAMETER; x++) {
for (int z = 0; z < (int) MAX_DIAMETER; z++) {
for (int y = (int) MAX_HEIGHT / 2; y < (int) MAX_HEIGHT; y++) {
if (isLakeBlock(lakeMap, x, y, z)) {
Block block = world.getBlockAt(sourceX + x, sourceY + y - 1, sourceZ + z);
if (block.getType() == Material.DIRT && !block.getRelative(BlockFace.UP).getType().isOccluding() && block.getRelative(BlockFace.UP).getLightLevel() > 0) {
block.setType(mycelBiome ? Material.MYCEL : Material.GRASS);
}
}
}
}
}
}
use of org.bukkit.material.DoublePlant in project Glowstone by GlowstoneMC.
the class StoneBoulder method generate.
public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
boolean groundReached = false;
while (!groundReached && sourceY > 3) {
Block block = world.getBlockAt(sourceX, sourceY - 1, sourceZ);
if (!block.isEmpty()) {
for (Material mat : GROUND_TYPES) {
if (mat == block.getType()) {
groundReached = true;
sourceY++;
break;
}
}
}
sourceY--;
}
if (groundReached && world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty()) {
for (int i = 0; i < 3; i++) {
int radiusX = random.nextInt(2);
int radiusZ = random.nextInt(2);
int radiusY = random.nextInt(2);
float f = (radiusX + radiusZ + radiusY) * 0.333F + 0.5F;
for (int x = -radiusX; x <= radiusX; x++) {
for (int z = -radiusZ; z <= radiusZ; z++) {
for (int y = -radiusY; y <= radiusY; y++) {
if (x * x + z * z + y * y <= f * f) {
BlockState state = world.getBlockAt(sourceX + x, sourceY + y, sourceZ + z).getState();
Block blockAbove = state.getBlock().getRelative(BlockFace.UP);
for (Material mat : PLANT_TYPES) {
if (blockAbove.getType() == mat) {
if (mat == Material.DOUBLE_PLANT && blockAbove.getState().getData() instanceof DoublePlant && ((DoublePlant) blockAbove.getState().getData()).getSpecies() == DoublePlantSpecies.PLANT_APEX) {
blockAbove.getRelative(BlockFace.UP).setType(Material.AIR);
}
blockAbove.setType(Material.AIR);
break;
}
}
state.setType(Material.MOSSY_COBBLESTONE);
state.setData(new MaterialData(Material.MOSSY_COBBLESTONE));
state.update(true);
}
}
}
}
sourceX += random.nextInt(4) - 1;
sourceZ += random.nextInt(4) - 1;
sourceY -= random.nextInt(2);
}
}
}
use of org.bukkit.material.DoublePlant 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.DoublePlant in project Glowstone by GlowstoneMC.
the class BlockPatch method generate.
public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
int n = random.nextInt(hRadius - MIN_RADIUS) + MIN_RADIUS;
for (int x = sourceX - n; x <= sourceX + n; x++) {
for (int z = sourceZ - n; z <= sourceZ + n; z++) {
if ((x - sourceX) * (x - sourceX) + (z - sourceZ) * (z - sourceZ) <= n * n) {
for (int y = sourceY - vRadius; y <= sourceY + vRadius; y++) {
Block block = world.getBlockAt(x, y, z);
for (Material overridable : overridables) {
if (block.getType() == overridable) {
Block blockAbove = block.getRelative(BlockFace.UP);
for (Material mat : PLANT_TYPES) {
if (blockAbove.getType() == mat) {
if (mat == Material.DOUBLE_PLANT && blockAbove.getState().getData() instanceof DoublePlant && ((DoublePlant) blockAbove.getState().getData()).getSpecies() == DoublePlantSpecies.PLANT_APEX) {
blockAbove.getRelative(BlockFace.UP).setType(Material.AIR);
}
blockAbove.setType(Material.AIR);
break;
}
}
BlockState state = block.getState();
state.setType(type);
state.setData(new MaterialData(type));
state.update(true);
break;
}
}
}
}
}
}
}
Aggregations