Record Class FixedOffset

java.lang.Object
java.lang.Record
com.jtprince.coordinateoffset.FixedOffset
Record Components:
x - X offset value in blocks. Will be subtracted from the player's real X coordinate.
z - Z offset value in blocks. Will be subtracted from the player's real Z coordinate.
All Implemented Interfaces:
Offset

@NullMarked public record FixedOffset(int x, int z) extends Record implements Offset
Amount by which a player's clientside X and Z coordinates will appear shifted compared to their real position in a world.

Fixed offsets are absolute in any coordinate space. For example, a fixed offset of (800, 800) will always subtract 800 from the player's coordinates. This may break coordinate-based alignment between nether portals and make it possible to reverse-engineer offsets through clever use of nether portals.

A fixed offset is fully resolved and may be applied to coordinates directly.

  • Field Summary

    Fields inherited from interface com.jtprince.coordinateoffset.Offset

    ALIGN_DEFAULT_OVERWORLD, ZERO
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    <T> T
    apply(T location)
    Apply this offset to a location.
    int
     
    int
     
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    Check if both components of this offset are zero, resulting in no coordinate offset.
    Get a new Offset with the inverse components as this one (x -> -x, z -> -z).
    Returns a string representation of this record class.
    <T> T
    unapply(T location)
    Unapply this offset from a location.
    int
    x()
    Returns the value of the x 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

    • FixedOffset

      public FixedOffset(int x, int z)
      Creates an instance of a FixedOffset record class.
      Parameters:
      x - the value for the x record component
      z - the value for the z record component
  • Method Details

    • toString

      public 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
    • negate

      public FixedOffset negate()
      Description copied from interface: Offset
      Get a new Offset with the inverse components as this one (x -> -x, z -> -z).
      Specified by:
      negate in interface Offset
      Returns:
      A new Offset.
    • isZero

      public boolean isZero()
      Description copied from interface: Offset
      Check if both components of this offset are zero, resulting in no coordinate offset.
      Specified by:
      isZero in interface Offset
    • chunkX

      public int chunkX()
    • chunkZ

      public int chunkZ()
    • apply

      public <T> T apply(T location) throws ClassCastException
      Description copied from interface: Offset
      Apply this offset to a location.
      Specified by:
      apply in interface Offset
      Type Parameters:
      T - Either OffsetLocation or a platform-specific location object.
      Parameters:
      location - Location to apply the offset to. This may either be a OffsetLocation or a platform-specific location object, such as a Bukkit Location.
      Returns:
      A new Location object with the offset applied and all other data (including type) matching the original.
      Throws:
      ClassCastException - if the provided object is not of an acceptable type for the running platform.
    • unapply

      public <T> T unapply(T location) throws ClassCastException
      Description copied from interface: Offset
      Unapply this offset from a location.
      Specified by:
      unapply in interface Offset
      Type Parameters:
      T - Either OffsetLocation or a platform-specific location object.
      Parameters:
      location - Location to unapply the offset from. This may either be a OffsetLocation or a platform-specific location object, such as a Bukkit Location.
      Returns:
      A new Location object with the offset unapplied and all other data (including type) matching the original.
      Throws:
      ClassCastException - if the provided object is not of an acceptable type for the running platform.
    • 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
    • z

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