use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class MegaPineTree method generatePodzolPatch.
private void generatePodzolPatch(int sourceX, int sourceY, int sourceZ) {
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
if (Math.abs(x) != 2 || Math.abs(z) != 2) {
for (int y = 2; y >= -3; y--) {
Block block = loc.getWorld().getBlockAt(sourceX + x, sourceY + y, sourceZ + z);
if (block.getType() == Material.GRASS || block.getType() == Material.DIRT) {
BlockState state = block.getState();
state.setType(Material.DIRT);
DirtType dirtType = DirtType.PODZOL;
if (loc.getWorld().getBlockAt(sourceX + x, sourceY + y + 1, sourceZ + z).getType().isOccluding()) {
dirtType = DirtType.NORMAL;
}
state.setData(new Dirt(dirtType));
state.update(true);
} else if (!block.isEmpty() && sourceY + y < sourceY) {
break;
}
}
}
}
}
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class TallGrass method generate.
public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
while ((world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty() || world.getBlockAt(sourceX, sourceY, sourceZ).getType() == Material.LEAVES) && sourceY > 0) {
sourceY--;
}
for (int i = 0; i < 128; 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);
if (y < 255 && block.getType() == Material.AIR && (block.getRelative(BlockFace.DOWN).getType() == Material.GRASS || block.getRelative(BlockFace.DOWN).getType() == Material.DIRT)) {
BlockState state = block.getState();
state.setType(Material.LONG_GRASS);
state.setData(grassType);
state.update(true);
}
}
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class UpdateSignHandler method handle.
@Override
public void handle(GlowSession session, UpdateSignMessage message) {
GlowPlayer player = session.getPlayer();
Location location = new Location(player.getWorld(), message.getX(), message.getY(), message.getZ());
if (!player.checkSignLocation(location)) {
GlowServer.logger.warning(session + " tried to edit sign at " + location);
return;
}
// filter out json messages that aren't plaintext
String[] lines = new String[4];
for (int i = 0; i < lines.length; ++i) {
lines[i] = message.getMessage()[i].asPlaintext();
}
SignChangeEvent event = new SignChangeEvent(location.getBlock(), player, lines);
EventFactory.callEvent(event);
if (event.isCancelled()) {
GlowServer.logger.warning("Sign was cancelled");
return;
}
// update the sign if it's actually still there
BlockState state = location.getBlock().getState();
if (state instanceof Sign) {
Sign sign = (Sign) state;
for (int i = 0; i < lines.length; ++i) {
sign.setLine(i, lines[i]);
}
sign.update();
}
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class StructureBuilder method createMobSpawner.
public void createMobSpawner(Vector pos, EntityType entityType) {
Vector vec = translate(pos);
if (boundingBox.isVectorInside(vec)) {
BlockState state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
delegate.backupBlockState(state.getBlock());
state.setType(Material.MOB_SPAWNER);
state.update(true);
state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
if (state instanceof CreatureSpawner) {
((CreatureSpawner) state).setSpawnedType(entityType);
}
}
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class LavaDecorator 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 = flowing ? 4 + random.nextInt(120) : 10 + random.nextInt(108);
Block block = world.getBlockAt(sourceX, sourceY, sourceZ);
if ((block.getType() == Material.NETHERRACK || block.isEmpty()) && block.getRelative(BlockFace.UP).getType() == Material.NETHERRACK) {
int netherrackBlockCount = 0;
for (BlockFace face : SIDES) {
if (block.getRelative(face).getType() == Material.NETHERRACK) {
netherrackBlockCount++;
}
}
int airBlockCount = 0;
for (BlockFace face : SIDES) {
if (block.getRelative(face).isEmpty()) {
airBlockCount++;
}
}
if (netherrackBlockCount == 5 || flowing && airBlockCount == 1 && netherrackBlockCount == 4) {
BlockState state = block.getState();
state.setType(Material.LAVA);
state.update(true);
new PulseTask((GlowBlock) block, true, 1, true).startPulseTask();
}
}
}
Aggregations