/** * Gets an integer approximation of the pitch between 0 and 255. * * @param loc The location to get the value from. * @return An integer approximation of the yaw. */ public static int getIntPitch(Location loc) { return (int) (loc.getPitch() % 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(); }
/** * 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; }
double pitch = location.getPitch(); if (pitch < -67.5D) { return BlockFace.DOWN;
/** * 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(pitchRelative.substring(1)); pitch = location.getPitch() + diff; } else { pitch = Float.valueOf(pitchRelative);
/** * 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()); }
/** * 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; }
destination.setPitch(entityLocation.getPitch()); destination.setYaw(entityLocation.getYaw());
} else { targetLocation.setYaw(target.getLocation().getYaw()); targetLocation.setPitch(target.getLocation().getPitch());
/** * {@inheritDoc} */ @Override public String getName() { return "Cannon (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ":" + this.location.getPitch() + ":" + this.location.getYaw() + ":" + this.speed + ")"; }
/** * {@inheritDoc} */ @Override public String getName() { return "Exact (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ")"; }
public CustomDesign(String uuid, Map<String, Object> data) { super(((CraftWorld) Bukkit.getWorld((String) data.get("location.world"))).getHandle()); this.uuid = UUID.fromString(uuid); this.ballMeta = new BallData(((MemorySection) data.get("meta")).getValues(true)); final Location location = Location.deserialize(((MemorySection) data.get("location")).getValues(true)); this.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); this.persistent = true; }
public CustomDesign(String uuid, Map<String, Object> data) { super(((CraftWorld) Bukkit.getWorld((String) data.get("location.world"))).getHandle()); this.uuid = UUID.fromString(uuid); this.ballMeta = new BallData(((MemorySection) data.get("meta")).getValues(true)); final Location location = Location.deserialize(((MemorySection) data.get("location")).getValues(true)); this.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); this.persistent = true; }
@Override public String toString() { if (isValid) { return "ca:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY() + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed; } return "i:Invalid Destination"; } }
private void teleportToHitBox() { final Location loc = this.hitBox.getSpigotEntity().getLocation(); if (this.isSmall()) { this.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); } else { this.setPositionRotation(loc.getX(), loc.getY() - 1.0, loc.getZ(), loc.getYaw(), loc.getPitch()); } }
private void teleportToHitBox() { final Location loc = this.hitBox.getSpigotEntity().getLocation(); if (this.isSmall()) { this.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); } else { this.setPositionRotation(loc.getX(), loc.getY() - 1.0, loc.getZ(), loc.getYaw(), loc.getPitch()); } }