api: Add getMirrorPoint to WorldPoint API

This commit is contained in:
Jordan Atwood
2021-06-22 10:18:55 -07:00
committed by Adam
parent 847c44c44c
commit d27f5f9a76
5 changed files with 97 additions and 66 deletions

View File

@@ -44,6 +44,14 @@ import net.runelite.api.Perspective;
@Value
public class WorldPoint
{
private static final int[] REGION_MIRRORS = {
// Prifddinas
12894, 8755,
12895, 8756,
13150, 9011,
13151, 9012
};
/**
* X-axis coordinate.
*/
@@ -373,4 +381,29 @@ public class WorldPoint
{
return position & (REGION_SIZE - 1);
}
/**
* Translate a coordinate either between overworld and real, or real and overworld
*
* @param worldPoint
* @param toOverworld whether to convert to overworld coordinates, or to real coordinates
* @return
*/
public static WorldPoint getMirrorPoint(WorldPoint worldPoint, boolean toOverworld)
{
int region = worldPoint.getRegionID();
for (int i = 0; i < REGION_MIRRORS.length; i += 2)
{
int real = REGION_MIRRORS[i];
int overworld = REGION_MIRRORS[i + 1];
// Test against what we are converting from
if (region == (toOverworld ? real : overworld))
{
return fromRegion(toOverworld ? overworld : real,
worldPoint.getRegionX(), worldPoint.getRegionY(), worldPoint.getPlane());
}
}
return worldPoint;
}
}