Add common method for converting local to world point
- Add commom method for converting local to world point accounting for instances - Make both discord and ground marker plugin use this method Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
committed by
Tomas Slusny
parent
0b2c7af6aa
commit
98ec2cd5c8
@@ -34,11 +34,9 @@ import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.runelite.api.Client;
|
||||
import static net.runelite.api.Constants.CHUNK_SIZE;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.WorldType;
|
||||
import net.runelite.api.coords.LocalPoint;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.ExperienceChanged;
|
||||
@@ -186,7 +184,7 @@ public class DiscordPlugin extends Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
final int playerRegionID = getCurrentRegion();
|
||||
final int playerRegionID = WorldPoint.fromLocalInstance(client, client.getLocalPlayer().getLocalLocation()).getRegionID();
|
||||
|
||||
if (playerRegionID == 0)
|
||||
{
|
||||
@@ -238,26 +236,4 @@ public class DiscordPlugin extends Plugin
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getCurrentRegion()
|
||||
{
|
||||
if (!client.isInInstancedRegion())
|
||||
{
|
||||
return client.getLocalPlayer().getWorldLocation().getRegionID();
|
||||
}
|
||||
|
||||
// get chunk data of current chunk
|
||||
final LocalPoint localPoint = client.getLocalPlayer().getLocalLocation();
|
||||
final int[][][] instanceTemplateChunks = client.getInstanceTemplateChunks();
|
||||
final int z = client.getPlane();
|
||||
final int chunkData = instanceTemplateChunks[z][localPoint.getSceneX() / CHUNK_SIZE][localPoint.getSceneY() / CHUNK_SIZE];
|
||||
|
||||
// extract world point from chunk data
|
||||
final int chunkY = (chunkData >> 3 & 0x7FF) * CHUNK_SIZE;
|
||||
final int chunkX = (chunkData >> 14 & 0x3FF) * CHUNK_SIZE;
|
||||
|
||||
final WorldPoint worldPoint = new WorldPoint(chunkX, chunkY, z);
|
||||
return worldPoint.getRegionID();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -311,39 +311,7 @@ public class GroundMarkerPlugin extends Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
WorldPoint worldPoint;
|
||||
|
||||
if (client.isInInstancedRegion())
|
||||
{
|
||||
// get position in the scene
|
||||
int sceneX = localPoint.getSceneX();
|
||||
int sceneY = localPoint.getSceneY();
|
||||
|
||||
// get chunk from scene
|
||||
int chunkX = sceneX / CHUNK_SIZE;
|
||||
int chunkY = sceneY / CHUNK_SIZE;
|
||||
|
||||
// get the template chunk for the chunk
|
||||
int[][][] instanceTemplateChunks = client.getInstanceTemplateChunks();
|
||||
int templateChunk = instanceTemplateChunks[client.getPlane()][chunkX][chunkY];
|
||||
|
||||
int rotation = templateChunk >> 1 & 0x3;
|
||||
int templateChunkY = (templateChunk >> 3 & 0x7FF) * CHUNK_SIZE;
|
||||
int templateChunkX = (templateChunk >> 14 & 0x3FF) * CHUNK_SIZE;
|
||||
int plane = templateChunk >> 24 & 0x3;
|
||||
|
||||
// calculate world point of the template
|
||||
int x = templateChunkX + (sceneX & (CHUNK_SIZE - 1));
|
||||
int y = templateChunkY + (sceneY & (CHUNK_SIZE - 1));
|
||||
|
||||
worldPoint = new WorldPoint(x, y, plane);
|
||||
// rotate point back to 0, to match with template
|
||||
worldPoint = rotateInverse(worldPoint, rotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
worldPoint = WorldPoint.fromLocal(client, localPoint);
|
||||
}
|
||||
WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, client.getLocalPlayer().getLocalLocation());
|
||||
|
||||
int regionId = worldPoint.getRegionID();
|
||||
GroundMarkerPoint point = new GroundMarkerPoint(regionId, worldPoint.getX() & 0x3f, worldPoint.getY() & 0x3f, client.getPlane());
|
||||
|
||||
Reference in New Issue
Block a user