Class Coord

  • All Implemented Interfaces:
    SceneNode

    public class Coord
    extends Object
    implements SceneNode
    Represents a world coordinate on the game map. Also referred to as Tile, or Position which Coord is here to replace.
    • Field Detail

      • NIL

        public static final Coord NIL
    • Method Detail

      • from

        public static Coord from​(int x,
                                 int y,
                                 int floorLevel,
                                 float subX,
                                 float subY)
      • from

        public static Coord from​(int x,
                                 int y,
                                 int floorLevel)
        Creates a new Coord from world-space X/Y coordinates and a floor level.

        This is the primary factory method for constructing world coordinates.

        Parameters:
        x - the world X coordinate
        y - the world Y coordinate
        floorLevel - the floor/plane (typically 0–3)
        Returns:
        a new Coord representing the given world position
      • from

        public static Coord from​(int x,
                                 int y)
        Creates a new Coord at the specified world X/Y coordinates on floor level 0.

        This is a convenience overload for situations where the floor is implicitly ground level.

        Parameters:
        x - the world X coordinate
        y - the world Y coordinate
        Returns:
        a new Coord at the given world position on floor 0
      • fromGrid

        public static Coord fromGrid​(RSWorldMatrix matrix,
                                     CoordGrid grid)
        Converts a CoordGrid (matrix-local tile coordinate) into a world-space Coord using the given RSWorldMatrix.

        In the engine, a CoordGrid stores coordinates relative to the originating matrix/scene. To convert these to absolute world coordinates, the matrix base is applied:

         worldX = grid.x + matrix.getBaseX()
         worldY = grid.y + matrix.getBaseY()
         

        The floor level is preserved.

        Parameters:
        matrix - the world matrix providing base coordinate offsets; must not be null
        grid - the matrix-local tile coordinate to convert
        Returns:
        the corresponding world-space Coord
      • fromGrid

        public static Coord fromGrid​(int matrixId,
                                     CoordGrid grid)
        Converts a CoordGrid into a world-space Coord by resolving the associated RSWorldMatrix using the given matrix ID.

        This is equivalent to:

         Coord.fromGrid(Game.getMatrix(matrixId), grid)
         
        Parameters:
        matrixId - the matrix ID used to look up the RSWorldMatrix
        grid - the matrix-local tile coordinate to convert
        Returns:
        the world-space Coord, or Coord.NIL if the matrix cannot be resolved
      • fromGrid

        public static Coord fromGrid​(CoordGrid grid)
        Converts a CoordGrid into a world-space Coord using the matrix referenced directly by the grid's own matrixId.

        This is the most convenient overload and is equivalent to:

         Coord.fromGrid(Game.getMatrix(grid.getMatrixId()), grid)
         
        Parameters:
        grid - the matrix-local tile coordinate to convert
        Returns:
        the corresponding world-space Coord, or Coord.NIL if the grid's matrix cannot be resolved
      • fromPacked

        public static Coord fromPacked​(int packed)
        Unpacks a 32-bit packed coordinate into a Coord.

        The packed format uses:

        • bits 28–29: floor level (0–3)
        • bits 14–27: X coordinate (0–16383)
        • bits 0–13 : Y coordinate (0–16383)
        Parameters:
        packed - the packed coordinate value
        Returns:
        a Coord extracted from the packed integer
      • rotate

        public static Coord rotate​(Coord coord,
                                   int rotation)
        Rotates a coordinate within its containing 8x8 chunk by the given rotation.

        Rotation is performed around the origin of the 8x8 chunk containing coord, using the standard RuneScape convention:

        • 0 – no rotation
        • 1 – 90 degrees clockwise
        • 2 – 180 degrees
        • 3 – 270 degrees clockwise
        The floor level is preserved.
        Parameters:
        coord - the coordinate to rotate
        rotation - rotation value in the range 0–3
        Returns:
        a new Coord representing the rotated position
      • pack

        public static int pack​(int x,
                               int y,
                               int floor)
        Packs a tile coordinate into a 32-bit integer using the standard RuneScape-style coordinate packing format.

        The layout is:

          floor (2 bits)  |   x (14 bits)   |   y (14 bits)
             [28..29]     |     [14..27]    |     [0..13]
         
        Parameters:
        x - the X tile coordinate (0–16383)
        y - the Y tile coordinate (0–16383)
        floor - the floor level (0–3)
        Returns:
        a packed 32-bit integer containing x, y, and floor
      • getX

        public int getX()
        Specified by:
        getX in interface SceneNode
      • getY

        public int getY()
        Specified by:
        getY in interface SceneNode
      • getSource

        public Coord getSource()
      • getSubX

        public float getSubX()
      • getSubY

        public float getSubY()
      • getPreciseX

        public float getPreciseX()
      • getPreciseY

        public float getPreciseY()
      • getRegionId

        public int getRegionId()
        Returns the region ID for this coordinate.

        The region ID is computed from the 8x8 regions:

         regionX = x >> 6
         regionY = y >> 6
         regionId = (regionX << 8) | regionY
         
        Returns:
        the packed region ID
      • translate

        public Coord translate​(int x,
                               int y)
      • dx

        public Coord dx​(int x)
      • dy

        public Coord dy​(int y)
      • getInstanced

        public Set<Coord> getInstanced()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object