Record Class Coord

java.lang.Object
java.lang.Record
dev.twilite.game.common.Coord

public record Coord(int x, int y, int floor) extends Record
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 Classes
    Modifier and Type
    Class
    Description
    static final record 
    Fine-grained coordinate, where one tile is 128 fine units.
    static final record 
    Coordinate relative to the loaded world's origin.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Coord(int x, int y)
    Creates an absolute world tile coordinate on floor 0.
    Coord(int x, int y, int floor)
    Creates an instance of a Coord record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns this coordinate as a one-tile area.
    Returns the direct greedy/dumb walk path from this coordinate to another coordinate in the currently loaded world.
    Returns the direct greedy/dumb walk path from this coordinate to an area in the currently loaded world.
    Returns the direct greedy/dumb walk path from this coordinate to a unit in the currently loaded world.
    int
    Returns Chebyshev tile distance to another coordinate.
    int
    Returns Chebyshev tile distance to an area.
    int
    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.
    boolean
    equals(Object other)
    Indicates whether some other object is "equal to" this one.
    Converts this tile coordinate to the fine coordinate at the tile origin.
    static Coord.Fine
    fine(int x, int y, int floor)
    Creates a fine coordinate.
    int
    Returns the value of the floor record component.
    static Coord
    fromFine(World world, Coord.Fine fine)
    Converts a fine coordinate into an absolute world coordinate.
    static Coord
    fromMap(World world, Coord.Map map)
    Converts a map-local coordinate into an absolute world coordinate.
    static Coord
    fromPacked(int packed)
    Decodes a packed RuneScape coordinate.
    static Coord
    fromRegion(int regionId, int regionX, int regionY, int floor)
    Creates an absolute world tile coordinate from a region id and region-local x/y offsets.
    int
    Returns a hash code value for this object.
    boolean
    Returns whether this coordinate is in an instance
    boolean
    Returns whether line of sight is clear from this coordinate to another coordinate in the currently loaded world.
    boolean
    Returns whether line of sight is clear from this coordinate to an area in the currently loaded world.
    boolean
    Returns whether line of sight is clear from this coordinate to a unit in the currently loaded world.
    boolean
    Returns whether a direct line of walk is clear from this coordinate to another coordinate in the currently loaded world.
    boolean
    Returns whether a direct line of walk is clear from this coordinate to an area in the currently loaded world.
    boolean
    Returns whether a direct line of walk is clear from this coordinate to a unit in the currently loaded world.
    int
    Returns Manhattan/taxicab tile distance to another coordinate.
    int
    Returns Manhattan/taxicab tile distance to an area.
    int
    Returns Manhattan/taxicab tile distance to a unit's occupied area.
    static Coord.Map
    map(int x, int y, int floor)
    Creates a map-local coordinate.
    map(World world)
    Converts this absolute coordinate into a coordinate relative to world.
    neighbors(boolean cardinal)
    Returns neighboring coordinates on the same floor.
    int
    Packs this coordinate into the game's compact coordinate format.
    static int
    pack(int x, int y, int floor)
    Packs coordinate components into the game's compact coordinate format.
    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.
    int
    Returns the packed region id containing this coordinate.
    int
    Returns this coordinate's x offset within its containing region.
    int
    Returns this coordinate's y offset within its containing region.
    Converts this template coordinate to its matching loaded instance coordinate.
    final String
    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.
    int
    x()
    Returns the value of the x record component.
    int
    y()
    Returns the value of the y record component.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Coord

      public Coord(int x, int y)
      Creates an absolute world tile coordinate on floor 0.
    • Coord

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

    • fromPacked

      public static Coord fromPacked(int packed)
      Decodes a packed RuneScape coordinate.
    • fromRegion

      public static Coord fromRegion(int regionId, int regionX, int regionY, int floor)
      Creates an absolute world tile coordinate from a region id and region-local x/y offsets.
    • fine

      public static Coord.Fine fine(int x, int y, int floor)
      Creates a fine coordinate.
    • map

      public static Coord.Map map(int x, int y, int floor)
      Creates a map-local coordinate.
    • fromFine

      public static Coord fromFine(World world, Coord.Fine fine)
      Converts a fine coordinate into an absolute world coordinate.
    • fromMap

      public static Coord fromMap(World world, Coord.Map map)
      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

      public Coord.Fine fine()
      Converts this tile coordinate to the fine coordinate at the tile origin.
    • map

      public Coord.Map map(World world)
      Converts this absolute coordinate into a coordinate relative to world.
    • translate

      public Coord translate(int x, int y)
      Returns a coordinate offset by the supplied x/y deltas.
    • dx

      public Coord dx(int x)
      Returns a coordinate offset on the x axis.
    • dy

      public Coord dy(int y)
      Returns a coordinate offset on the y axis.
    • neighbors

      public List<Coord> neighbors(boolean cardinal)
      Returns neighboring coordinates on the same floor.
      Parameters:
      cardinal - whether to return only cardinal neighbors
    • distanceTo

      public int distanceTo(Coord coord)
      Returns Chebyshev tile distance to another coordinate.
    • distanceTo

      public int distanceTo(Rect rect)
      Returns Chebyshev tile distance to an area.
    • distanceTo

      public int distanceTo(Unit unit)
      Returns Chebyshev tile distance to a unit's occupied area.
    • manhattanDistanceTo

      public int manhattanDistanceTo(Coord coord)
      Returns Manhattan/taxicab tile distance to another coordinate.
    • manhattanDistanceTo

      public int manhattanDistanceTo(Rect rect)
      Returns Manhattan/taxicab tile distance to an area.
    • manhattanDistanceTo

      public int manhattanDistanceTo(Unit unit)
      Returns Manhattan/taxicab tile distance to a unit's occupied area.
    • lineOfSightTo

      public boolean lineOfSightTo(Coord coord)
      Returns whether line of sight is clear from this coordinate to another coordinate in the currently loaded world.
    • lineOfSightTo

      public boolean lineOfSightTo(Rect rect)
      Returns whether line of sight is clear from this coordinate to an area in the currently loaded world.
    • lineOfSightTo

      public boolean lineOfSightTo(Unit unit)
      Returns whether line of sight is clear from this coordinate to a unit in the currently loaded world.
    • lineOfWalkTo

      public boolean lineOfWalkTo(Coord coord)
      Returns whether a direct line of walk is clear from this coordinate to another coordinate in the currently loaded world.
    • lineOfWalkTo

      public boolean lineOfWalkTo(Rect rect)
      Returns whether a direct line of walk is clear from this coordinate to an area in the currently loaded world.
    • lineOfWalkTo

      public boolean lineOfWalkTo(Unit unit)
      Returns whether a direct line of walk is clear from this coordinate to a unit in the currently loaded world.
    • directPathTo

      public List<Coord> directPathTo(Coord coord)
      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

      public List<Coord> directPathTo(Rect rect)
      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

      public List<Coord> directPathTo(Unit unit)
      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

      public Coord 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

      public Coord 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

      public Rect 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

      public boolean equals(Object other)
      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:
      other - the object with which to compare
      Returns:
      true if this object is the same as the other argument; false otherwise.
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • 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
    • 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
    • floor

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