use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class DefaultDispenseBehavior method dispenseStack.
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
BlockFace facing = BlockDispenser.getFacing(block);
Vector dispensePosition = BlockDispenser.getDispensePosition(block);
ItemStack items = new ItemStack(stack.getType(), 1);
stack.setAmount(stack.getAmount() - 1);
doDispense(block, items, 6, facing, dispensePosition);
return stack.getAmount() > 0 ? stack : null;
}
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 BKCommonLib by bergerhealer.
the class CommonMapController method onEntityRightClick.
@EventHandler(priority = EventPriority.LOWEST)
protected void onEntityRightClick(PlayerInteractEntityEvent event) {
if (!(event.getRightClicked() instanceof ItemFrame)) {
return;
}
ItemFrame itemFrame = (ItemFrame) event.getRightClicked();
if (lastClickOffset != null) {
Vector pos = lastClickOffset;
lastClickOffset = null;
BlockFace attachedFace = itemFrame.getAttachedFace();
double dx, dy;
if (FaceUtil.isAlongZ(attachedFace)) {
dx = pos.getX() + 0.5;
dy = 1.0 - (pos.getY() + 0.5);
if (attachedFace == BlockFace.SOUTH) {
dx = 1.0 - dx;
}
} else {
dx = pos.getZ() + 0.5;
dy = 1.0 - (pos.getY() + 0.5);
if (attachedFace == BlockFace.WEST) {
dx = 1.0 - dx;
}
}
event.setCancelled(dispatchClickAction(event.getPlayer(), itemFrame, dx, dy, MapAction.RIGHT_CLICK));
} else {
event.setCancelled(dispatchClickActionApprox(event.getPlayer(), itemFrame, MapAction.RIGHT_CLICK));
}
}
use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.
the class CommonMapController method dispatchClickActionApprox.
private boolean dispatchClickActionApprox(Player player, ItemFrame itemFrame, MapAction action) {
// Calculate the vector position on the map that was clicked
BlockFace attachedFace = itemFrame.getAttachedFace();
Location playerPos = player.getEyeLocation();
Vector dir = playerPos.getDirection();
Block itemBlock = EntityUtil.getHangingBlock(itemFrame);
double target_x = (double) itemBlock.getX() + 1.0;
double target_y = (double) itemBlock.getY() + 1.0;
double target_z = (double) itemBlock.getZ() + 1.0;
// offset from wall
final double FRAME_OFFSET = 0.0625;
double dx, dy;
if (FaceUtil.isAlongZ(attachedFace)) {
if (attachedFace == BlockFace.NORTH) {
target_z -= 1.0;
}
target_z -= attachedFace.getModZ() * FRAME_OFFSET;
dir.multiply((target_z - playerPos.getZ()) / dir.getZ());
dx = target_x - (playerPos.getX() + dir.getX());
dy = target_y - (playerPos.getY() + dir.getY());
if (attachedFace == BlockFace.NORTH) {
dx = 1.0 - dx;
}
} else {
if (attachedFace == BlockFace.WEST) {
target_x -= 1.0;
}
target_x -= attachedFace.getModX() * FRAME_OFFSET;
dir.multiply((target_x - playerPos.getX()) / dir.getX());
dx = target_z - (playerPos.getZ() + dir.getZ());
dy = target_y - (playerPos.getY() + dir.getY());
if (attachedFace == BlockFace.EAST) {
dx = 1.0 - dx;
}
}
return dispatchClickAction(player, itemFrame, dx, dy, action);
}
Aggregations