Package org.bukkit
Class Location
java.lang.Object
org.bukkit.Location
- All Implemented Interfaces:
java.lang.Cloneable,ConfigurationSerializable
public class Location extends java.lang.Object implements java.lang.Cloneable, ConfigurationSerializable
Represents a 3-dimensional position in a world
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Locationadd(double x, double y, double z)Adds the location by another.Locationadd(Location vec)Adds the location by another.Locationadd(Vector vec)Adds the location by a vector.Locationclone()static Locationdeserialize(java.util.Map<java.lang.String,java.lang.Object> args)Required method for deserializationdoubledistance(Location o)Get the distance between this location and another.doubledistanceSquared(Location o)Get the squared distance between this location and another.booleanequals(java.lang.Object obj)BlockgetBlock()Gets the block at the represented locationintgetBlockX()Gets the floored value of the X component, indicating the block that this location is contained with.intgetBlockY()Gets the floored value of the Y component, indicating the block that this location is contained with.intgetBlockZ()Gets the floored value of the Z component, indicating the block that this location is contained with.ChunkgetChunk()Gets the chunk at the represented locationVectorgetDirection()Gets a unit-vector pointing in the direction that this Location is facing.floatgetPitch()Gets the pitch of this location, measured in degrees.WorldgetWorld()Gets the world that this location resides indoublegetX()Gets the x-coordinate of this locationdoublegetY()Gets the y-coordinate of this locationfloatgetYaw()Gets the yaw of this location, measured in degrees.doublegetZ()Gets the z-coordinate of this locationinthashCode()doublelength()Gets the magnitude of the location, defined as sqrt(x^2+y^2+z^2).doublelengthSquared()Gets the magnitude of the location squared.static intlocToBlock(double loc)Safely converts a double (location coordinate) to an int (block coordinate)Locationmultiply(double m)Performs scalar multiplication, multiplying all components with a scalar.java.util.Map<java.lang.String,java.lang.Object>serialize()Creates a Map representation of this class.LocationsetDirection(Vector vector)voidsetPitch(float pitch)Sets the pitch of this location, measured in degrees.voidsetWorld(World world)Sets the world that this location resides invoidsetX(double x)Sets the x-coordinate of this locationvoidsetY(double y)Sets the y-coordinate of this locationvoidsetYaw(float yaw)Sets the yaw of this location, measured in degrees.voidsetZ(double z)Sets the z-coordinate of this locationLocationsubtract(double x, double y, double z)Subtracts the location by another.Locationsubtract(Location vec)Subtracts the location by another.Locationsubtract(Vector vec)Subtracts the location by a vector.java.lang.StringtoString()VectortoVector()Constructs a newVectorbased on this LocationLocationzero()Zero this location's components.
-
Constructor Details
-
Location
Constructs a new Location with the given coordinates- Parameters:
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 location
-
Location
Constructs a new Location with the given coordinates and direction- Parameters:
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 degrees
-
-
Method Details
-
setWorld
Sets the world that this location resides in- Parameters:
world- New world that this location resides in
-
getWorld
Gets the world that this location resides in- Returns:
- World that contains this location
-
getChunk
Gets the chunk at the represented location- Returns:
- Chunk at the represented location
-
getBlock
Gets the block at the represented location- Returns:
- Block at the represented location
-
setX
public void setX(double x)Sets the x-coordinate of this location- Parameters:
x- X-coordinate
-
getX
public double getX()Gets the x-coordinate of this location- Returns:
- x-coordinate
-
getBlockX
public int getBlockX()Gets the floored value of the X component, indicating the block that this location is contained with.- Returns:
- block X
-
setY
public void setY(double y)Sets the y-coordinate of this location- Parameters:
y- y-coordinate
-
getY
public double getY()Gets the y-coordinate of this location- Returns:
- y-coordinate
-
getBlockY
public int getBlockY()Gets the floored value of the Y component, indicating the block that this location is contained with.- Returns:
- block y
-
setZ
public void setZ(double z)Sets the z-coordinate of this location- Parameters:
z- z-coordinate
-
getZ
public double getZ()Gets the z-coordinate of this location- Returns:
- z-coordinate
-
getBlockZ
public int getBlockZ()Gets the floored value of the Z component, indicating the block that this location is contained with.- Returns:
- block z
-
setYaw
public void setYaw(float yaw)Sets the yaw of this location, measured in degrees.- A yaw of 0 or 360 represents the positive z direction.
- A yaw of 180 represents the negative z direction.
- A yaw of 90 represents the negative x direction.
- A yaw of 270 represents the positive x direction.
- Parameters:
yaw- new rotation's yaw
-
getYaw
public float getYaw()Gets the yaw of this location, measured in degrees.- A yaw of 0 or 360 represents the positive z direction.
- A yaw of 180 represents the negative z direction.
- A yaw of 90 represents the negative x direction.
- A yaw of 270 represents the positive x direction.
- Returns:
- the rotation's yaw
-
setPitch
public void setPitch(float pitch)Sets the pitch of this location, measured in degrees.- A pitch of 0 represents level forward facing.
- A pitch of 90 represents downward facing, or negative y direction.
- A pitch of -90 represents upward facing, or positive y direction.
- Parameters:
pitch- new incline's pitch
-
getPitch
public float getPitch()Gets the pitch of this location, measured in degrees.- A pitch of 0 represents level forward facing.
- A pitch of 90 represents downward facing, or negative y direction.
- A pitch of -90 represents upward facing, or positive y direction.
- Returns:
- the incline's pitch
-
getDirection
Gets a unit-vector pointing in the direction that this Location is facing. -
setDirection
- Parameters:
vector- the direction vector- Returns:
- the same location
-
add
Adds the location by another.- Parameters:
vec- The other location- Returns:
- the same location
- Throws:
java.lang.IllegalArgumentException- for differing worlds- See Also:
Vector
-
add
Adds the location by a vector.- Parameters:
vec- Vector to use- Returns:
- the same location
- See Also:
Vector
-
add
Adds the location by another. Not world-aware.- Parameters:
x- X coordinatey- Y coordinatez- Z coordinate- Returns:
- the same location
- See Also:
Vector
-
subtract
Subtracts the location by another.- Parameters:
vec- The other location- Returns:
- the same location
- Throws:
java.lang.IllegalArgumentException- for differing worlds- See Also:
Vector
-
subtract
Subtracts the location by a vector.- Parameters:
vec- The vector to use- Returns:
- the same location
- See Also:
Vector
-
subtract
Subtracts the location by another. Not world-aware and orientation independent.- Parameters:
x- X coordinatey- Y coordinatez- Z coordinate- Returns:
- the same location
- See Also:
Vector
-
length
public double length()Gets the magnitude of the location, defined as sqrt(x^2+y^2+z^2). The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the location's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the length is too long. Not world-aware and orientation independent.- Returns:
- the magnitude
- See Also:
Vector
-
lengthSquared
public double lengthSquared()Gets the magnitude of the location squared. Not world-aware and orientation independent.- Returns:
- the magnitude
- See Also:
Vector
-
distance
Get the distance between this location and another. The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the location's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the distance is too long.- Parameters:
o- The other location- Returns:
- the distance
- Throws:
java.lang.IllegalArgumentException- for differing worlds- See Also:
Vector
-
distanceSquared
Get the squared distance between this location and another.- Parameters:
o- The other location- Returns:
- the distance
- Throws:
java.lang.IllegalArgumentException- for differing worlds- See Also:
Vector
-
multiply
Performs scalar multiplication, multiplying all components with a scalar. Not world-aware.- Parameters:
m- The factor- Returns:
- the same location
- See Also:
Vector
-
zero
Zero this location's components. Not world-aware.- Returns:
- the same location
- See Also:
Vector
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
toVector
Constructs a newVectorbased on this Location- Returns:
- New Vector containing the coordinates represented by this Location
-
clone
- Overrides:
clonein classjava.lang.Object
-
locToBlock
public static int locToBlock(double loc)Safely converts a double (location coordinate) to an int (block coordinate)- Parameters:
loc- Precise coordinate- Returns:
- Block coordinate
-
serialize
public java.util.Map<java.lang.String,java.lang.Object> serialize()Description copied from interface:ConfigurationSerializableCreates a Map representation of this class.This class must provide a method to restore this class, as defined in the
ConfigurationSerializableinterface javadocs.- Specified by:
serializein interfaceConfigurationSerializable- Returns:
- Map containing the current state of this class
-
deserialize
Required method for deserialization- Parameters:
args- map to deserialize- Returns:
- deserialized location
- Throws:
java.lang.IllegalArgumentException- if the world don't exists- See Also:
ConfigurationSerializable
-