Class WorldArea
- java.lang.Object
-
- net.runelite.api.coords.WorldArea
-
public class WorldArea extends java.lang.Object
Represents an area on the world.
-
-
Constructor Summary
Constructors Constructor Description WorldArea(int x, int y, int width, int height, int plane)
WorldArea(WorldPoint location, int width, int height)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WorldArea
calculateNextTravellingPoint(Client client, WorldArea target, boolean stopAtMeleeDistance)
Calculates the next area that will be occupied if this area attempts to move toward it by using the normal NPC travelling pattern.WorldArea
calculateNextTravellingPoint(Client client, WorldArea target, boolean stopAtMeleeDistance, java.util.function.Predicate<? super WorldPoint> extraCondition)
Calculates the next area that will be occupied if this area attempts to move toward it by using the normal NPC travelling pattern.boolean
canTravelInDirection(Client client, int dx, int dy)
Determines if the area can travel in one of the 9 directions by using the standard collision detection algorithm.boolean
canTravelInDirection(Client client, int dx, int dy, java.util.function.Predicate<? super WorldPoint> extraCondition)
Determines if the area can travel in one of the 9 directions by using the standard collision detection algorithm.boolean
contains(WorldPoint worldPoint)
Checks whether a tile is contained within the area and in the same plane.boolean
contains2D(WorldPoint worldPoint)
Checks whether a tile is contained within the area while ignoring the plane.int
distanceTo(WorldArea other)
Computes the shortest distance to another area.int
distanceTo(WorldPoint other)
Computes the shortest distance to a world coordinate.int
distanceTo2D(WorldArea other)
Computes the shortest distance to another area while ignoring the plane.int
distanceTo2D(WorldPoint other)
Computes the shortest distance to a world coordinate.int
getHeight()
The height of the area.int
getPlane()
The plane the area is on.int
getWidth()
The width of the area.int
getX()
The western most point of the area.int
getY()
The southern most point of the area.boolean
hasLineOfSightTo(Client client, WorldArea other)
Determine if this WorldArea has line of sight to another WorldArea.boolean
hasLineOfSightTo(Client client, WorldPoint other)
Determine if this WorldArea has line of sight to another WorldArea.boolean
intersectsWith(WorldArea other)
Checks whether this area intersects with another.boolean
isInMeleeDistance(WorldArea other)
Checks whether this area is within melee distance of another.boolean
isInMeleeDistance(WorldPoint other)
Checks whether a coordinate is within melee distance of this area.WorldPoint
toWorldPoint()
Retrieves the southwestern most point of this WorldArea.java.util.List<WorldPoint>
toWorldPointList()
Accumulates all the WorldPoints that this WorldArea contains and returns them as a list
-
-
-
Constructor Detail
-
WorldArea
public WorldArea(int x, int y, int width, int height, int plane)
-
WorldArea
public WorldArea(WorldPoint location, int width, int height)
-
-
Method Detail
-
distanceTo
public int distanceTo(WorldArea other)
Computes the shortest distance to another area.- Parameters:
other
- the passed area- Returns:
- the distance, or
Integer.MAX_VALUE
if the planes differ
-
distanceTo
public int distanceTo(WorldPoint other)
Computes the shortest distance to a world coordinate.- Parameters:
other
- the passed coordinate- Returns:
- the distance, or
Integer.MAX_VALUE
if the planes differ
-
distanceTo2D
public int distanceTo2D(WorldArea other)
Computes the shortest distance to another area while ignoring the plane.- Parameters:
other
- the passed area- Returns:
- the distance
-
distanceTo2D
public int distanceTo2D(WorldPoint other)
Computes the shortest distance to a world coordinate.- Parameters:
other
- the passed coordinate- Returns:
- the distance
-
contains
public boolean contains(WorldPoint worldPoint)
Checks whether a tile is contained within the area and in the same plane.- Returns:
true
if the tile is contained within the bounds of this area,false
otherwise.
-
contains2D
public boolean contains2D(WorldPoint worldPoint)
Checks whether a tile is contained within the area while ignoring the plane.- Returns:
true
if the tile is contained within the bounds of this area regardless of plane,false
otherwise.
-
isInMeleeDistance
public boolean isInMeleeDistance(WorldArea other)
Checks whether this area is within melee distance of another.Melee distance is exactly 1 tile, so this method computes and returns whether the shortest distance to the passed area is directly on the outside of this areas edge.
- Parameters:
other
- the other area- Returns:
- true if in melee distance, false otherwise
-
isInMeleeDistance
public boolean isInMeleeDistance(WorldPoint other)
Checks whether a coordinate is within melee distance of this area.- Parameters:
other
- the coordinate- Returns:
- true if in melee distance, false otherwise
- See Also:
isInMeleeDistance(WorldArea)
-
intersectsWith
public boolean intersectsWith(WorldArea other)
Checks whether this area intersects with another.- Parameters:
other
- the other area- Returns:
- true if the areas intersect, false otherwise
-
canTravelInDirection
public boolean canTravelInDirection(Client client, int dx, int dy)
Determines if the area can travel in one of the 9 directions by using the standard collision detection algorithm.Note that this method does not consider other actors as a collision, but most non-boss NPCs do check for collision with some actors. For actor collision checking, use the
canTravelInDirection(Client, int, int, Predicate)
method.- Parameters:
client
- the client to test indx
- the x-axis direction to travel (-1, 0, or 1)dy
- the y-axis direction to travel (-1, 0, or 1)- Returns:
- true if the area can travel in the specified direction
-
canTravelInDirection
public boolean canTravelInDirection(Client client, int dx, int dy, java.util.function.Predicate<? super WorldPoint> extraCondition)
Determines if the area can travel in one of the 9 directions by using the standard collision detection algorithm.The passed x and y axis directions indicate the direction to travel in.
Note that this method does not normally consider other actors as a collision, but most non-boss NPCs do check for collision with some actors. However, using the
extraCondition
param it is possible to implement this check manually.- Parameters:
client
- the client to test indx
- the x-axis direction to travel (-1, 0, or 1)dy
- the y-axis direction to travel (-1, 0, or 1)extraCondition
- an additional condition to perform when checking valid tiles, such as performing a check for un-passable actors- Returns:
- true if the area can travel in the specified direction
-
calculateNextTravellingPoint
public WorldArea calculateNextTravellingPoint(Client client, WorldArea target, boolean stopAtMeleeDistance)
Calculates the next area that will be occupied if this area attempts to move toward it by using the normal NPC travelling pattern.- Parameters:
client
- the client to calculate withtarget
- the target areastopAtMeleeDistance
- whether to stop at melee distance to the target- Returns:
- the next occupied area
-
calculateNextTravellingPoint
public WorldArea calculateNextTravellingPoint(Client client, WorldArea target, boolean stopAtMeleeDistance, java.util.function.Predicate<? super WorldPoint> extraCondition)
Calculates the next area that will be occupied if this area attempts to move toward it by using the normal NPC travelling pattern.- Parameters:
client
- the client to calculate withtarget
- the target areastopAtMeleeDistance
- whether to stop at melee distance to the targetextraCondition
- an additional condition to perform when checking valid tiles, such as performing a check for un-passable actors- Returns:
- the next occupied area
-
hasLineOfSightTo
public boolean hasLineOfSightTo(Client client, WorldArea other)
Determine if this WorldArea has line of sight to another WorldArea.Note that the reverse isn't necessarily true, meaning this can return true while the other WorldArea does not have line of sight to this WorldArea.
- Parameters:
client
- The client to compare inother
- The other WorldArea to compare with- Returns:
- Returns true if this WorldArea has line of sight to the other
-
hasLineOfSightTo
public boolean hasLineOfSightTo(Client client, WorldPoint other)
Determine if this WorldArea has line of sight to another WorldArea.Note that the reverse isn't necessarily true, meaning this can return true while the other WorldArea does not have line of sight to this WorldArea.
- Parameters:
client
- The client to compare inother
- The other WorldPoint to compare with- Returns:
- Returns true if this WorldPoint has line of sight to the WorldPoint
-
toWorldPoint
public WorldPoint toWorldPoint()
Retrieves the southwestern most point of this WorldArea.- Returns:
- Returns the southwestern most WorldPoint in the area
-
toWorldPointList
public java.util.List<WorldPoint> toWorldPointList()
Accumulates all the WorldPoints that this WorldArea contains and returns them as a list- Returns:
- Returns the WorldPoints in this WorldArea
-
getX
public int getX()
The western most point of the area.
-
getY
public int getY()
The southern most point of the area.
-
getWidth
public int getWidth()
The width of the area.
-
getHeight
public int getHeight()
The height of the area.
-
getPlane
public int getPlane()
The plane the area is on.
-
-