Class Calculations

java.lang.Object
net.storm.api.commons.Calculations

public class Calculations extends Object
Provides utility methods for pathfinding and collision detection calculations.

This class contains methods for checking collision flags, determining walkability between tiles, detecting walls and doors, and performing breadth-first search pathfinding to determine which tiles can be reached from a source location.

The collision system uses bitwise flags from CollisionDataFlag to determine movement restrictions. Walls are detected both through collision flags and by examining wall objects on tiles.

Example usage:


 // Check if a tile is blocked
 if (Calculations.isObstacle(client, targetPoint)) {
     // Cannot walk to this tile
 }

 // Check if we can interact with a locatable object
 if (Calculations.isInteractable(client, playerLocation, gameObject)) {
     // Object is reachable
 }

 // Check if a specific tile is walkable
 if (Calculations.isWalkable(client, playerLocation, destination)) {
     // Can walk to destination
 }
 
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    canWalk(net.runelite.api.coords.Direction direction, int startFlag, int endFlag)
    Determines if movement is possible in a specific direction.
    static boolean
    check(int flag, int checkFlag)
    Checks if a specific flag bit is set in a collision flag.
    static int
    getCollisionFlag(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint point)
    Gets the collision flag for a specific world point.
    static net.runelite.api.coords.WorldPoint
    getNeighbour(net.runelite.api.coords.Direction direction, net.runelite.api.coords.WorldPoint source)
    Gets the neighboring world point in the specified direction.
    static List<net.runelite.api.coords.WorldPoint>
    getNeighbours(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, Locatable locatableDestination)
    Gets all walkable neighboring tiles from a source point.
    static List<net.runelite.api.coords.WorldPoint>
    getVisitedTiles(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, net.runelite.api.coords.WorldPoint worldPoint)
    Performs a breadth-first search to find all tiles visited when pathfinding from source to a world point.
    static List<net.runelite.api.coords.WorldPoint>
    getVisitedTiles(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, net.runelite.api.coords.WorldPoint destination, Locatable locatableDestination)
    Performs a breadth-first search to find all tiles visited when pathfinding from source to destination.
    static List<net.runelite.api.coords.WorldPoint>
    getVisitedTiles(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, Locatable locatable)
    Performs a breadth-first search to find all tiles visited when pathfinding from source to a locatable object.
    static boolean
    isDoored(ITile source, ITile destination)
    Checks if there is a closed door between two adjacent tiles.
    static boolean
    isInteractable(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, Locatable locatable)
    Checks if a locatable object can be interacted with from the source location.
    static boolean
    isObstacle(int endFlag)
    Checks if a collision flag indicates a full movement block.
    static boolean
    isObstacle(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint worldPoint)
    Checks if a world point is a full obstacle that blocks movement.
    static boolean
    isWalkable(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, net.runelite.api.coords.WorldPoint worldPoint)
    Checks if a world point can be walked to from the source location.
    static boolean
    isWalled(net.runelite.api.coords.Direction direction, int startFlag)
    Checks if there is a wall blocking movement in the specified direction.
    static boolean
    isWalled(ITile source, ITile destination)
    Checks if there is a wall object blocking movement between two adjacent tiles.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Calculations

      public Calculations()
  • Method Details

    • check

      public static boolean check(int flag, int checkFlag)
      Checks if a specific flag bit is set in a collision flag.
      Parameters:
      flag - the collision flag value to check
      checkFlag - the specific bit(s) to check for
      Returns:
      true if the checkFlag bit(s) are set in flag, false otherwise
    • isObstacle

      public static boolean isObstacle(int endFlag)
      Checks if a collision flag indicates a full movement block.
      Parameters:
      endFlag - the collision flag to check
      Returns:
      true if the flag indicates a full obstacle, false otherwise
    • isObstacle

      public static boolean isObstacle(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint worldPoint)
      Checks if a world point is a full obstacle that blocks movement.
      Parameters:
      client - the game client
      worldPoint - the world point to check
      Returns:
      true if the tile at the world point is a full obstacle, false otherwise
      Throws:
      IllegalStateException - if collision maps are not loaded
    • getCollisionFlag

      public static int getCollisionFlag(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint point)
      Gets the collision flag for a specific world point.

      If the point is not within the loaded scene, returns CollisionDataFlag.BLOCK_MOVEMENT_FULL indicating it is blocked.

      Parameters:
      client - the game client
      point - the world point to get the collision flag for
      Returns:
      the collision flag value for the specified point
      Throws:
      IllegalStateException - if collision maps or collision data are not loaded
    • isWalled

      public static boolean isWalled(net.runelite.api.coords.Direction direction, int startFlag)
      Checks if there is a wall blocking movement in the specified direction.

      Uses direction-specific collision flag bits to determine if a wall exists on the edge of a tile in the given direction.

      Parameters:
      direction - the direction to check for a wall
      startFlag - the collision flag of the source tile
      Returns:
      true if there is a wall blocking the specified direction, false otherwise
      Throws:
      IllegalArgumentException - if direction is not a cardinal direction
    • isWalled

      public static boolean isWalled(ITile source, ITile destination)
      Checks if there is a wall object blocking movement between two adjacent tiles.

      This method examines the wall object on the source tile and its orientation to determine if it blocks movement to the destination tile.

      Parameters:
      source - the source tile
      destination - the destination tile
      Returns:
      true if a wall object blocks movement between the tiles, false otherwise
    • isDoored

      public static boolean isDoored(ITile source, ITile destination)
      Checks if there is a closed door between two adjacent tiles.

      A closed door is a wall object that has an "Open" action and blocks movement between the tiles.

      Parameters:
      source - the source tile
      destination - the destination tile
      Returns:
      true if there is a closed door between the tiles, false otherwise
    • canWalk

      public static boolean canWalk(net.runelite.api.coords.Direction direction, int startFlag, int endFlag)
      Determines if movement is possible in a specific direction.

      Movement is blocked if the destination tile is a full obstacle or if there is a wall blocking the direction.

      Parameters:
      direction - the direction of movement
      startFlag - the collision flag of the source tile
      endFlag - the collision flag of the destination tile
      Returns:
      true if movement is possible in the specified direction, false otherwise
    • getNeighbour

      public static net.runelite.api.coords.WorldPoint getNeighbour(net.runelite.api.coords.Direction direction, net.runelite.api.coords.WorldPoint source)
      Gets the neighboring world point in the specified direction.
      Parameters:
      direction - the direction to the neighbor
      source - the source world point
      Returns:
      the world point one tile in the specified direction from source
      Throws:
      IllegalArgumentException - if direction is not a cardinal direction
    • getNeighbours

      public static List<net.runelite.api.coords.WorldPoint> getNeighbours(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, Locatable locatableDestination)
      Gets all walkable neighboring tiles from a source point.

      If a locatable destination is provided, tiles that are part of the destination's area are included even if they would normally be blocked, allowing interaction with game objects.

      Parameters:
      client - the game client
      source - the source world point
      locatableDestination - optional destination object for special handling, may be null
      Returns:
      a list of walkable neighboring world points
    • getVisitedTiles

      public static List<net.runelite.api.coords.WorldPoint> getVisitedTiles(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, net.runelite.api.coords.WorldPoint destination, Locatable locatableDestination)
      Performs a breadth-first search to find all tiles visited when pathfinding from source to destination.

      The search stops when the destination is reached or when MAX_ATTEMPTED_TILES have been checked.

      Parameters:
      client - the game client
      source - the starting world point
      destination - the target world point, may be null if locatableDestination is provided
      locatableDestination - optional destination object for special handling, may be null if destination is provided
      Returns:
      a list of visited world points during pathfinding, or an empty list if the destination is not in the scene or on a different plane
    • getVisitedTiles

      public static List<net.runelite.api.coords.WorldPoint> getVisitedTiles(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, Locatable locatable)
      Performs a breadth-first search to find all tiles visited when pathfinding from source to a locatable object.

      This is a convenience method for compatibility that delegates to getVisitedTiles(Client, WorldPoint, WorldPoint, Locatable).

      Parameters:
      client - the game client
      source - the starting world point
      locatable - the target locatable object
      Returns:
      a list of visited world points during pathfinding
    • getVisitedTiles

      public static List<net.runelite.api.coords.WorldPoint> getVisitedTiles(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, net.runelite.api.coords.WorldPoint worldPoint)
      Performs a breadth-first search to find all tiles visited when pathfinding from source to a world point.

      This is a convenience method for compatibility that delegates to getVisitedTiles(Client, WorldPoint, WorldPoint, Locatable).

      Parameters:
      client - the game client
      source - the starting world point
      worldPoint - the target world point
      Returns:
      a list of visited world points during pathfinding
    • isInteractable

      public static boolean isInteractable(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, Locatable locatable)
      Checks if a locatable object can be interacted with from the source location.

      An object is interactable if pathfinding from the source can reach the object's world location.

      Parameters:
      client - the game client
      source - the starting world point (typically player position)
      locatable - the object to check interactability for
      Returns:
      true if the object can be interacted with from the source, false otherwise
    • isWalkable

      public static boolean isWalkable(net.runelite.api.Client client, net.runelite.api.coords.WorldPoint source, net.runelite.api.coords.WorldPoint worldPoint)
      Checks if a world point can be walked to from the source location.

      A point is walkable if pathfinding from the source can reach it.

      Parameters:
      client - the game client
      source - the starting world point (typically player position)
      worldPoint - the destination to check walkability for
      Returns:
      true if the destination can be walked to from the source, false otherwise