Package com.jtprince.coordinateoffset
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
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
ConstructorsConstructorDescriptionScalableOffset(int x, int z) Creates an instance of aScalableOffsetrecord class. -
Method Summary
Modifier and TypeMethodDescription<T> Tapply(T location) Apply this offset to a location.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisZero()Check if both components of this offset are zero, resulting in no coordinate offset.negate()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 configuredoffsetsAreMultiplesOfBlocksvalue, returning aFixedOffset.scaleDownBy(double divisor) Deprecated, for removal: This API element is subject to removal in a future version.scaleToWorld(OffsetWorld world) Scale the components of this offset to the coordinate scale of the specified world.toString()Returns a string representation of this record class.<T> Tunapply(T location) Unapply this offset from a location.intx()Returns the value of thexrecord component.intz()Returns the value of thezrecord component.
-
Constructor Details
-
Method Details
-
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. -
apply
Description copied from interface:OffsetApply this offset to a location.- Specified by:
applyin interfaceOffset- Type Parameters:
T- EitherOffsetLocationor a platform-specific location object.- Parameters:
location- Location to apply the offset to. This may either be aOffsetLocationor 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
Description copied from interface:OffsetUnapply this offset from a location.- Specified by:
unapplyin interfaceOffset- Type Parameters:
T- EitherOffsetLocationor a platform-specific location object.- Parameters:
location- Location to unapply the offset from. This may either be aOffsetLocationor 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
Description copied from interface:OffsetGet a new Offset with the inverse components as this one (x -> -x, z -> -z). -
isZero
public boolean isZero()Description copied from interface:OffsetCheck if both components of this offset are zero, resulting in no coordinate offset. -
scaleDownAndRound
Scale the components of this offset down by the specified divisor, then round to the nearest configuredoffsetsAreMultiplesOfBlocksvalue, returning aFixedOffset.- Parameters:
divisor- Amount by which to scale down the components of this offset.- Returns:
- A new
FixedOffsetwith scaled components.
-
scaleDownBy
Deprecated, for removal: This API element is subject to removal in a future version.UsescaleDownAndRound(double)instead to ensure offsets are always multiples of the configuredoffsetsAreMultiplesOfBlocksvalue.Scale the components of this offset down by the specified divisor, returning aFixedOffset.- Parameters:
divisor- Amount by which to scale the components of this offset.- Returns:
- A new
FixedOffsetwith scaled components.
-
scaleToWorld
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
FixedOffsetwith 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. -
equals
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 '=='. -
x
public int x()Returns the value of thexrecord component.- Returns:
- the value of the
xrecord component
-
z
public int z()Returns the value of thezrecord component.- Returns:
- the value of the
zrecord component
-
scaleDownAndRound(double)instead to ensure offsets are always multiples of the configuredoffsetsAreMultiplesOfBlocksvalue.