Record Class BlockPosition

java.lang.Object
java.lang.Record
wtf.choco.veinminer.util.BlockPosition
Record Components:
x - the x coordinate
y - the y coordinate
z - the z coordinate

public record BlockPosition(int x, int y, int z) extends Record
Represents a set of x, y, and z coordinates in a world.
  • Constructor Summary

    Constructors
    Constructor
    Description
    BlockPosition(int x, int y, int z)
    Creates an instance of a BlockPosition record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @NotNull BlockPosition
    at(int x, int y, int z)
    Get a BlockPosition at the given coordinates.
    double
    distance(int x, int y, int z)
    Get the distance between this block and the given set of coordinates.
    double
    distanceSquared(int x, int y, int z)
    Get the distance squared between this block and the given set of coordinates.
    final boolean
    Indicates whether some other object is "equal to" this one.
    @NotNull BlockPosition
    getRelative(@NotNull BlockFace face)
    Get a new BlockPosition relative to the given BlockFace.
    final int
    Returns a hash code value for this object.
    @NotNull BlockPosition
    offset(int dx, int dy, int dz)
    Get a new BlockPosition offset by the given values.
    long
    Pack this BlockPosition's coordinates into a primitive long.
    static long
    pack(int x, int y, int z)
    Packs the given coordinates into a primitive long.
    final String
    Returns a string representation of this record class.
    static @NotNull BlockPosition
    unpack(long packedPos)
    Unpack a BlockPosition from the given packed long.
    static int
    unpackX(long packedPos)
    Unpack an x coordinate from the given packed long.
    static int
    unpackY(long packedPos)
    Unpack a y coordinate from the given packed long.
    static int
    unpackZ(long packedPos)
    Unpack a z coordinate from the given packed long.
    int
    x()
    Returns the value of the x record component.
    int
    y()
    Returns the value of the y record component.
    int
    z()
    Returns the value of the z record component.

    Methods inherited from class java.lang.Object

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

    • BlockPosition

      public BlockPosition(int x, int y, int z)
      Creates an instance of a BlockPosition 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
  • Method Details

    • offset

      @NotNull public @NotNull BlockPosition offset(int dx, int dy, int dz)
      Get a new BlockPosition offset by the given values.
      Parameters:
      dx - the x offset
      dy - the y offset
      dz - the z offset
      Returns:
      the offset block position
    • getRelative

      @NotNull public @NotNull BlockPosition getRelative(@NotNull @NotNull BlockFace face)
      Get a new BlockPosition relative to the given BlockFace.
      Parameters:
      face - the direction in which to get the relative position
      Returns:
      the relative position
    • distanceSquared

      public double distanceSquared(int x, int y, int z)
      Get the distance squared between this block and the given set of coordinates.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      Returns:
      the distance squared in blocks
      See Also:
    • distance

      public double distance(int x, int y, int z)
      Get the distance between this block and the given set of coordinates.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      Returns:
      the distance in blocks
      See Also:
    • pack

      public long pack()
      Pack this BlockPosition's coordinates into a primitive long.
      Returns:
      the packed position
    • at

      @NotNull public static @NotNull BlockPosition at(int x, int y, int z)
      Get a BlockPosition at the given coordinates.

      Convenience method. Equivalent to invoking the constructor with the same arguments

      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      Returns:
      the created BlockPosition
    • unpack

      @NotNull public static @NotNull BlockPosition unpack(long packedPos)
      Unpack a BlockPosition from the given packed long.
      Parameters:
      packedPos - the packed long position
      Returns:
      the resulting BlockPosition
    • pack

      public static long pack(int x, int y, int z)
      Packs the given coordinates into a primitive long.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      Returns:
      the packed position
    • unpackX

      public static int unpackX(long packedPos)
      Unpack an x coordinate from the given packed long.
      Parameters:
      packedPos - the position as a long
      Returns:
      the unpacked x coordinate
    • unpackY

      public static int unpackY(long packedPos)
      Unpack a y coordinate from the given packed long.
      Parameters:
      packedPos - the position as a long
      Returns:
      the unpacked y coordinate
    • unpackZ

      public static int unpackZ(long packedPos)
      Unpack a z coordinate from the given packed long.
      Parameters:
      packedPos - the position as a long
      Returns:
      the unpacked z coordinate
    • 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 int x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

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

      public int z()
      Returns the value of the z record component.
      Returns:
      the value of the z record component