Cloneable
, ConfigurationSerializable
public class Location extends Object implements Cloneable, ConfigurationSerializable
Constructor | Description |
---|---|
Location(@Nullable World world,
double x,
double y,
double z) |
Constructs a new Location with the given coordinates
|
Location(@Nullable World world,
double x,
double y,
double z,
float yaw,
float pitch) |
Constructs a new Location with the given coordinates and direction
|
Modifier and Type | Method | Description |
---|---|---|
@NotNull Location |
add(double x,
double y,
double z) |
Adds the location by another.
|
@NotNull Location |
add(@NotNull Location vec) |
Adds the location by another.
|
@NotNull Location |
add(@NotNull Vector vec) |
Adds the location by a vector.
|
void |
checkFinite() |
Check if each component of this Location is finite.
|
@NotNull Location |
clone() |
|
static @NotNull Location |
deserialize(@NotNull Map<String,Object> args) |
Required method for deserialization
|
double |
distance(@NotNull Location o) |
Get the distance between this location and another.
|
double |
distanceSquared(@NotNull Location o) |
Get the squared distance between this location and another.
|
boolean |
equals(Object obj) |
|
@NotNull Block |
getBlock() |
Gets the block at the represented location
|
int |
getBlockX() |
Gets the floored value of the X component, indicating the block that
this location is contained with.
|
int |
getBlockY() |
Gets the floored value of the Y component, indicating the block that
this location is contained with.
|
int |
getBlockZ() |
Gets the floored value of the Z component, indicating the block that
this location is contained with.
|
@NotNull Chunk |
getChunk() |
Gets the chunk at the represented location
|
@NotNull Vector |
getDirection() |
Gets a unit-vector pointing in the direction that this Location is
facing.
|
float |
getPitch() |
Gets the pitch of this location, measured in degrees.
|
@Nullable World |
getWorld() |
Gets the world that this location resides in
|
double |
getX() |
Gets the x-coordinate of this location
|
double |
getY() |
Gets the y-coordinate of this location
|
float |
getYaw() |
Gets the yaw of this location, measured in degrees.
|
double |
getZ() |
Gets the z-coordinate of this location
|
int |
hashCode() |
|
boolean |
isWorldLoaded() |
Checks if world in this location is present and loaded.
|
double |
length() |
Gets the magnitude of the location, defined as sqrt(x^2+y^2+z^2).
|
double |
lengthSquared() |
Gets the magnitude of the location squared.
|
static int |
locToBlock(double loc) |
Safely converts a double (location coordinate) to an int (block
coordinate)
|
@NotNull Location |
multiply(double m) |
Performs scalar multiplication, multiplying all components with a
scalar.
|
static float |
normalizePitch(float pitch) |
Normalizes the given pitch angle to a value between
+/-90
degrees. |
static float |
normalizeYaw(float yaw) |
Normalizes the given yaw angle to a value between
+/-180
degrees. |
@NotNull Map<String,Object> |
serialize() |
Creates a Map representation of this class.
|
@NotNull Location |
setDirection(@NotNull Vector vector) |
|
void |
setPitch(float pitch) |
Sets the pitch of this location, measured in degrees.
|
void |
setWorld(@Nullable World world) |
Sets the world that this location resides in
|
void |
setX(double x) |
Sets the x-coordinate of this location
|
void |
setY(double y) |
Sets the y-coordinate of this location
|
void |
setYaw(float yaw) |
Sets the yaw of this location, measured in degrees.
|
void |
setZ(double z) |
Sets the z-coordinate of this location
|
@NotNull Location |
subtract(double x,
double y,
double z) |
Subtracts the location by another.
|
@NotNull Location |
subtract(@NotNull Location vec) |
Subtracts the location by another.
|
@NotNull Location |
subtract(@NotNull Vector vec) |
Subtracts the location by a vector.
|
String |
toString() |
|
@NotNull Vector |
toVector() |
Constructs a new
Vector based on this Location |
@NotNull Location |
zero() |
Zero this location's components.
|
public Location(@Nullable @Nullable World world, double x, double y, double z)
world
- The world in which this location residesx
- The x-coordinate of this new locationy
- The y-coordinate of this new locationz
- The z-coordinate of this new locationpublic Location(@Nullable @Nullable World world, double x, double y, double z, float yaw, float pitch)
world
- The world in which this location residesx
- The x-coordinate of this new locationy
- The y-coordinate of this new locationz
- The z-coordinate of this new locationyaw
- The absolute rotation on the x-plane, in degreespitch
- The absolute rotation on the y-plane, in degreespublic void setWorld(@Nullable @Nullable World world)
world
- New world that this location resides inpublic boolean isWorldLoaded()
@Nullable public @Nullable World getWorld()
null
if it is not setIllegalArgumentException
- when world is unloadedisWorldLoaded()
@NotNull public @NotNull Chunk getChunk()
@NotNull public @NotNull Block getBlock()
public void setX(double x)
x
- X-coordinatepublic double getX()
public int getBlockX()
public void setY(double y)
y
- y-coordinatepublic double getY()
public int getBlockY()
public void setZ(double z)
z
- z-coordinatepublic double getZ()
public int getBlockZ()
public void setYaw(float yaw)
yaw
- new rotation's yawpublic float getYaw()
public void setPitch(float pitch)
pitch
- new incline's pitchpublic float getPitch()
@NotNull public @NotNull Vector getDirection()
@NotNull public @NotNull Location setDirection(@NotNull @NotNull Vector vector)
vector
- the direction vector@NotNull public @NotNull Location add(@NotNull @NotNull Location vec)
vec
- The other locationIllegalArgumentException
- for differing worldsVector
@NotNull public @NotNull Location add(@NotNull @NotNull Vector vec)
vec
- Vector to useVector
@NotNull public @NotNull Location add(double x, double y, double z)
x
- X coordinatey
- Y coordinatez
- Z coordinateVector
@NotNull public @NotNull Location subtract(@NotNull @NotNull Location vec)
vec
- The other locationIllegalArgumentException
- for differing worldsVector
@NotNull public @NotNull Location subtract(@NotNull @NotNull Vector vec)
vec
- The vector to useVector
@NotNull public @NotNull Location subtract(double x, double y, double z)
x
- X coordinatey
- Y coordinatez
- Z coordinateVector
public double length()
Vector
public double lengthSquared()
Vector
public double distance(@NotNull @NotNull Location o)
o
- The other locationIllegalArgumentException
- for differing worldsVector
public double distanceSquared(@NotNull @NotNull Location o)
o
- The other locationIllegalArgumentException
- for differing worldsVector
@NotNull public @NotNull Location multiply(double m)
m
- The factorVector
@NotNull public @NotNull Location zero()
Vector
@NotNull public @NotNull Vector toVector()
Vector
based on this Locationpublic void checkFinite() throws IllegalArgumentException
IllegalArgumentException
- if any component is not finitepublic static int locToBlock(double loc)
loc
- Precise coordinate@NotNull public @NotNull Map<String,Object> serialize()
ConfigurationSerializable
This class must provide a method to restore this class, as defined in
the ConfigurationSerializable
interface javadocs.
serialize
in interface ConfigurationSerializable
@NotNull public static @NotNull Location deserialize(@NotNull @NotNull Map<String,Object> args)
args
- map to deserializeIllegalArgumentException
- if the world don't existsConfigurationSerializable
public static float normalizeYaw(float yaw)
+/-180
degrees.yaw
- the yaw in degreesgetYaw()
public static float normalizePitch(float pitch)
+/-90
degrees.pitch
- the pitch in degreesgetPitch()
Copyright © 2020. All rights reserved.