use of org.bukkit.block.BlockFace 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);
}
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class ItemBucket method rightClickAir.
@Override
public void rightClickAir(GlowPlayer player, ItemStack holding) {
Iterator<Block> itr = new BlockIterator(player, 5);
Block target = null;
// Used to determine the side the block was clicked on:
Block previousTarget = null;
BlockType targetBlockType = null;
boolean validTarget = false;
// Find the next available non-air liquid block type which is collectible in a radius of 5 blocks
while (itr.hasNext()) {
previousTarget = target;
target = itr.next();
targetBlockType = ItemTable.instance().getBlock(target.getType());
if (targetBlockType instanceof BlockLiquid) {
if (((BlockLiquid) targetBlockType).isCollectible((GlowBlockState) target.getState())) {
validTarget = true;
break;
}
}
}
if (target != null && validTarget) {
// Get the direction of the bucket fill
BlockFace face;
if (previousTarget != null) {
face = target.getFace(previousTarget);
} else {
face = BlockFace.SELF;
}
Material replaceWith = ((BlockLiquid) targetBlockType).getBucketType();
PlayerBucketFillEvent event = EventFactory.callEvent(new PlayerBucketFillEvent(player, target, face, holding.getType(), holding));
if (event.isCancelled()) {
return;
}
if (player.getGameMode() != GameMode.CREATIVE) {
if (holding.getAmount() == 1) {
holding.setType(replaceWith);
} else {
holding.setAmount(holding.getAmount() - 1);
player.getInventory().addItem(new ItemStack(replaceWith));
}
}
target.setType(Material.AIR);
}
}
use of org.bukkit.block.BlockFace 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();
}
}
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class GlowstoneDecorator method decorate.
@Override
public void decorate(World world, Random random, Chunk source) {
int amount = variableAmount ? 1 + random.nextInt(1 + random.nextInt(10)) : 10;
for (int i = 0; i < amount; i++) {
int sourceX = (source.getX() << 4) + random.nextInt(16);
int sourceZ = (source.getZ() << 4) + random.nextInt(16);
int sourceY = 4 + random.nextInt(120);
Block block = world.getBlockAt(sourceX, sourceY, sourceZ);
if (block.isEmpty() && block.getRelative(BlockFace.UP).getType() == Material.NETHERRACK) {
BlockState state = block.getState();
state.setType(Material.GLOWSTONE);
state.update(true);
for (int j = 0; j < 1500; j++) {
int x = sourceX + random.nextInt(8) - random.nextInt(8);
int z = sourceZ + random.nextInt(8) - random.nextInt(8);
int y = sourceY - random.nextInt(12);
block = world.getBlockAt(x, y, z);
if (block.isEmpty()) {
int glowstoneBlockCount = 0;
for (BlockFace face : SIDES) {
if (block.getRelative(face).getType() == Material.GLOWSTONE) {
glowstoneBlockCount++;
}
}
if (glowstoneBlockCount == 1) {
state = block.getState();
state.setType(Material.GLOWSTONE);
state.update(true);
}
}
}
}
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockRedstone method calculateConnections.
public static List<BlockFace> calculateConnections(GlowBlock block) {
List<BlockFace> value = new ArrayList<>();
List<BlockFace> connections = new ArrayList<>();
value.add(BlockFace.DOWN);
for (BlockFace face : SIDES) {
GlowBlock target = block.getRelative(face);
switch(target.getType()) {
case DIODE_BLOCK_ON:
case DIODE_BLOCK_OFF:
Diode diode = (Diode) target.getState().getData();
if (face == diode.getFacing() || face == diode.getFacing().getOppositeFace()) {
connections.add(face);
}
break;
case REDSTONE_BLOCK:
case REDSTONE_TORCH_ON:
case REDSTONE_TORCH_OFF:
case REDSTONE_WIRE:
case WOOD_BUTTON:
case STONE_BUTTON:
case LEVER:
case OBSERVER:
connections.add(face);
break;
default:
if (target.getType().isSolid() && !block.getRelative(BlockFace.UP).getType().isSolid() && target.getRelative(BlockFace.UP).getType() == Material.REDSTONE_WIRE) {
connections.add(face);
} else if (!target.getType().isSolid() && target.getRelative(BlockFace.DOWN).getType() == Material.REDSTONE_WIRE) {
connections.add(face);
}
break;
}
}
if (connections.isEmpty()) {
value.addAll(Arrays.asList(SIDES));
} else {
value.addAll(connections);
if (connections.size() == 1) {
value.add(connections.get(0).getOppositeFace());
}
}
return value;
}
Aggregations