runelite-api: add ability to get npc index
This commit is contained in:
@@ -34,4 +34,5 @@ public interface NPC extends Actor
|
||||
@Override
|
||||
int getCombatLevel();
|
||||
|
||||
int getIndex();
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ import net.runelite.rs.api.RSDeque;
|
||||
import net.runelite.rs.api.RSHashTable;
|
||||
import net.runelite.rs.api.RSIndexedSprite;
|
||||
import net.runelite.rs.api.RSItemContainer;
|
||||
import net.runelite.rs.api.RSNPC;
|
||||
import net.runelite.rs.api.RSName;
|
||||
import net.runelite.rs.api.RSWidget;
|
||||
|
||||
@@ -494,6 +495,24 @@ public abstract class RSClientMixin implements RSClient
|
||||
eventBus.post(gameStateChange);
|
||||
}
|
||||
|
||||
|
||||
@FieldHook("cachedNPCs")
|
||||
@Inject
|
||||
public static void cachedNPCsChanged(int idx)
|
||||
{
|
||||
RSNPC[] cachedNPCs = client.getCachedNPCs();
|
||||
if (idx < 0 || idx >= cachedNPCs.length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RSNPC npc = cachedNPCs[idx];
|
||||
if (npc != null)
|
||||
{
|
||||
npc.setIndex(idx);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@FieldHook("grandExchangeOffers")
|
||||
public static void onGrandExchangeOffersChanged(int idx)
|
||||
|
||||
@@ -32,6 +32,9 @@ import net.runelite.rs.api.RSNPCComposition;
|
||||
@Mixin(RSNPC.class)
|
||||
public abstract class RSNPCMixin implements RSNPC
|
||||
{
|
||||
@Inject
|
||||
private int npcIndex;
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public int getId()
|
||||
@@ -55,4 +58,18 @@ public abstract class RSNPCMixin implements RSNPC
|
||||
RSNPCComposition composition = getComposition();
|
||||
return composition == null ? -1 : composition.getCombatLevel();
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public int getIndex()
|
||||
{
|
||||
return npcIndex;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setIndex(int id)
|
||||
{
|
||||
npcIndex = id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,9 @@ public interface RSNPC extends RSActor, NPC
|
||||
{
|
||||
@Import("composition")
|
||||
RSNPCComposition getComposition();
|
||||
|
||||
@Override
|
||||
int getIndex();
|
||||
|
||||
void setIndex(int id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user