runelite-api/src/main/java/net/runelite/api/coords/WorldArea.java
/**
	 * Calculates the next area that will be occupied if this area
	 * attempts to move toward it by using the normal NPC travelling
	 * pattern.
	 *
	 * @param client The client to calculate with
	 * @param target The target area
	 * @param stopAtMeleeDistance Determine if it should stop at melee distance to the target
	 * @param extraCondition Additional check for if movement is allowed through specific
	 * tiles, which may be used if movement should be disabled through other actors
	 * @return Returns the next occupied area
	 */
Calculates the next area that will be occupied if this area
attempts to move toward it by using the normal NPC travelling
pattern.


Calculates the next area that will be occupied if this area attempts to move toward it by using the normal NPC travelling pattern .
public WorldArea calculateNextTravellingPoint(Client client, WorldArea target,
		boolean stopAtMeleeDistance, Predicate<? super WorldPoint> extraCondition)
	{
		if (plane != target.getPlane())
		{
			return null;
		}
		if (this.intersectsWith(target))
		{
			if (stopAtMeleeDistance)
			{
				return null;
			}
			else
			{
				return this;
			}
		}
		int dx = target.x - this.x;
		int dy = target.y - this.y;
		Point axisDistances = getAxisDistances(target);
		if (stopAtMeleeDistance && axisDistances.getX() + axisDistances.getY() == 1)
		{
			return this;
		}
		LocalPoint lp = LocalPoint.fromWorld(client, x, y);
		if (lp == null ||
			lp.getRegionX() + dx < 0 || lp.getRegionX() + dy >= Constants.REGION_SIZE ||
			lp.getRegionY() + dx < 0 || lp.getRegionY() + dy >= Constants.REGION_SIZE)
		{
			return null;
		}
		int dxSig = Integer.signum(dx);
		int dySig = Integer.signum(dy);
		if (stopAtMeleeDistance && axisDistances.getX() == 1 && axisDistances.getY() == 1)
		{
			if (this.canTravelInDirection(client, dxSig, 0, extraCondition))
			{
				return new WorldArea(x + dxSig, y, width, height, plane);
			}
		}
		else
		{
			if (this.canTravelInDirection(client, dxSig, dySig, extraCondition))
			{
				return new WorldArea(x + dxSig, y + dySig, width, height, plane);
			}
			else if (dx != 0 && this.canTravelInDirection(client, dxSig, 0, extraCondition))
			{
				return new WorldArea(x + dxSig, y, width, height, plane);
			}
			else if (dy != 0 && Math.max(Math.abs(dx), Math.abs(dy)) > 1 &&
				this.canTravelInDirection(client, 0, dy, extraCondition))
			{
				return new WorldArea(x, y + dySig, width, height, plane);
			}
		}
		return this;
	}
public WorldArea calculateNextTravellingPoint ( Client client , WorldArea target , boolean stopAtMeleeDistance , Predicate < ? super WorldPoint > extraCondition ) { if ( plane != target . getPlane ( ) ) { return null ; } if ( this . intersectsWith ( target ) ) { if ( stopAtMeleeDistance ) { return null ; } else { return this ; } } int dx = target . x - this . x ; int dy = target . y - this . y ; Point axisDistances = getAxisDistances ( target ) ; if ( stopAtMeleeDistance && axisDistances . getX ( ) + axisDistances . getY ( ) == 1 ) { return this ; } LocalPoint lp = LocalPoint . fromWorld ( client , x , y ) ; if ( lp == null || lp . getRegionX ( ) + dx < 0 || lp . getRegionX ( ) + dy >= Constants . REGION_SIZE || lp . getRegionY ( ) + dx < 0 || lp . getRegionY ( ) + dy >= Constants . REGION_SIZE ) { return null ; } int dxSig = Integer . signum ( dx ) ; int dySig = Integer . signum ( dy ) ; if ( stopAtMeleeDistance && axisDistances . getX ( ) == 1 && axisDistances . getY ( ) == 1 ) { if ( this . canTravelInDirection ( client , dxSig , 0 , extraCondition ) ) { return new WorldArea ( x + dxSig , y , width , height , plane ) ; } } else { if ( this . canTravelInDirection ( client , dxSig , dySig , extraCondition ) ) { return new WorldArea ( x + dxSig , y + dySig , width , height , plane ) ; } else if ( dx != 0 && this . canTravelInDirection ( client , dxSig , 0 , extraCondition ) ) { return new WorldArea ( x + dxSig , y , width , height , plane ) ; } else if ( dy != 0 && Math . max ( Math . abs ( dx ) , Math . abs ( dy ) ) > 1 && this . canTravelInDirection ( client , 0 , dy , extraCondition ) ) { return new WorldArea ( x , y + dySig , width , height , plane ) ; } } return this ; }
Calculates the next area that will be occupied if this area
 attempts to move toward it by using the normal NPC travelling
 pattern.
Calculates the next area that will be occupied if this area attempts to move toward it by using the normal NPC travelling pattern .
// Movement is unpredictable when the NPC and actor stand on top of each other // NPC is in melee distance of target, so no movement is done // NPC is travelling out of region, so collision data isn't available // When it needs to stop at melee distance, it will only attempt // to travel along the x axis when it is standing diagonally // from the target // Note that NPCs don't attempts to travel along the y-axis // if the target is <= 1 tile distance away // The NPC is stuck