use of org.bukkit.block.BlockState 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 (sourceY > 0 && (world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty() || // TODO: 1.13 leaves
world.getBlockAt(sourceX, sourceY, sourceZ).getType() == Material.LEGACY_LEAVES)) {
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.block.BlockState in project Glowstone by GlowstoneMC.
the class FireDecorator method decorate.
@Override
public void decorate(World world, Random random, Chunk source) {
int amount = 1 + random.nextInt(1 + random.nextInt(10));
for (int j = 0; j < amount; j++) {
int sourceX = (source.getX() << 4) + random.nextInt(16);
int sourceZ = (source.getZ() << 4) + random.nextInt(16);
int sourceY = 4 + random.nextInt(120);
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);
Block block = world.getBlockAt(x, y, z);
Block blockBelow = world.getBlockAt(x, y - 1, z);
if (y < 128 && block.getType() == Material.AIR && blockBelow.getType() == Material.NETHERRACK) {
BlockState state = block.getState();
state.setType(Material.FIRE);
state.setData(new MaterialData(Material.FIRE));
state.update(true);
}
}
}
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class BlockPatch method generate.
@Override
public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
boolean succeeded = false;
int n = random.nextInt(horizRadius - MIN_RADIUS) + MIN_RADIUS;
int nsquared = n * n;
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) > nsquared) {
continue;
}
for (int y = sourceY - vertRadius; y <= sourceY + vertRadius; y++) {
Block block = world.getBlockAt(x, y, z);
if (!overridables.contains(block.getType())) {
continue;
}
if (TerrainObject.killPlantAbove(block)) {
break;
}
BlockState state = block.getState();
state.setType(type);
state.setData(new MaterialData(type));
state.update(true);
succeeded = true;
break;
}
}
}
return succeeded;
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class SugarCane method generate.
@Override
public boolean generate(World world, Random random, int x, int y, int z) {
if (!world.getBlockAt(x, y, z).isEmpty()) {
return false;
}
Block block = world.getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
boolean adjacentWater = false;
for (BlockFace face : FACES) {
// needs a directly adjacent water block
Material blockType = block.getRelative(face).getType();
if (blockType == Material.WATER) {
adjacentWater = true;
break;
}
}
if (!adjacentWater) {
return false;
}
for (int n = 0; n <= random.nextInt(random.nextInt(3) + 1) + 1; n++) {
block = world.getBlockAt(x, y + n, z).getRelative(BlockFace.DOWN);
if (block.getType() == Material.SUGAR_CANE || block.getType() == Material.GRASS_BLOCK || block.getType() == Material.DIRT || block.getType() == Material.SAND) {
Block caneBlock = block.getRelative(BlockFace.UP);
if (!caneBlock.isEmpty() && !caneBlock.getRelative(BlockFace.UP).isEmpty()) {
return n > 0;
}
BlockState state = caneBlock.getState();
state.setType(Material.SUGAR_CANE);
state.update(true);
}
}
return true;
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class FlowingLiquidDecorator 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(random.nextInt(type == Material.LAVA ? random.nextInt(240) + 8 : 248) + 8);
Block block = world.getBlockAt(sourceX, sourceY, sourceZ);
if ((block.getType() == Material.STONE || block.getType() == Material.AIR) && block.getRelative(BlockFace.DOWN).getType() == Material.STONE && block.getRelative(BlockFace.UP).getType() == Material.STONE) {
int stoneBlockCount = 0;
for (BlockFace face : SIDES) {
if (block.getRelative(face).getType() == Material.STONE) {
stoneBlockCount++;
}
}
if (stoneBlockCount == 3) {
int airBlockCount = 0;
for (BlockFace face : SIDES) {
if (block.getRelative(face).isEmpty()) {
airBlockCount++;
}
}
if (airBlockCount == 1) {
BlockState state = block.getState();
state.setType(type);
state.update(true);
new PulseTask((GlowBlock) state.getBlock(), true, 1, true).startPulseTask();
}
}
}
}
Aggregations