Class Location

java.lang.Object
dev.polv.taleapi.world.Location

public final class Location extends Object
Represents a position in the world with coordinates and optional rotation.

Locations are immutable. All modification methods return a new Location instance.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Location(double x, double y, double z)
    Creates a new location with the specified coordinates and no rotation.
    Location(double x, double y, double z, float yaw, float pitch)
    Creates a new location with the specified coordinates and rotation.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(double dx, double dy, double dz)
    Creates a new location by adding the given offsets.
    double
    Calculates the distance between this location and another.
    double
    Calculates the squared distance between this location and another.
    boolean
     
    int
     
    float
     
     
    withRotation(float yaw, float pitch)
    Creates a new location with modified rotation.
    withX(double x)
    Creates a new location with modified x coordinate.
    withY(double y)
    Creates a new location with modified y coordinate.
    withZ(double z)
    Creates a new location with modified z coordinate.
    double
    x()
     
    double
    y()
     
    float
    yaw()
     
    double
    z()
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Location

      public Location(double x, double y, double z)
      Creates a new location with the specified coordinates and no rotation.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
    • Location

      public Location(double x, double y, double z, float yaw, float pitch)
      Creates a new location with the specified coordinates and rotation.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      yaw - the yaw rotation (horizontal, 0-360)
      pitch - the pitch rotation (vertical, -90 to 90)
  • Method Details

    • x

      public double x()
      Returns:
      the x coordinate
    • y

      public double y()
      Returns:
      the y coordinate
    • z

      public double z()
      Returns:
      the z coordinate
    • yaw

      public float yaw()
      Returns:
      the yaw rotation (horizontal angle)
    • pitch

      public float pitch()
      Returns:
      the pitch rotation (vertical angle)
    • withX

      public Location withX(double x)
      Creates a new location with modified x coordinate.
      Parameters:
      x - the new x coordinate
      Returns:
      a new Location with the modified value
    • withY

      public Location withY(double y)
      Creates a new location with modified y coordinate.
      Parameters:
      y - the new y coordinate
      Returns:
      a new Location with the modified value
    • withZ

      public Location withZ(double z)
      Creates a new location with modified z coordinate.
      Parameters:
      z - the new z coordinate
      Returns:
      a new Location with the modified value
    • withRotation

      public Location withRotation(float yaw, float pitch)
      Creates a new location with modified rotation.
      Parameters:
      yaw - the new yaw rotation
      pitch - the new pitch rotation
      Returns:
      a new Location with the modified values
    • add

      public Location add(double dx, double dy, double dz)
      Creates a new location by adding the given offsets.
      Parameters:
      dx - the x offset
      dy - the y offset
      dz - the z offset
      Returns:
      a new Location with the offsets applied
    • distance

      public double distance(Location other)
      Calculates the distance between this location and another.
      Parameters:
      other - the other location
      Returns:
      the distance between the two locations
    • distanceSquared

      public double distanceSquared(Location other)
      Calculates the squared distance between this location and another.

      This is faster than distance(Location) as it avoids the square root. Useful for distance comparisons.

      Parameters:
      other - the other location
      Returns:
      the squared distance between the two locations
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object