From 850bf3d333550c37ac0149035a1586c2a9b507ed Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 4 Jul 2021 21:23:20 -0400 Subject: [PATCH] api: fix computing scene coord for negative local points Also add an isInScene method to make testing if a point is in the scene easier, and use it. --- .../java/net/runelite/api/Perspective.java | 31 +++++++++---------- .../net/runelite/api/coords/LocalPoint.java | 14 +++++++-- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/runelite-api/src/main/java/net/runelite/api/Perspective.java b/runelite-api/src/main/java/net/runelite/api/Perspective.java index 06c84f08f2..af61d02134 100644 --- a/runelite-api/src/main/java/net/runelite/api/Perspective.java +++ b/runelite-api/src/main/java/net/runelite/api/Perspective.java @@ -410,6 +410,21 @@ public class Perspective int plane, int zOffset) { + if (!localLocation.isInScene()) + { + return null; + } + + final byte[][][] tileSettings = client.getTileSettings(); + final int sceneX = localLocation.getSceneX(); + final int sceneY = localLocation.getSceneY(); + + int tilePlane = plane; + if (plane < Constants.MAX_Z - 1 && (tileSettings[1][sceneX][sceneY] & TILE_FLAG_BRIDGE) == TILE_FLAG_BRIDGE) + { + tilePlane = plane + 1; + } + final int swX = localLocation.getX() - (sizeX * LOCAL_TILE_SIZE / 2); final int swY = localLocation.getY() - (sizeY * LOCAL_TILE_SIZE / 2); @@ -422,22 +437,6 @@ public class Perspective final int nwX = neX; final int nwY = swY; - final byte[][][] tileSettings = client.getTileSettings(); - - final int sceneX = localLocation.getSceneX(); - final int sceneY = localLocation.getSceneY(); - - if (sceneX < 0 || sceneY < 0 || sceneX >= SCENE_SIZE || sceneY >= SCENE_SIZE) - { - return null; - } - - int tilePlane = plane; - if (plane < Constants.MAX_Z - 1 && (tileSettings[1][sceneX][sceneY] & TILE_FLAG_BRIDGE) == TILE_FLAG_BRIDGE) - { - tilePlane = plane + 1; - } - final int swHeight = getHeight(client, swX, swY, tilePlane) - zOffset; final int nwHeight = getHeight(client, nwX, nwY, tilePlane) - zOffset; final int neHeight = getHeight(client, neX, neY, tilePlane) - zOffset; diff --git a/runelite-api/src/main/java/net/runelite/api/coords/LocalPoint.java b/runelite-api/src/main/java/net/runelite/api/coords/LocalPoint.java index e8df3e9d7d..3a726fc765 100644 --- a/runelite-api/src/main/java/net/runelite/api/coords/LocalPoint.java +++ b/runelite-api/src/main/java/net/runelite/api/coords/LocalPoint.java @@ -95,6 +95,16 @@ public class LocalPoint return (int) Math.hypot(getX() - other.getX(), getY() - other.getY()); } + /** + * Test if this point is in the loaded scene, a 104x104 tile area. + * @return + */ + public boolean isInScene() + { + return x >= 0 && x < Perspective.SCENE_SIZE << Perspective.LOCAL_COORD_BITS + && y >= 0 && y < Perspective.SCENE_SIZE << Perspective.LOCAL_COORD_BITS; + } + /** * Gets the coordinate at the center of the passed tile. * @@ -117,7 +127,7 @@ public class LocalPoint */ public int getSceneX() { - return x >>> Perspective.LOCAL_COORD_BITS; + return x >> Perspective.LOCAL_COORD_BITS; } /** @@ -127,6 +137,6 @@ public class LocalPoint */ public int getSceneY() { - return y >>> Perspective.LOCAL_COORD_BITS; + return y >> Perspective.LOCAL_COORD_BITS; } }