Remove unnecessary code from GroundMarkerPlugin
- Instead of writing rotation and inverse rotation methods twice, simply pass inversed rotation to rotate method - Do not create canvasTilePoly 2 times Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -191,7 +191,7 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
WorldPoint p = new WorldPoint(client.getBaseX() + x * CHUNK_SIZE + (worldPoint.getX() & (CHUNK_SIZE - 1)),
|
WorldPoint p = new WorldPoint(client.getBaseX() + x * CHUNK_SIZE + (worldPoint.getX() & (CHUNK_SIZE - 1)),
|
||||||
client.getBaseY() + y * CHUNK_SIZE + (worldPoint.getY() & (CHUNK_SIZE - 1)),
|
client.getBaseY() + y * CHUNK_SIZE + (worldPoint.getY() & (CHUNK_SIZE - 1)),
|
||||||
worldPoint.getPlane());
|
worldPoint.getPlane());
|
||||||
p = rotateChunk(p, rotation);
|
p = rotate(p, rotation);
|
||||||
worldPoints.add(p);
|
worldPoints.add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,14 +200,26 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
return worldPoints;
|
return worldPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotate the chunk containing the given point to rotation 0
|
||||||
|
*
|
||||||
|
* @param point point
|
||||||
|
* @param rotation rotation
|
||||||
|
* @return world point
|
||||||
|
*/
|
||||||
|
private static WorldPoint rotateInverse(WorldPoint point, int rotation)
|
||||||
|
{
|
||||||
|
return rotate(point, 4 - rotation);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotate the coordinates in the chunk according to chunk rotation
|
* Rotate the coordinates in the chunk according to chunk rotation
|
||||||
*
|
*
|
||||||
* @param point
|
* @param point point
|
||||||
* @param rotation
|
* @param rotation rotation
|
||||||
* @return
|
* @return world point
|
||||||
*/
|
*/
|
||||||
private static WorldPoint rotateChunk(WorldPoint point, int rotation)
|
private static WorldPoint rotate(WorldPoint point, int rotation)
|
||||||
{
|
{
|
||||||
int chunkX = point.getX() & ~(CHUNK_SIZE - 1);
|
int chunkX = point.getX() & ~(CHUNK_SIZE - 1);
|
||||||
int chunkY = point.getY() & ~(CHUNK_SIZE - 1);
|
int chunkY = point.getY() & ~(CHUNK_SIZE - 1);
|
||||||
@@ -341,7 +353,7 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
|
|
||||||
worldPoint = new WorldPoint(x, y, plane);
|
worldPoint = new WorldPoint(x, y, plane);
|
||||||
// rotate point back to 0, to match with template
|
// rotate point back to 0, to match with template
|
||||||
worldPoint = rotate(worldPoint, rotation);
|
worldPoint = rotateInverse(worldPoint, rotation);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -369,31 +381,6 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
loadPoints();
|
loadPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Rotate the chunk containing the given point to rotation 0
|
|
||||||
*
|
|
||||||
* @param point
|
|
||||||
* @param rotation
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private WorldPoint rotate(WorldPoint point, int rotation)
|
|
||||||
{
|
|
||||||
int chunkX = point.getX() & ~(CHUNK_SIZE - 1);
|
|
||||||
int chunkY = point.getY() & ~(CHUNK_SIZE - 1);
|
|
||||||
int x = point.getX() & (CHUNK_SIZE - 1);
|
|
||||||
int y = point.getY() & (CHUNK_SIZE - 1);
|
|
||||||
switch (rotation)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
return new WorldPoint(chunkX + ((CHUNK_SIZE - 1) - y), chunkY + x, point.getPlane());
|
|
||||||
case 2:
|
|
||||||
return new WorldPoint(chunkX + ((CHUNK_SIZE - 1) - x), chunkY + ((CHUNK_SIZE - 1) - y), point.getPlane());
|
|
||||||
case 3:
|
|
||||||
return new WorldPoint(chunkX + y, chunkY + ((CHUNK_SIZE - 1) - x), point.getPlane());
|
|
||||||
}
|
|
||||||
return point;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the tile which the given mouse point is in
|
* Find the tile which the given mouse point is in
|
||||||
* @param mouse
|
* @param mouse
|
||||||
@@ -426,7 +413,7 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Perspective.getCanvasTilePoly(client, local).contains(gameMouse))
|
if (poly.contains(gameMouse))
|
||||||
{
|
{
|
||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user