Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.Location Class Reference
Inheritance diagram for org.bukkit.Location:

Public Member Functions

 Location (final World world, final double x, final double y, final double z)
 
 Location (final World world, final double x, final double y, final double z, final float yaw, final float pitch)
 
void setWorld (World world)
 
World getWorld ()
 
Chunk getChunk ()
 
Block getBlock ()
 
void setX (double x)
 
double getX ()
 
int getBlockX ()
 
void setY (double y)
 
double getY ()
 
int getBlockY ()
 
void setZ (double z)
 
double getZ ()
 
int getBlockZ ()
 
void setYaw (float yaw)
 
float getYaw ()
 
void setPitch (float pitch)
 
float getPitch ()
 
Vector getDirection ()
 
Location setDirection (Vector vector)
 
Location add (Location vec)
 
Location add (Vector vec)
 
Location add (double x, double y, double z)
 
Location subtract (Location vec)
 
Location subtract (Vector vec)
 
Location subtract (double x, double y, double z)
 
double length ()
 
double lengthSquared ()
 
double distance (Location o)
 
double distanceSquared (Location o)
 
Location multiply (double m)
 
Location zero ()
 
boolean equals (Object obj)
 
int hashCode ()
 
String toString ()
 
Vector toVector ()
 
Location clone ()
 

Static Public Member Functions

static int locToBlock (double loc)
 

Detailed Description

Represents a 3-dimensional position in a world

Definition at line 10 of file Location.java.

Constructor & Destructor Documentation

org.bukkit.Location.Location ( final World  world,
final double  x,
final double  y,
final double  z 
)

Constructs a new Location with the given coordinates

Parameters
worldThe world in which this location resides
xThe x-coordinate of this new location
yThe y-coordinate of this new location
zThe z-coordinate of this new location

Definition at line 26 of file Location.java.

26  {
27  this(world, x, y, z, 0, 0);
28  }
org.bukkit.Location.Location ( final World  world,
final double  x,
final double  y,
final double  z,
final float  yaw,
final float  pitch 
)

Constructs a new Location with the given coordinates and direction

Parameters
worldThe world in which this location resides
xThe x-coordinate of this new location
yThe y-coordinate of this new location
zThe z-coordinate of this new location
yawThe absolute rotation on the x-plane, in degrees
pitchThe absolute rotation on the y-plane, in degrees

Definition at line 40 of file Location.java.

40  {
41  this.world = world;
42  this.x = x;
43  this.y = y;
44  this.z = z;
45  this.pitch = pitch;
46  this.yaw = yaw;
47  }

Member Function Documentation

Location org.bukkit.Location.add ( Location  vec)

Adds the location by another.

See also
Vector
Parameters
vecThe other location
Returns
the same location
Exceptions
IllegalArgumentExceptionfor differing worlds

Definition at line 301 of file Location.java.

References org.bukkit.Location.getWorld().

301  {
302  if (vec == null || vec.getWorld() != getWorld()) {
303  throw new IllegalArgumentException("Cannot add Locations of differing worlds");
304  }
305 
306  x += vec.x;
307  y += vec.y;
308  z += vec.z;
309  return this;
310  }
Location org.bukkit.Location.add ( Vector  vec)

Adds the location by a vector.

See also
Vector
Parameters
vecVector to use
Returns
the same location

Definition at line 319 of file Location.java.

References org.bukkit.util.Vector.getX(), org.bukkit.util.Vector.getY(), and org.bukkit.util.Vector.getZ().

319  {
320  this.x += vec.getX();
321  this.y += vec.getY();
322  this.z += vec.getZ();
323  return this;
324  }
Location org.bukkit.Location.add ( double  x,
double  y,
double  z 
)

Adds the location by another. Not world-aware.

See also
Vector
Parameters
xX coordinate
yY coordinate
zZ coordinate
Returns
the same location

Definition at line 335 of file Location.java.

335  {
336  this.x += x;
337  this.y += y;
338  this.z += z;
339  return this;
340  }
double org.bukkit.Location.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.

See also
Vector
Parameters
oThe other location
Returns
the distance
Exceptions
IllegalArgumentExceptionfor differing worlds

Definition at line 430 of file Location.java.

References org.bukkit.Location.distanceSquared().

430  {
431  return Math.sqrt(distanceSquared(o));
432  }
double distanceSquared(Location o)
Definition: Location.java:442
double org.bukkit.Location.distanceSquared ( Location  o)

Get the squared distance between this location and another.

See also
Vector
Parameters
oThe other location
Returns
the distance
Exceptions
IllegalArgumentExceptionfor differing worlds

Definition at line 442 of file Location.java.

References org.bukkit.World.getName(), and org.bukkit.Location.getWorld().

Referenced by org.bukkit.Location.distance().

442  {
443  if (o == null) {
444  throw new IllegalArgumentException("Cannot measure distance to a null location");
445  } else if (o.getWorld() == null || getWorld() == null) {
446  throw new IllegalArgumentException("Cannot measure distance to a null world");
447  } else if (o.getWorld() != getWorld()) {
448  throw new IllegalArgumentException("Cannot measure distance between " + getWorld().getName() + " and " + o.getWorld().getName());
449  }
450 
451  return NumberConversions.square(x - o.x) + NumberConversions.square(y - o.y) + NumberConversions.square(z - o.z);
452  }
String getName()
Block org.bukkit.Location.getBlock ( )

Gets the block at the represented location

Returns
Block at the represented location

Definition at line 81 of file Location.java.

References org.bukkit.World.getBlockAt().

81  {
82  return world.getBlockAt(this);
83  }
Block getBlockAt(int x, int y, int z)
int org.bukkit.Location.getBlockX ( )

Gets the floored value of the X component, indicating the block that this location is contained with.

Returns
block X

Definition at line 109 of file Location.java.

References org.bukkit.Location.locToBlock().

109  {
110  return locToBlock(x);
111  }
static int locToBlock(double loc)
Definition: Location.java:557
int org.bukkit.Location.getBlockY ( )

Gets the floored value of the Y component, indicating the block that this location is contained with.

Returns
block y

Definition at line 137 of file Location.java.

References org.bukkit.Location.locToBlock().

137  {
138  return locToBlock(y);
139  }
static int locToBlock(double loc)
Definition: Location.java:557
int org.bukkit.Location.getBlockZ ( )

Gets the floored value of the Z component, indicating the block that this location is contained with.

Returns
block z

Definition at line 165 of file Location.java.

References org.bukkit.Location.locToBlock().

165  {
166  return locToBlock(z);
167  }
static int locToBlock(double loc)
Definition: Location.java:557
Chunk org.bukkit.Location.getChunk ( )

Gets the chunk at the represented location

Returns
Chunk at the represented location

Definition at line 72 of file Location.java.

References org.bukkit.World.getChunkAt().

72  {
73  return world.getChunkAt(this);
74  }
Chunk getChunkAt(int x, int z)
Vector org.bukkit.Location.getDirection ( )

Gets a unit-vector pointing in the direction that this Location is facing.

Returns
a vector pointing the direction of this location's pitch and yaw

Definition at line 244 of file Location.java.

References org.bukkit.Location.getPitch(), org.bukkit.Location.getYaw(), org.bukkit.util.Vector.setX(), org.bukkit.util.Vector.setY(), and org.bukkit.util.Vector.setZ().

Referenced by org.bukkit.util.BlockIterator.BlockIterator().

244  {
245  Vector vector = new Vector();
246 
247  double rotX = this.getYaw();
248  double rotY = this.getPitch();
249 
250  vector.setY(-Math.sin(Math.toRadians(rotY)));
251 
252  double xz = Math.cos(Math.toRadians(rotY));
253 
254  vector.setX(-xz * Math.sin(Math.toRadians(rotX)));
255  vector.setZ(xz * Math.cos(Math.toRadians(rotX)));
256 
257  return vector;
258  }
float org.bukkit.Location.getPitch ( )

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.

    pitch values the equivalent of looking down.

    Returns
    the incline's pitch

Definition at line 233 of file Location.java.

Referenced by org.bukkit.Location.getDirection().

233  {
234  return pitch;
235  }
World org.bukkit.Location.getWorld ( )

Gets the world that this location resides in

Returns
World that contains this location

Definition at line 63 of file Location.java.

Referenced by org.bukkit.Location.add(), org.bukkit.util.BlockIterator.BlockIterator(), org.bukkit.Location.distanceSquared(), org.bukkit.event.player.PlayerRespawnEvent.setRespawnLocation(), and org.bukkit.Location.subtract().

63  {
64  return world;
65  }
double org.bukkit.Location.getX ( )

Gets the x-coordinate of this location

Returns
x-coordinate

Definition at line 99 of file Location.java.

99  {
100  return x;
101  }
double org.bukkit.Location.getY ( )

Gets the y-coordinate of this location

Returns
y-coordinate

Definition at line 127 of file Location.java.

127  {
128  return y;
129  }
float org.bukkit.Location.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.

Increasing yaw values are the equivalent of turning to your right-facing, increasing the scale of the next respective axis, and decreasing the scale of the previous axis.

Returns
the rotation's yaw

Definition at line 201 of file Location.java.

Referenced by org.bukkit.Location.getDirection().

201  {
202  return yaw;
203  }
double org.bukkit.Location.getZ ( )

Gets the z-coordinate of this location

Returns
z-coordinate

Definition at line 155 of file Location.java.

155  {
156  return z;
157  }
double org.bukkit.Location.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.

See also
Vector
Returns
the magnitude

Definition at line 403 of file Location.java.

403  {
404  return Math.sqrt(NumberConversions.square(x) + NumberConversions.square(y) + NumberConversions.square(z));
405  }
double org.bukkit.Location.lengthSquared ( )

Gets the magnitude of the location squared. Not world-aware and orientation independent.

See also
Vector
Returns
the magnitude

Definition at line 414 of file Location.java.

414  {
415  return NumberConversions.square(x) + NumberConversions.square(y) + NumberConversions.square(z);
416  }
static int org.bukkit.Location.locToBlock ( double  loc)
static

Safely converts a double (location coordinate) to an int (block coordinate)

Parameters
locPrecise coordinate
Returns
Block coordinate

Definition at line 557 of file Location.java.

Referenced by org.bukkit.Location.getBlockX(), org.bukkit.Location.getBlockY(), and org.bukkit.Location.getBlockZ().

557  {
558  return NumberConversions.floor(loc);
559  }
Location org.bukkit.Location.multiply ( double  m)

Performs scalar multiplication, multiplying all components with a scalar. Not world-aware.

Parameters
mThe factor
See also
Vector
Returns
the same location

Definition at line 462 of file Location.java.

462  {
463  x *= m;
464  y *= m;
465  z *= m;
466  return this;
467  }
Location org.bukkit.Location.setDirection ( Vector  vector)

Sets the yaw and pitch to point in the direction of the vector.

Definition at line 264 of file Location.java.

References org.bukkit.util.Vector.getX(), org.bukkit.util.Vector.getY(), and org.bukkit.util.Vector.getZ().

264  {
265  /*
266  * Sin = Opp / Hyp
267  * Cos = Adj / Hyp
268  * Tan = Opp / Adj
269  *
270  * x = -Opp
271  * z = Adj
272  */
273  final double _2PI = 2 * Math.PI;
274  final double x = vector.getX();
275  final double z = vector.getZ();
276 
277  if (x == 0 && z == 0) {
278  pitch = vector.getY() > 0 ? -90 : 90;
279  return this;
280  }
281 
282  double theta = Math.atan2(-x, z);
283  yaw = (float) Math.toDegrees((theta + _2PI) % _2PI);
284 
285  double x2 = NumberConversions.square(x);
286  double z2 = NumberConversions.square(z);
287  double xz = Math.sqrt(x2 + z2);
288  pitch = (float) Math.toDegrees(Math.atan(-vector.getY() / xz));
289 
290  return this;
291  }
void org.bukkit.Location.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.

    pitch values the equivalent of looking down.

    Parameters
    pitchnew incline's pitch

Definition at line 217 of file Location.java.

217  {
218  this.pitch = pitch;
219  }
void org.bukkit.Location.setWorld ( World  world)

Sets the world that this location resides in

Parameters
worldNew world that this location resides in

Definition at line 54 of file Location.java.

54  {
55  this.world = world;
56  }
void org.bukkit.Location.setX ( double  x)

Sets the x-coordinate of this location

Parameters
xX-coordinate

Definition at line 90 of file Location.java.

90  {
91  this.x = x;
92  }
void org.bukkit.Location.setY ( double  y)

Sets the y-coordinate of this location

Parameters
yy-coordinate

Definition at line 118 of file Location.java.

118  {
119  this.y = y;
120  }
void org.bukkit.Location.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.

Increasing yaw values are the equivalent of turning to your right-facing, increasing the scale of the next respective axis, and decreasing the scale of the previous axis.

Parameters
yawnew rotation's yaw

Definition at line 183 of file Location.java.

183  {
184  this.yaw = yaw;
185  }
void org.bukkit.Location.setZ ( double  z)

Sets the z-coordinate of this location

Parameters
zz-coordinate

Definition at line 146 of file Location.java.

146  {
147  this.z = z;
148  }
Location org.bukkit.Location.subtract ( Location  vec)

Subtracts the location by another.

See also
Vector
Parameters
vecThe other location
Returns
the same location
Exceptions
IllegalArgumentExceptionfor differing worlds

Definition at line 350 of file Location.java.

References org.bukkit.Location.getWorld().

350  {
351  if (vec == null || vec.getWorld() != getWorld()) {
352  throw new IllegalArgumentException("Cannot add Locations of differing worlds");
353  }
354 
355  x -= vec.x;
356  y -= vec.y;
357  z -= vec.z;
358  return this;
359  }
Location org.bukkit.Location.subtract ( Vector  vec)

Subtracts the location by a vector.

See also
Vector
Parameters
vecThe vector to use
Returns
the same location

Definition at line 368 of file Location.java.

References org.bukkit.util.Vector.getX(), org.bukkit.util.Vector.getY(), and org.bukkit.util.Vector.getZ().

368  {
369  this.x -= vec.getX();
370  this.y -= vec.getY();
371  this.z -= vec.getZ();
372  return this;
373  }
Location org.bukkit.Location.subtract ( double  x,
double  y,
double  z 
)

Subtracts the location by another. Not world-aware and orientation independent.

See also
Vector
Parameters
xX coordinate
yY coordinate
zZ coordinate
Returns
the same location

Definition at line 385 of file Location.java.

385  {
386  this.x -= x;
387  this.y -= y;
388  this.z -= z;
389  return this;
390  }
Vector org.bukkit.Location.toVector ( )

Constructs a new Vector based on this Location

Returns
New Vector containing the coordinates represented by this Location

Definition at line 537 of file Location.java.

Referenced by org.bukkit.util.BlockIterator.BlockIterator().

537  {
538  return new Vector(x, y, z);
539  }
Location org.bukkit.Location.zero ( )

Zero this location's components. Not world-aware.

See also
Vector
Returns
the same location

Definition at line 475 of file Location.java.

475  {
476  x = 0;
477  y = 0;
478  z = 0;
479  return this;
480  }

The documentation for this class was generated from the following file: