Use npc indices to iterate local npcs
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
package net.runelite.api;
|
||||
|
||||
import java.awt.Canvas;
|
||||
import java.util.List;
|
||||
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
@@ -35,9 +36,7 @@ public interface Client
|
||||
|
||||
Player[] getCachedPlayers();
|
||||
|
||||
NPC getNpc(int idx);
|
||||
|
||||
NPC[] getCachedNPCs();
|
||||
List<NPC> getNpcs();
|
||||
|
||||
int getBoostedSkillLevel(Skill skill);
|
||||
|
||||
|
||||
@@ -27,16 +27,13 @@ package net.runelite.api.queries;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class NPCQuery extends ActorQuery<NPC, NPCQuery>
|
||||
{
|
||||
@Override
|
||||
public NPC[] result(Client client)
|
||||
{
|
||||
return Arrays.stream(client.getCachedNPCs())
|
||||
.filter(Objects::nonNull)
|
||||
return client.getNpcs().stream()
|
||||
.filter(predicate)
|
||||
.toArray(NPC[]::new);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.awt.Polygon;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.List;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.DecorativeObject;
|
||||
import net.runelite.api.GameObject;
|
||||
@@ -148,23 +149,17 @@ public class DevToolsOverlay extends Overlay
|
||||
|
||||
private void renderNpcs(Graphics2D graphics)
|
||||
{
|
||||
NPC[] npcs = client.getCachedNPCs();
|
||||
if (npcs != null && (npcs.length - 1) > 0)
|
||||
List<NPC> npcs = client.getNpcs();
|
||||
for (NPC npc : npcs)
|
||||
{
|
||||
for (NPC npc : npcs)
|
||||
String text = npc.getName() + " (ID: " + npc.getId() + ") (A: " + npc.getAnimation() + ") (G: " + npc.getGraphic() + ")";
|
||||
if (npc.getCombatLevel() > 1)
|
||||
{
|
||||
if (npc != null)
|
||||
{
|
||||
String text = npc.getName() + " (ID: " + npc.getId() + ") (A: " + npc.getAnimation() + ") (G: " + npc.getGraphic() + ")";
|
||||
if (npc.getCombatLevel() > 1)
|
||||
{
|
||||
OverlayUtil.renderActorOverlay(graphics, npc, text, YELLOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
OverlayUtil.renderActorOverlay(graphics, npc, text, ORANGE);
|
||||
}
|
||||
}
|
||||
OverlayUtil.renderActorOverlay(graphics, npc, text, YELLOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
OverlayUtil.renderActorOverlay(graphics, npc, text, ORANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.image.BufferedImage;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.Perspective;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.mixins.Inject;
|
||||
@@ -59,7 +60,8 @@ public abstract class RSActorMixin implements RSActor
|
||||
|
||||
if (i < 0x8000)
|
||||
{
|
||||
return client.getNpc(i);
|
||||
NPC[] npcs = client.getCachedNPCs();
|
||||
return npcs[i];
|
||||
}
|
||||
|
||||
i -= 0x8000;
|
||||
|
||||
@@ -52,9 +52,19 @@ public abstract class RSClientMixin implements RSClient
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public NPC getNpc(int idx)
|
||||
public List<NPC> getNpcs()
|
||||
{
|
||||
return getCachedNPCs()[idx];
|
||||
int validNpcIndexes = getNpcIndexesCount();
|
||||
int[] npcIndexes = getNpcIndices();
|
||||
NPC[] cachedNpcs = getCachedNPCs();
|
||||
List<NPC> npcs = new ArrayList<NPC>(validNpcIndexes);
|
||||
|
||||
for (int i = 0; i < validNpcIndexes; ++i)
|
||||
{
|
||||
npcs.add(cachedNpcs[npcIndexes[i]]);
|
||||
}
|
||||
|
||||
return npcs;
|
||||
}
|
||||
|
||||
@Inject
|
||||
|
||||
@@ -117,8 +117,13 @@ public interface RSClient extends RSGameEngine, Client
|
||||
@Override
|
||||
RSPlayer getLocalPlayer();
|
||||
|
||||
@Import("npcIndexesCount")
|
||||
int getNpcIndexesCount();
|
||||
|
||||
@Import("npcIndices")
|
||||
int[] getNpcIndices();
|
||||
|
||||
@Import("cachedNPCs")
|
||||
@Override
|
||||
RSNPC[] getCachedNPCs();
|
||||
|
||||
@Import("collisionMaps")
|
||||
|
||||
Reference in New Issue
Block a user