Record Class Location

java.lang.Object
java.lang.Record
fr.fidorial.world.Location
Record Components:
x - the X coordinate
y - the Y coordinate, at the feet for an entity
z - the Z coordinate
yaw - the horizontal rotation in degrees, 0 facing south and growing clockwise
pitch - the vertical rotation in degrees, -90 looking straight up and 90 straight down

public record Location(double x, double y, double z, float yaw, float pitch) extends Record
A precise position and orientation, independent of any world.
Since:
0.1.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Location(double x, double y, double z, float yaw, float pitch)
    Creates an instance of a Location record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the position of the block holding this location.
    Returns the position of the chunk holding this location.
    double
    Computes the distance to another location, ignoring orientation.
    double
    Computes the squared distance to another location, ignoring orientation.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    static Location
    of(double x, double y, double z)
    Returns a location at the given coordinates, facing south.
    float
    Returns the value of the pitch record component.
    final String
    Returns a string representation of this record class.
    withPosition(double x, double y, double z)
    Returns this location moved to other coordinates, keeping its orientation.
    withRotation(float yaw, float pitch)
    Returns this location with another orientation, keeping its coordinates.
    double
    x()
    Returns the value of the x record component.
    double
    y()
    Returns the value of the y record component.
    float
    yaw()
    Returns the value of the yaw record component.
    double
    z()
    Returns the value of the z record component.

    Methods inherited from class Object

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

    • Location

      public Location(double x, double y, double z, float yaw, float pitch)
      Creates an instance of a Location record class.
      Parameters:
      x - the value for the x record component
      y - the value for the y record component
      z - the value for the z record component
      yaw - the value for the yaw record component
      pitch - the value for the pitch record component
  • Method Details

    • of

      public static Location of(double x, double y, double z)
      Returns a location at the given coordinates, facing south.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      z - the Z coordinate
      Returns:
      a location at the given coordinates, facing south
      Since:
      0.1.0
    • chunk

      public ChunkPos chunk()
      Returns the position of the chunk holding this location.
      Returns:
      the position of the chunk holding this location
      Since:
      0.1.0
    • blockPos

      public BlockPos blockPos()
      Returns the position of the block holding this location.
      Returns:
      the position of the block holding this location
      Since:
      0.1.0
    • withPosition

      public Location withPosition(double x, double y, double z)
      Returns this location moved to other coordinates, keeping its orientation.
      Parameters:
      x - the new X coordinate
      y - the new Y coordinate
      z - the new Z coordinate
      Returns:
      this location moved to other coordinates, keeping its orientation
      Since:
      0.1.0
    • withRotation

      public Location withRotation(float yaw, float pitch)
      Returns this location with another orientation, keeping its coordinates.
      Parameters:
      yaw - the new horizontal rotation in degrees
      pitch - the new vertical rotation in degrees
      Returns:
      this location with another orientation, keeping its coordinates
      Since:
      0.1.0
    • distanceSquared

      public double distanceSquared(Location other)
      Computes the squared distance to another location, ignoring orientation.

      Cheaper than distance(Location); prefer it to compare distances.

      Parameters:
      other - the other location
      Returns:
      the squared distance in blocks
      Since:
      0.1.0
    • distance

      public double distance(Location other)
      Computes the distance to another location, ignoring orientation.
      Parameters:
      other - the other location
      Returns:
      the distance in blocks
      Since:
      0.1.0
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • x

      public double x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

      public double y()
      Returns the value of the y record component.
      Returns:
      the value of the y record component
    • z

      public double z()
      Returns the value of the z record component.
      Returns:
      the value of the z record component
    • yaw

      public float yaw()
      Returns the value of the yaw record component.
      Returns:
      the value of the yaw record component
    • pitch

      public float pitch()
      Returns the value of the pitch record component.
      Returns:
      the value of the pitch record component