use of org.bukkit.material.MaterialData 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.MaterialData 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.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockSponge method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
// TODO: Move this to a new method when physics works and run this on neighbour change too.
MaterialData data = holding.getData();
if (!(data instanceof Sponge)) {
warnMaterialData(Sponge.class, data);
return;
}
Sponge sponge = (Sponge) data;
if (sponge.getType() == SpongeType.NORMAL) {
GlowBlock block = state.getBlock();
TaxicabBlockIterator iterator = new TaxicabBlockIterator(block);
iterator.setMaxDistance(7);
iterator.setMaxBlocks(66);
iterator.setValidator(new BlockMaterialValidator(WATER_MATERIALS));
if (iterator.hasNext()) {
sponge = sponge.clone();
sponge.setType(SpongeType.WET);
do {
iterator.next().setType(Material.AIR);
} while (iterator.hasNext());
}
}
state.setType(Material.SPONGE);
state.setData(sponge);
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockStairs method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (data instanceof Stairs) {
((Stairs) data).setFacingDirection(player.getDirection());
if (face == BlockFace.DOWN || face != BlockFace.UP && clickedLoc.getY() >= 0.5) {
((Stairs) data).setInverted(true);
}
state.setData(data);
} else {
warnMaterialData(Stairs.class, data);
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockVine method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
if (random.nextInt(4) == 0) {
GlowBlockState state = block.getState();
MaterialData data = state.getData();
if (data instanceof Vine) {
Vine vine = (Vine) data;
boolean hasNearVineBlocks = hasNearVineBlocks(block);
BlockFace face = FACES[random.nextInt(FACES.length)];
if (block.getY() < 255 && face == BlockFace.UP && block.getRelative(face).isEmpty()) {
if (!hasNearVineBlocks) {
Vine v = (Vine) data;
for (BlockFace f : HORIZONTAL_FACES) {
if (random.nextInt(2) == 0 || !block.getRelative(f).getRelative(face).getType().isSolid()) {
v.removeFromFace(f);
}
}
putVineOnHorizontalBlockFace(block.getRelative(face), v, block);
}
} else if (Arrays.asList(HORIZONTAL_FACES).contains(face) && !vine.isOnFace(face)) {
if (!hasNearVineBlocks) {
GlowBlock b = block.getRelative(face);
if (b.isEmpty()) {
BlockFace clockwiseFace = getClockwiseFace(face);
BlockFace counterClockwiseFace = getCounterClockwiseFace(face);
GlowBlock clockwiseBlock = b.getRelative(clockwiseFace);
GlowBlock counterClockwiseBlock = b.getRelative(counterClockwiseFace);
boolean isOnCWFace = vine.isOnFace(clockwiseFace);
boolean isOnCCWFace = vine.isOnFace(counterClockwiseFace);
if (isOnCWFace && clockwiseBlock.getType().isSolid()) {
putVine(b, new Vine(clockwiseFace), block);
} else if (isOnCCWFace && counterClockwiseBlock.getType().isSolid()) {
putVine(b, new Vine(counterClockwiseFace), block);
} else if (isOnCWFace && clockwiseBlock.isEmpty() && block.getRelative(clockwiseFace).getType().isSolid()) {
putVine(clockwiseBlock, new Vine(face.getOppositeFace()), block);
} else if (isOnCCWFace && counterClockwiseBlock.isEmpty() && block.getRelative(counterClockwiseFace).getType().isSolid()) {
putVine(counterClockwiseBlock, new Vine(face.getOppositeFace()), block);
} else if (b.getRelative(BlockFace.UP).getType().isSolid()) {
putVine(b, new Vine(), block);
}
} else if (b.getType().isOccluding()) {
vine.putOnFace(face);
putVine(block, vine, null);
}
}
} else if (block.getY() > 1) {
GlowBlock b = block.getRelative(BlockFace.DOWN);
Vine v = (Vine) data;
if (b.getType() == Material.VINE || b.isEmpty()) {
for (BlockFace f : HORIZONTAL_FACES) {
if (random.nextInt(2) == 0) {
v.removeFromFace(f);
}
}
putVineOnHorizontalBlockFace(b, v, b.isEmpty() ? block : null);
}
}
} else {
warnMaterialData(Vine.class, data);
}
}
}
Aggregations