Record Class Pos

java.lang.Object
java.lang.Record
net.minestom.server.coordinate.Pos
All Implemented Interfaces:
Point

public record Pos(double x, double y, double z, float yaw, float pitch) extends Record implements Point
Represents a position containing coordinates and a view.

To become a value then primitive type.

  • Field Details

    • ZERO

      public static final Pos ZERO
  • Constructor Details

    • Pos

      public Pos(double x, double y, double z, float yaw, float pitch)
      Creates an instance of a Pos 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
    • Pos

      public Pos(double x, double y, double z)
    • Pos

      public Pos(Point point, float yaw, float pitch)
    • Pos

      public Pos(Point point)
  • Method Details

    • fromPoint

      @Deprecated public static Pos fromPoint(Point point)
      Deprecated.
      use Point.asPos() instead
      Converts a Point into a Pos. Will cast if possible, or instantiate a new object.
      Parameters:
      point - the point to convert
      Returns:
      the converted position
    • withCoord

      @Contract(pure=true) public Pos withCoord(double x, double y, double z)
      Changes the 3 coordinates of this position.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      z - the Z coordinate
      Returns:
      a new position
    • withCoord

      @Contract(pure=true) public Pos withCoord(Point point)
    • withView

      @Contract(pure=true) public Pos withView(float yaw, float pitch)
    • withView

      @Contract(pure=true) public Pos withView(Pos pos)
    • withDirection

      @Contract(pure=true) public Pos withDirection(Point point)
      Sets the yaw and pitch to point in the direction of the point.
    • withYaw

      @Contract(pure=true) public Pos withYaw(float yaw)
    • withYaw

      @Contract(pure=true) public Pos withYaw(DoubleUnaryOperator operator)
    • withPitch

      @Contract(pure=true) public Pos withPitch(float pitch)
    • withLookAt

      @Contract(pure=true) public Pos withLookAt(Point point)
    • withPitch

      @Contract(pure=true) public Pos withPitch(DoubleUnaryOperator operator)
    • sameView

      public boolean sameView(Pos position)
      Checks if two positions have a similar view (yaw/pitch).
      Parameters:
      position - the position to compare
      Returns:
      true if the two positions have the same view
    • sameView

      public boolean sameView(float yaw, float pitch)
    • direction

      public Vec direction()
      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
    • facing

      public Direction facing()
      Returns:
      The closest direction yaw and pitch are facing to.
    • apply

      @Contract(pure=true) public Pos apply(Pos.Operator operator)
      Returns a new position based on this position fields.
      Parameters:
      operator - the operator deconstructing this object and providing a new position
      Returns:
      the new position
    • withX

      @Contract(pure=true) public Pos withX(DoubleUnaryOperator operator)
      Description copied from interface: Point
      Creates a point with a modified X coordinate based on its value.
      Specified by:
      withX in interface Point
      Parameters:
      operator - the operator providing the current X coordinate and returning the new
      Returns:
      a new point
    • withX

      @Contract(pure=true) public Pos withX(double x)
      Description copied from interface: Point
      Creates a point with the specified X coordinate.
      Specified by:
      withX in interface Point
      Parameters:
      x - the new X coordinate
      Returns:
      a new point
    • withY

      @Contract(pure=true) public Pos withY(DoubleUnaryOperator operator)
      Description copied from interface: Point
      Creates a point with a modified Y coordinate based on its value.
      Specified by:
      withY in interface Point
      Parameters:
      operator - the operator providing the current Y coordinate and returning the new
      Returns:
      a new point
    • withY

      @Contract(pure=true) public Pos withY(double y)
      Description copied from interface: Point
      Creates a point with the specified Y coordinate.
      Specified by:
      withY in interface Point
      Parameters:
      y - the new Y coordinate
      Returns:
      a new point
    • withZ

      @Contract(pure=true) public Pos withZ(DoubleUnaryOperator operator)
      Description copied from interface: Point
      Creates a point with a modified Z coordinate based on its value.
      Specified by:
      withZ in interface Point
      Parameters:
      operator - the operator providing the current Z coordinate and returning the new
      Returns:
      a new point
    • withZ

      @Contract(pure=true) public Pos withZ(double z)
      Description copied from interface: Point
      Creates a point with the specified Z coordinate.
      Specified by:
      withZ in interface Point
      Parameters:
      z - the new Z coordinate
      Returns:
      a new point
    • add

      public Pos add(double x, double y, double z)
      Specified by:
      add in interface Point
    • add

      public Pos add(Point point)
      Specified by:
      add in interface Point
    • add

      public Pos add(double value)
      Specified by:
      add in interface Point
    • sub

      public Pos sub(double x, double y, double z)
      Specified by:
      sub in interface Point
    • sub

      public Pos sub(Point point)
      Specified by:
      sub in interface Point
    • sub

      public Pos sub(double value)
      Specified by:
      sub in interface Point
    • mul

      public Pos mul(double x, double y, double z)
      Specified by:
      mul in interface Point
    • mul

      public Pos mul(Point point)
      Specified by:
      mul in interface Point
    • mul

      public Pos mul(double value)
      Specified by:
      mul in interface Point
    • div

      public Pos div(double x, double y, double z)
      Specified by:
      div in interface Point
    • div

      public Pos div(Point point)
      Specified by:
      div in interface Point
    • div

      public Pos div(double value)
      Specified by:
      div in interface Point
    • relative

      public Pos relative(BlockFace face)
      Specified by:
      relative in interface Point
    • 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 '=='.
      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.
      Specified by:
      x in interface Point
      Returns:
      the value of the x record component
    • y

      public double y()
      Returns the value of the y record component.
      Specified by:
      y in interface Point
      Returns:
      the value of the y record component
    • z

      public double z()
      Returns the value of the z record component.
      Specified by:
      z in interface Point
      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