use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class SugarCane method generate.
public void generate(World world, Random random, int x, int y, int z) {
if (world.getBlockAt(x, y, z).isEmpty()) {
Block block = world.getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
boolean adjacentWater = false;
for (BlockFace face : FACES) {
// needs a directly adjacent water block
if (block.getRelative(face).getType() == Material.STATIONARY_WATER || block.getRelative(face).getType() == Material.WATER) {
adjacentWater = true;
break;
}
}
if (adjacentWater) {
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 || block.getType() == Material.GRASS || block.getType() == Material.DIRT && block.getState().getData() instanceof Dirt && ((Dirt) block.getState().getData()).getType() == DirtType.NORMAL || block.getType() == Material.SAND) {
Block caneBlock = block.getRelative(BlockFace.UP);
if (!caneBlock.isEmpty() && !caneBlock.getRelative(BlockFace.UP).isEmpty()) {
return;
}
BlockState state = caneBlock.getState();
state.setType(Material.SUGAR_CANE_BLOCK);
state.setData(new MaterialData(Material.SUGAR_CANE_BLOCK));
state.update(true);
}
}
}
}
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class StructureBuilder method createRandomItemsContainer.
public boolean createRandomItemsContainer(Vector pos, Random random, RandomItemsContent content, DirectionalContainer container, int maxStacks) {
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(container.getItemType());
state.setData(container);
state.update(true);
return content.fillContainer(random, container, state, maxStacks);
}
return false;
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class BlockSapling method generateTree.
private void generateTree(TreeType type, GlowBlock block, GlowPlayer player) {
// get data but filters sapling age
int data = block.getData() & 0x7;
// replaces the sapling block(s)
block.setType(Material.AIR);
if (type == TreeType.JUNGLE || type == TreeType.MEGA_REDWOOD || type == TreeType.DARK_OAK) {
block.getRelative(BlockFace.SOUTH).setType(Material.AIR);
block.getRelative(BlockFace.EAST).setType(Material.AIR);
block.getRelative(BlockFace.SOUTH_EAST).setType(Material.AIR);
}
// try to generate a tree
Location loc = block.getLocation();
BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
boolean canGrow = false;
if (GlowTree.newInstance(type, random, loc, blockStateDelegate).generate()) {
List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, player != null, player, blockStates);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
canGrow = true;
for (BlockState state : blockStates) {
state.update(true);
}
}
}
if (!canGrow) {
// places the sapling block(s) back if the tree was not generated
// the sapling ages are overwritten but this is an expected
// vanilla behavior
block.setType(Material.SAPLING);
block.setData((byte) data);
if (type == TreeType.JUNGLE || type == TreeType.MEGA_REDWOOD || type == TreeType.DARK_OAK) {
block.getRelative(BlockFace.SOUTH).setType(Material.SAPLING);
block.getRelative(BlockFace.SOUTH).setData((byte) data);
block.getRelative(BlockFace.EAST).setType(Material.SAPLING);
block.getRelative(BlockFace.EAST).setData((byte) data);
block.getRelative(BlockFace.SOUTH_EAST).setType(Material.SAPLING);
block.getRelative(BlockFace.SOUTH_EAST).setData((byte) data);
}
}
}
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 ((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.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