/** * Gets an integer approximation of the yaw between 0 and 255. * * @param loc The location to get the value from. * @return An integer approximation of the yaw. */ public static int getIntYaw(Location loc) { return (int) (loc.getYaw() % 360 / 360 * 256); }
/** * Gets whether there has been a rotation change between the two Locations. * * @param first The initial location. * @param second The final location. * @return A boolean. */ public static boolean hasRotated(Location first, Location second) { return first.getPitch() != second.getPitch() || first.getYaw() != second.getYaw(); }
/** * Get the direction (SOUTH, WEST, NORTH, or EAST) this entity is facing. * * @return The cardinal BlockFace of this entity. */ public BlockFace getCardinalFacing() { double rot = getLocation().getYaw() % 360; if (rot < 0) { rot += 360.0; } if (0 <= rot && rot < 45) { return BlockFace.SOUTH; } else if (45 <= rot && rot < 135) { return BlockFace.WEST; } else if (135 <= rot && rot < 225) { return BlockFace.NORTH; } else if (225 <= rot && rot < 315) { return BlockFace.EAST; } else if (315 <= rot && rot < 360.0) { return BlockFace.SOUTH; } else { return BlockFace.EAST; } }
/** * Gets the full direction (including SOUTH_SOUTH_EAST etc) this entity is facing. * * @return The intercardinal BlockFace of this entity */ public BlockFace getFacing() { long facing = Math.round(getLocation().getYaw() / 22.5) + 8; return Position.getDirection((byte) (facing % 16)); }
/** * Gets a unit-vector pointing in the direction that this Location is * facing. * * @return a vector pointing the direction of this location's {@link * #getPitch() pitch} and {@link #getYaw() yaw} */ public Vector getDirection() { Vector vector = new Vector(); double rotX = this.getYaw(); double rotY = this.getPitch(); vector.setY(-Math.sin(Math.toRadians(rotY))); double xz = Math.cos(Math.toRadians(rotY)); vector.setX(-xz * Math.sin(Math.toRadians(rotX))); vector.setZ(xz * Math.cos(Math.toRadians(rotX))); return vector; }
/** * Launches a projectile from this entity in the horizontal direction it is facing, relative to * the given velocity vector. * * @param type the projectile class * @param location the location to launch the projectile from * @param originalVector the direction to shoot in * @param pitchOffset degrees to subtract from the pitch angle while calculating the y * component of the initial direction * @param velocity the speed for the first flight tick * @param <T> the projectile class * @return the launched projectile */ protected <T extends Projectile> T launchProjectile(Class<? extends T> type, Location location, Vector originalVector, float pitchOffset, float velocity) { double pitchRadians = Math.toRadians(location.getPitch()); double yawRadians = Math.toRadians(location.getYaw()); double verticalMultiplier = cos(pitchRadians); double x = verticalMultiplier * sin(-yawRadians); double z = verticalMultiplier * cos(yawRadians); double y = sin(-(Math.toRadians(location.getPitch() - pitchOffset))); T projectile = launchProjectile(type, location, x, y, z, velocity); projectile.getVelocity().add(originalVector); return projectile; }
diff = Float.valueOf(yawRelative.substring(1)); yaw = location.getYaw() + diff; } else { yaw = Float.valueOf(yawRelative);
/** * Write a Location to the "Pos" and "Rotation" children of a tag. * * <p>Does not save world information, use writeWorld instead. * * @param loc The location to write. * @param tag The tag to write to. */ public static void locationToListTags(Location loc, CompoundTag tag) { tag.putDoubleList("Pos", Arrays.asList(loc.getX(), loc.getY(), loc.getZ())); tag.putFloatList("Rotation", Arrays.asList(loc.getYaw(), loc.getPitch())); }
/** * Create a WorldEdit location from a Bukkit location. * * @param location the Bukkit location * @return a WorldEdit location */ public static Location adapt(org.bukkit.Location location) { checkNotNull(location); Vector3 position = asVector(location); return new com.sk89q.worldedit.util.Location( adapt(location.getWorld()), position, location.getYaw(), location.getPitch()); }
public PositionRotationMessage(Location location) { this(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); }
@Override public com.sk89q.worldedit.util.Location getLocation() { Location nativeLocation = player.getLocation(); Vector3 position = BukkitAdapter.asVector(nativeLocation); return new com.sk89q.worldedit.util.Location( getWorld(), position, nativeLocation.getYaw(), nativeLocation.getPitch()); }
@Override protected void onOpened(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc, GlowBlockState state, MaterialData materialData) { if (materialData instanceof Gate) { Gate gate = (Gate) materialData; gate.setFacingDirection( getOpenDirection(player.getLocation().getYaw(), gate.getFacing())); } else { warnMaterialData(Gate.class, materialData); } }
private static BlockFace getFacingDirection(BlockFace myFacing, BlockFace otherFacing, BlockFace connection, GlowPlayer player) { if (connection != myFacing && connection != myFacing.getOppositeFace()) { return myFacing; } if (connection != otherFacing && connection != otherFacing.getOppositeFace()) { return otherFacing; } float yaw = player.getLocation().getYaw() % 360; yaw = yaw < 0 ? yaw + 360 : yaw; switch (connection) { case NORTH: case SOUTH: return yaw < 180 ? BlockFace.EAST : BlockFace.WEST; case EAST: case WEST: return yaw > 90 && yaw < 270 ? BlockFace.SOUTH : BlockFace.NORTH; default: ConsoleMessages.Warn.Block.Chest.FACING.log(connection); return BlockFace.NORTH; } }
@Override public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) { super.placeBlock(player, state, face, holding, clickedLoc); MaterialData materialData = state.getData(); if (materialData instanceof Gate) { Gate gate = (Gate) materialData; float yaw = player.getLocation().getYaw(); gate.setFacingDirection(blockFaceFromYaw(yaw)); state.update(true); } else { warnMaterialData(Gate.class, materialData); } }
/** * Creates the spawn messages given the shooter ID on the receiving end (which is different for * the shooter than for everyone else). * * @param shooterId the shooter's ID, according to the receiving client * @return the spawn messages */ private List<Message> createSpawnMessage(int shooterId) { List<Message> spawnMessage = super.createSpawnMessage(); double x = location.getX(); double y = location.getY(); double z = location.getZ(); int intPitch = Position.getIntPitch(location); int intHeadYaw = Position.getIntHeadYaw(location.getYaw()); spawnMessage.set(0, new SpawnObjectMessage(getEntityId(), getUniqueId(), SpawnObjectMessage.FISHING_HOOK, x, y, z, intPitch, intHeadYaw, shooterId, velocity)); return spawnMessage; }
/** * Copy the contents of one Location to another. * * @param source The Location to read from. * @param dest The Location to modify. May be null. * @return The dest parameter, modified if not null. */ public static Location copyLocation(Location source, Location dest) { if (dest == null) { return null; } dest.setWorld(source.getWorld()); dest.setX(source.getX()); dest.setY(source.getY()); dest.setZ(source.getZ()); dest.setPitch(source.getPitch()); dest.setYaw(source.getYaw()); return dest; }
double yaw = Math.toRadians(location.getYaw()); double z = Math.sin(yaw); double x = Math.cos(yaw);
private void placeBoat(GlowPlayer player, ItemStack holding) { Block targetBlock = player.getTargetBlock((Set<Material>) null, 5); if (targetBlock != null && !targetBlock.isEmpty() && targetBlock.getRelative(BlockFace.UP).isEmpty()) { Location location = targetBlock.getRelative(BlockFace.UP).getLocation(); // center boat on cursor location location.add(0.6875f, 0, 0.6875f); location.setYaw(player.getLocation().getYaw()); Boat boat = targetBlock.getWorld().spawn(location, Boat.class); boat.setWoodType(woodType); if (player.getGameMode() != GameMode.CREATIVE) { player.getInventory().removeItem(holding); } } }
newTarget.setType(Material.AIR); upper.setType(Material.AIR); float yaw = player.getLocation().getYaw(); float finalYaw = Math.round(yaw / 22.5f / 2) * 45; loc.setYaw(finalYaw - 180);
destination.setYaw(entityLocation.getYaw());