Package dev.twilite.game.common
Record Class Coord
java.lang.Object
java.lang.Record
dev.twilite.game.common.Coord
Absolute world tile coordinate.
Coordinates are represented as world x/y plus a floor. Use Coord.Map
for coordinates relative to a loaded World, and Coord.Fine for
sub-tile/fine positions used by models and projection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordFine-grained coordinate, where one tile is 128 fine units.static final recordCoordinate relative to the loaded world's origin. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionarea()Returns this coordinate as a one-tile area.directPathTo(Coord coord) Returns the direct greedy/dumb walk path from this coordinate to another coordinate in the currently loaded world.directPathTo(Rect rect) Returns the direct greedy/dumb walk path from this coordinate to an area in the currently loaded world.directPathTo(Unit unit) Returns the direct greedy/dumb walk path from this coordinate to a unit in the currently loaded world.intdistanceTo(Coord coord) Returns Chebyshev tile distance to another coordinate.intdistanceTo(Rect rect) Returns Chebyshev tile distance to an area.intdistanceTo(Unit unit) Returns Chebyshev tile distance to a unit's occupied area.dx(int x) Returns a coordinate offset on the x axis.dy(int y) Returns a coordinate offset on the y axis.booleanIndicates whether some other object is "equal to" this one.fine()Converts this tile coordinate to the fine coordinate at the tile origin.static Coord.Finefine(int x, int y, int floor) Creates a fine coordinate.intfloor()Returns the value of thefloorrecord component.static CoordfromFine(World world, Coord.Fine fine) Converts a fine coordinate into an absolute world coordinate.static CoordConverts a map-local coordinate into an absolute world coordinate.static CoordfromPacked(int packed) Decodes a packed RuneScape coordinate.static CoordfromRegion(int regionId, int regionX, int regionY, int floor) Creates an absolute world tile coordinate from a region id and region-local x/y offsets.inthashCode()Returns a hash code value for this object.booleanReturns whether this coordinate is in an instancebooleanlineOfSightTo(Coord coord) Returns whether line of sight is clear from this coordinate to another coordinate in the currently loaded world.booleanlineOfSightTo(Rect rect) Returns whether line of sight is clear from this coordinate to an area in the currently loaded world.booleanlineOfSightTo(Unit unit) Returns whether line of sight is clear from this coordinate to a unit in the currently loaded world.booleanlineOfWalkTo(Coord coord) Returns whether a direct line of walk is clear from this coordinate to another coordinate in the currently loaded world.booleanlineOfWalkTo(Rect rect) Returns whether a direct line of walk is clear from this coordinate to an area in the currently loaded world.booleanlineOfWalkTo(Unit unit) Returns whether a direct line of walk is clear from this coordinate to a unit in the currently loaded world.intmanhattanDistanceTo(Coord coord) Returns Manhattan/taxicab tile distance to another coordinate.intmanhattanDistanceTo(Rect rect) Returns Manhattan/taxicab tile distance to an area.intmanhattanDistanceTo(Unit unit) Returns Manhattan/taxicab tile distance to a unit's occupied area.static Coord.Mapmap(int x, int y, int floor) Creates a map-local coordinate.Converts this absolute coordinate into a coordinate relative toworld.neighbors(boolean cardinal) Returns neighboring coordinates on the same floor.intpack()Packs this coordinate into the game's compact coordinate format.static intpack(int x, int y, int floor) Packs coordinate components into the game's compact coordinate format.booleanpathInDirection(int x, int y) Returns whether this coordinate has an open one-tile path in the supplied direction in the currently loaded world.intregionId()Returns the packed region id containing this coordinate.intregionX()Returns this coordinate's x offset within its containing region.intregionY()Returns this coordinate's y offset within its containing region.Converts this template coordinate to its matching loaded instance coordinate.final StringtoString()Returns a string representation of this record class.Converts this loaded instance coordinate to its source template coordinate.translate(int x, int y) Returns a coordinate offset by the supplied x/y deltas.intx()Returns the value of thexrecord component.inty()Returns the value of theyrecord component.
-
Field Details
-
REGION_SIZE
public static final int REGION_SIZE- See Also:
-
-
Constructor Details
-
Coord
public Coord(int x, int y) Creates an absolute world tile coordinate on floor0. -
Coord
public Coord(int x, int y, int floor) Creates an instance of aCoordrecord class.- Parameters:
x- the value for thexrecord componenty- the value for theyrecord componentfloor- the value for thefloorrecord component
-
-
Method Details
-
fromPacked
Decodes a packed RuneScape coordinate. -
fromRegion
Creates an absolute world tile coordinate from a region id and region-local x/y offsets. -
fine
Creates a fine coordinate. -
map
Creates a map-local coordinate. -
fromFine
Converts a fine coordinate into an absolute world coordinate. -
fromMap
Converts a map-local coordinate into an absolute world coordinate. -
pack
public static int pack(int x, int y, int floor) Packs coordinate components into the game's compact coordinate format. -
fine
Converts this tile coordinate to the fine coordinate at the tile origin. -
map
Converts this absolute coordinate into a coordinate relative toworld. -
translate
Returns a coordinate offset by the supplied x/y deltas. -
dx
Returns a coordinate offset on the x axis. -
dy
Returns a coordinate offset on the y axis. -
neighbors
Returns neighboring coordinates on the same floor.- Parameters:
cardinal- whether to return only cardinal neighbors
-
distanceTo
Returns Chebyshev tile distance to another coordinate. -
distanceTo
Returns Chebyshev tile distance to an area. -
distanceTo
Returns Chebyshev tile distance to a unit's occupied area. -
manhattanDistanceTo
Returns Manhattan/taxicab tile distance to another coordinate. -
manhattanDistanceTo
Returns Manhattan/taxicab tile distance to an area. -
manhattanDistanceTo
Returns Manhattan/taxicab tile distance to a unit's occupied area. -
lineOfSightTo
Returns whether line of sight is clear from this coordinate to another coordinate in the currently loaded world. -
lineOfSightTo
Returns whether line of sight is clear from this coordinate to an area in the currently loaded world. -
lineOfSightTo
Returns whether line of sight is clear from this coordinate to a unit in the currently loaded world. -
lineOfWalkTo
Returns whether a direct line of walk is clear from this coordinate to another coordinate in the currently loaded world. -
lineOfWalkTo
Returns whether a direct line of walk is clear from this coordinate to an area in the currently loaded world. -
lineOfWalkTo
Returns whether a direct line of walk is clear from this coordinate to a unit in the currently loaded world. -
directPathTo
Returns the direct greedy/dumb walk path from this coordinate to another coordinate in the currently loaded world.This is not full pathfinding. It only steps directly toward the target and returns any partial path before blocking.
-
directPathTo
Returns the direct greedy/dumb walk path from this coordinate to an area in the currently loaded world.This is not full pathfinding. It only steps directly toward the target and returns any partial path before blocking.
-
directPathTo
Returns the direct greedy/dumb walk path from this coordinate to a unit in the currently loaded world.This is not full pathfinding. It only steps directly toward the target and returns any partial path before blocking.
-
pathInDirection
public boolean pathInDirection(int x, int y) Returns whether this coordinate has an open one-tile path in the supplied direction in the currently loaded world. -
toTemplate
Converts this loaded instance coordinate to its source template coordinate. Returns this coordinate when it is not in an instance or no template mapping is available. -
toInstance
Converts this template coordinate to its matching loaded instance coordinate. Returns this coordinate when it is already in an instance or no instance mapping is available. -
area
Returns this coordinate as a one-tile area. -
pack
public int pack()Packs this coordinate into the game's compact coordinate format. -
regionId
public int regionId()Returns the packed region id containing this coordinate. -
regionX
public int regionX()Returns this coordinate's x offset within its containing region. -
regionY
public int regionY()Returns this coordinate's y offset within its containing region. -
instanced
public boolean instanced()Returns whether this coordinate is in an instance -
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 '=='. -
hashCode
public int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
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. -
x
public int x()Returns the value of thexrecord component.- Returns:
- the value of the
xrecord component
-
y
public int y()Returns the value of theyrecord component.- Returns:
- the value of the
yrecord component
-
floor
public int floor()Returns the value of thefloorrecord component.- Returns:
- the value of the
floorrecord component
-