use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BucketDispenseBehavior method dispenseStack.
@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
ItemFilledBucket bucket = (ItemFilledBucket) ItemTable.instance().getItem(stack.getType());
BlockLiquid liquid = (BlockLiquid) bucket.getLiquid();
BlockFace facing = BlockDispenser.getFacing(block);
GlowBlock target = block.getRelative(facing);
if (canPlace(target, facing, stack)) {
target.setType(liquid.getMaterial());
stack.setType(Material.BUCKET);
stack.setAmount(1);
return stack;
} else {
return defaultBehavior.dispense(block, stack);
}
}
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 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);
}
use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.
the class MapResourcePack method createPlaceholderModel.
/**
* Creates a placeholder model. Used when models can not be loaded.
*
* @return placeholder model
*/
protected final Model createPlaceholderModel(RenderOptions renderOptions) {
Model model = new Model();
Model.Element element = new Model.Element();
for (BlockFace face : FaceUtil.BLOCK_SIDES) {
element.faces.put(face, createPlaceholderFace());
}
element.buildQuads();
model.placeholder = true;
model.elements.add(element);
model.name = renderOptions.lookupModelName();
return model;
}
Aggregations