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(@NotNull @NotNull Point point, float yaw, float pitch)
    • Pos

      public Pos(@NotNull @NotNull Point point)
  • Method Details

    • fromPoint

      @NotNull public static @NotNull Pos fromPoint(@NotNull @NotNull Point point)
      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) @NotNull public @NotNull 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) @NotNull public @NotNull Pos withCoord(@NotNull @NotNull Point point)
    • withView

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

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

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

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

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

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

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

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

      public boolean sameView(@NotNull @NotNull 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

      @NotNull public @NotNull 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
    • apply

      @Contract(pure=true) @NotNull public @NotNull Pos apply(@NotNull @NotNull 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) @NotNull public @NotNull Pos withX(@NotNull @NotNull 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) @NotNull public @NotNull 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) @NotNull public @NotNull Pos withY(@NotNull @NotNull 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) @NotNull public @NotNull 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) @NotNull public @NotNull Pos withZ(@NotNull @NotNull 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) @NotNull public @NotNull 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

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

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

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

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

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

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

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

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

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

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

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

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

      @NotNull public @NotNull Pos relative(@NotNull @NotNull BlockFace face)
      Specified by:
      relative in interface Point
    • asVec

      @Contract(pure=true) @NotNull public @NotNull Vec asVec()
    • 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