Record Class ScalableOffset

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

@NullMarked public record ScalableOffset(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.

A scalable offset is scaled based on the coordinate system of the world the offset is applied in. For example, a scalable offset of (800, 800) may subtract 800 blocks from the player's coordinates in the overworld and subtract 100 blocks in the nether.

Scalable offsets cannot be applied to coordinates directly. They must first be scaled to a FixedOffset with the context of a world's coordinate scale. See scaleDownAndRound(double).

  • Field Summary

    Fields inherited from interface com.jtprince.coordinateoffset.Offset

    ALIGN_DEFAULT_OVERWORLD, ZERO
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    <T> T
    apply(T location)
    Apply this offset to a location.
    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).
    scaleDownAndRound(double divisor)
    Scale the components of this offset down by the specified divisor, then round to the nearest configured offsetsAreMultiplesOfBlocks value, returning a FixedOffset.
    scaleDownBy(double divisor)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use scaleDownAndRound(double) instead to ensure offsets are always multiples of the configured offsetsAreMultiplesOfBlocks value.
    Scale the components of this offset to the coordinate scale of the specified world.
    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

    • ScalableOffset

      public ScalableOffset(int x, int z)
      Creates an instance of a ScalableOffset 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
    • 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.
    • negate

      public ScalableOffset 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
    • scaleDownAndRound

      public FixedOffset scaleDownAndRound(double divisor)
      Scale the components of this offset down by the specified divisor, then round to the nearest configured offsetsAreMultiplesOfBlocks value, returning a FixedOffset.
      Parameters:
      divisor - Amount by which to scale down the components of this offset.
      Returns:
      A new FixedOffset with scaled components.
    • scaleDownBy

      @Deprecated(forRemoval=true) public FixedOffset scaleDownBy(double divisor)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use scaleDownAndRound(double) instead to ensure offsets are always multiples of the configured offsetsAreMultiplesOfBlocks value.
      Scale the components of this offset down by the specified divisor, returning a FixedOffset.
      Parameters:
      divisor - Amount by which to scale the components of this offset.
      Returns:
      A new FixedOffset with scaled components.
    • scaleToWorld

      public FixedOffset scaleToWorld(OffsetWorld world)
      Scale the components of this offset to the coordinate scale of the specified world.
      Parameters:
      world - World to scale the offset to.
      Returns:
      A new FixedOffset with scaled components.
    • 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