use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockBed method afterPlace.
@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
if (block.getType() == Material.BED_BLOCK) {
BlockFace direction = ((Bed) block.getState().getData()).getFacing();
GlowBlock headBlock = block.getRelative(direction);
headBlock.setType(Material.BED_BLOCK);
GlowBlockState headBlockState = headBlock.getState();
MaterialData data = headBlockState.getData();
((Bed) data).setHeadOfBed(true);
((Bed) data).setFacingDirection(direction);
headBlockState.setData(data);
headBlockState.update(true);
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockDirectional method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
super.placeBlock(player, state, face, holding, clickedLoc);
// the direction of the block
BlockFace faceHead = calculateFace(player, state);
state.setRawData((byte) getRawFace(opposite ? faceHead.getOppositeFace() : faceHead));
}
use of org.bukkit.block.BlockFace 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.BlockFace in project Glowstone by GlowstoneMC.
the class TaxicabBlockIterator method hasNext.
@Override
public boolean hasNext() {
if (validBlockCount >= maxBlocks) {
return false;
}
// Note that the pending analysis queue will always contain at least one element: the end of distance marker.
while (nextValidBlocks.isEmpty() && currentDistance <= maxDistance && pendingAnalysis.size() >= 2) {
Object object = pendingAnalysis.remove();
// If we find the end of distance marker, we'll increase the distance, and then we'll re-add it to the end.
if (object == DistanceMarker.INSTANCE) {
pendingAnalysis.add(object);
currentDistance++;
continue;
}
// If it wasn't the EoD marker, it must be a block. We'll look now for valid blocks around it.
Block block = (Block) object;
for (BlockFace face : VALID_FACES) {
Block near = block.getRelative(face);
// Only analyse the block if we haven't checked it yet.
if (usedBlocks.add(near) && isValid(near)) {
nextValidBlocks.add(near);
pendingAnalysis.add(near);
}
}
}
return !nextValidBlocks.isEmpty();
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockStem method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
// in order to grow naturally (vanilla behavior)
if (block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt((int) (25.0F / getGrowthRateModifier(block)) + 1) == 0) {
int cropState = block.getData();
if (cropState >= CropState.RIPE.ordinal()) {
// check around there's not already a fruit
if (block.getRelative(BlockFace.EAST).getType() == fruitType || block.getRelative(BlockFace.WEST).getType() == fruitType || block.getRelative(BlockFace.NORTH).getType() == fruitType || block.getRelative(BlockFace.SOUTH).getType() == fruitType) {
return;
}
// produce a fruit if possible
int n = random.nextInt(4);
BlockFace face;
switch(n) {
case 1:
face = BlockFace.WEST;
break;
case 2:
face = BlockFace.NORTH;
break;
case 3:
face = BlockFace.SOUTH;
break;
default:
face = BlockFace.EAST;
}
GlowBlock targetBlock = block.getRelative(face);
GlowBlockState targetBlockState = targetBlock.getState();
GlowBlock belowTargetBlock = targetBlock.getRelative(BlockFace.DOWN);
if (targetBlock.getType() == Material.AIR && (belowTargetBlock.getType() == Material.SOIL || belowTargetBlock.getType() == Material.DIRT || belowTargetBlock.getType() == Material.GRASS)) {
targetBlockState.setType(fruitType);
if (fruitType == Material.PUMPKIN) {
targetBlockState.setData(new Pumpkin(face.getOppositeFace()));
}
targetBlockState.update(true);
}
} else {
cropState++;
GlowBlockState state = block.getState();
state.setRawData((byte) cropState);
BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
}
}
// we check for insufficient light on the block itself, then drop
if (block.getLightLevel() < 8) {
block.breakNaturally();
}
}
Aggregations