Record Class RelativeVec

java.lang.Object
java.lang.Record
net.minestom.server.utils.location.RelativeVec

public record RelativeVec(@NotNull Vec vec, @NotNull RelativeVec.CoordinateType coordinateType, boolean relativeX, boolean relativeY, boolean relativeZ) extends Record
Represents a location which can have fields relative to an Entity position.

Useful for parsing Vec2 or Vec3 types

  • Constructor Details

    • RelativeVec

      public RelativeVec(@NotNull @NotNull Vec vec, @NotNull @NotNull RelativeVec.CoordinateType coordinateType, boolean relativeX, boolean relativeY, boolean relativeZ)
      Creates an instance of a RelativeVec record class.
      Parameters:
      vec - the value for the vec record component
      coordinateType - the value for the coordinateType record component
      relativeX - the value for the relativeX record component
      relativeY - the value for the relativeY record component
      relativeZ - the value for the relativeZ record component
  • Method Details

    • from

      @NotNull public @NotNull Vec from(@Nullable @Nullable Pos origin)
      Gets the location based on the relative fields and vec().
      Parameters:
      origin - the origin position, null if none
      Returns:
      the location
    • from

      @NotNull public @NotNull Vec from(@Nullable @Nullable Entity entity)
      Gets the location based on the relative fields.
      Parameters:
      entity - the entity to get the relative position from
      Returns:
      the location
    • fromSender

      @NotNull public @NotNull Vec fromSender(@Nullable @Nullable CommandSender sender)
      Shorthand for from(Pos) If player uses their position otherwise, Vec.ZERO
      Parameters:
      sender - entity
      Returns:
      the position with any relativity
    • fromView

      public Vec fromView(@Nullable @Nullable Pos point)
      Computes a view Vec based on the given point's yaw and pitch. If no point is null, a default position Pos.ZERO is used.
      Parameters:
      point - The reference position used for computing relative coordinates. If null Pos.ZERO
      Returns:
      A Vec with XZ based on the provided position. Y is ignored.
    • fromView

      @NotNull public @NotNull Vec fromView(@Nullable @Nullable Entity entity)
      Shorthand for fromView(Pos)
      Parameters:
      entity - to get the position from, otherwise Pos.ZERO
      Returns:
      the view.
    • isRelativeX

      public boolean isRelativeX()
      Gets if the 'x' field is relative.
      Returns:
      true if the 'x' field is relative
    • isRelativeY

      public boolean isRelativeY()
      Gets if the 'y' field is relative.
      Returns:
      true if the 'y' field is relative
    • isRelativeZ

      public boolean isRelativeZ()
      Gets if the 'z' field is relative.
      Returns:
      true if the 'z' field is relative
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components 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.
    • vec

      @NotNull public @NotNull Vec vec()
      Returns the value of the vec record component.
      Returns:
      the value of the vec record component
    • coordinateType

      @NotNull public @NotNull RelativeVec.CoordinateType coordinateType()
      Returns the value of the coordinateType record component.
      Returns:
      the value of the coordinateType record component
    • relativeX

      public boolean relativeX()
      Returns the value of the relativeX record component.
      Returns:
      the value of the relativeX record component
    • relativeY

      public boolean relativeY()
      Returns the value of the relativeY record component.
      Returns:
      the value of the relativeY record component
    • relativeZ

      public boolean relativeZ()
      Returns the value of the relativeZ record component.
      Returns:
      the value of the relativeZ record component