org.bukkit
Class Location

java.lang.Object
  extended by org.bukkit.Location
All Implemented Interfaces:
Cloneable

public class Location
extends Object
implements Cloneable

Represents a 3-dimensional position in a world


Constructor Summary
Location(World world, double x, double y, double z)
          Constructs a new Location with the given coordinates
Location(World world, double x, double y, double z, float yaw, float pitch)
          Constructs a new Location with the given coordinates and direction
 
Method Summary
 Location add(double x, double y, double z)
          Adds the location by another.
 Location add(Location vec)
          Adds the location by another.
 Location add(Vector vec)
          Adds the location by a vector.
 Location clone()
           
 double distance(Location o)
          Get the distance between this location and another.
 double distanceSquared(Location o)
          Get the squared distance between this location and another.
 boolean equals(Object obj)
           
 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.
 Chunk getChunk()
          Gets the chunk at the represented location
 Vector getDirection()
          Gets a Vector pointing in the direction that this Location is facing
 float getPitch()
          Gets the pitch of this location
 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
 double getZ()
          Gets the z-coordinate of this location
 int hashCode()
           
 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)
 Location multiply(double m)
          Performs scalar multiplication, multiplying all components with a scalar.
 void setPitch(float pitch)
          Sets the pitch of this location
 void setWorld(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
 void setZ(double z)
          Sets the z-coordinate of this location
 Location subtract(double x, double y, double z)
          Subtracts the location by another.
 Location subtract(Location vec)
          Subtracts the location by another.
 Location subtract(Vector vec)
          Subtracts the location by a vector.
 String toString()
           
 Vector toVector()
          Constructs a new Vector based on this Location
 Location zero()
          Zero this location's components.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Location

public Location(World world,
                double x,
                double y,
                double z)
Constructs a new Location with the given coordinates

Parameters:
world - The world in which this location resides
x - The x-coordinate of this new location
y - The y-coordinate of this new location
z - The z-coordinate of this new location

Location

public Location(World world,
                double x,
                double y,
                double z,
                float yaw,
                float pitch)
Constructs a new Location with the given coordinates and direction

Parameters:
world - The world in which this location resides
x - The x-coordinate of this new location
y - The y-coordinate of this new location
z - The z-coordinate of this new location
yaw - The absolute rotation on the x-plane, in degrees
pitch - The absolute rotation on the y-plane, in degrees
Method Detail

setWorld

public void setWorld(World world)
Sets the world that this location resides in

Parameters:
world - New world that this location resides in

getWorld

public World getWorld()
Gets the world that this location resides in

Returns:
World that contains this location

getChunk

public Chunk getChunk()
Gets the chunk at the represented location

Returns:
Chunk at the represented location

getBlock

public Block 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

Parameters:
yaw - New yaw

getYaw

public float getYaw()
Gets the yaw of this location

Returns:
Yaw

setPitch

public void setPitch(float pitch)
Sets the pitch of this location

Parameters:
pitch - New pitch

getPitch

public float getPitch()
Gets the pitch of this location

Returns:
Pitch

getDirection

public Vector getDirection()
Gets a Vector pointing in the direction that this Location is facing

Returns:
Vector

add

public Location add(Location vec)
Adds the location by another.

Parameters:
vec - The other location
Returns:
the same location
Throws:
IllegalArgumentException - for differing worlds
See Also:
Vector

add

public Location add(Vector vec)
Adds the location by a vector.

Parameters:
vec - Vector to use
Returns:
the same location
See Also:
Vector

add

public Location add(double x,
                    double y,
                    double z)
Adds the location by another. Not world-aware.

Parameters:
x - X coordinate
y - Y coordinate
z - Z coordinate
Returns:
the same location
See Also:
Vector

subtract

public Location subtract(Location vec)
Subtracts the location by another.

Parameters:
vec - The other location
Returns:
the same location
Throws:
IllegalArgumentException - for differing worlds
See Also:
Vector

subtract

public Location subtract(Vector vec)
Subtracts the location by a vector.

Parameters:
vec - The vector to use
Returns:
the same location
See Also:
Vector

subtract

public Location subtract(double x,
                         double y,
                         double z)
Subtracts the location by another. Not world-aware and orientation independent.

Parameters:
x - X coordinate
y - Y coordinate
z - 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

public double distance(Location o)
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:
IllegalArgumentException - for differing worlds
See Also:
Vector

distanceSquared

public double distanceSquared(Location o)
Get the squared distance between this location and another.

Parameters:
o - The other location
Returns:
the distance
Throws:
IllegalArgumentException - for differing worlds
See Also:
Vector

multiply

public Location multiply(double m)
Performs scalar multiplication, multiplying all components with a scalar. Not world-aware.

Parameters:
m - The factor
Returns:
the same location
See Also:
Vector

zero

public Location zero()
Zero this location's components. Not world-aware.

Returns:
the same location
See Also:
Vector

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

toVector

public Vector toVector()
Constructs a new Vector based on this Location

Returns:
New Vector containing the coordinates represented by this Location

clone

public Location clone()
Overrides:
clone in class 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


Copyright © 2013. All Rights Reserved.