Skip to content

Commit

Permalink
fix: Remove npcs() iteration from drawCallback (#1981)
Browse files Browse the repository at this point in the history
* fix: Use new npcs() method in RL

* fix: Remove npcs() check within drawback

This was causing an issue where the looping of npcs within a loop of npcs was causing npcs to not render.

* fix: Update to 4.7.6.1

Fix for npcs issue with latest RL update.
  • Loading branch information
Zoinkwiz authored Feb 18, 2025
1 parent 1676ae3 commit 1a84c2b
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {
}

group = 'com.questhelper'
version = '4.7.6'
version = '4.7.6.1'
sourceCompatibility = "11"

tasks.withType(JavaCompile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public NpcCondition(int npcID, Zone zone)
@Override
public void initialize(Client client)
{
for (NPC npc : client.getNpcs())
for (NPC npc : client.getTopLevelWorldView().npcs())
{
if (npcID == npc.getId())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected FollowerItemRequirement copyOfClass()
@Override
public boolean check(Client client)
{
boolean match = client.getNpcs().stream()
boolean match = client.getTopLevelWorldView().npcs().stream()
.filter(npc -> npc.getInteracting() != null) // we need this check because Client#getLocalPlayer is Nullable
.filter(npc -> npc.getInteracting() == client.getLocalPlayer())
.anyMatch(npc -> followerIDs.contains(npc.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FollowerRequirement(String text, List<Integer> followers)
@Override
public boolean check(Client client)
{
return client.getNpcs()
return client.getTopLevelWorldView().npcs()
.stream()
.filter(npc -> npc.getInteracting() != null) // we need this check because Client#getLocalPlayer is Nullable
.filter(npc -> npc.getInteracting() == client.getLocalPlayer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public NpcInteractingRequirement(Integer... npcID)
@Override
public boolean check(Client client)
{
return client.getNpcs().stream()
return client.getTopLevelWorldView().npcs().stream()
.filter(npc -> npc.getInteracting() != null)
.filter(npc -> npc.getInteracting() == client.getLocalPlayer())
.anyMatch(npc -> npcIDs.contains(npc.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public NpcInteractingWithNpcRequirement(Integer npcID, String... npcNames)
@Override
public boolean check(Client client)
{
return client.getNpcs().stream()
return client.getTopLevelWorldView().npcs().stream()
.filter(npc -> npc.getInteracting() != null)
.filter(npc -> npcNames.contains(npc.getInteracting().getName()))
.anyMatch(npc -> npc.getInteracting().getInteracting() == npc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public NpcRequirement(int npcID, String npcName)
@Override
public boolean check(Client client)
{
List<NPC> found = client.getNpcs().stream()
List<NPC> found = client.getTopLevelWorldView().npcs().stream()
.filter(npc -> npc.getId() == npcID)
.filter(npc -> npcName == null || (npc.getName() != null && npc.getName().equals(npcName)))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static void createHopleez(RuneliteObjectManager runeliteObjectManager, C
replacedHopleez.setFace(7481);
replacedHopleez.setExamine("He was here first.");
replacedHopleez.addExamineAction(runeliteObjectManager);
replacedHopleez.setDisplayRequirement(new Conditions(new NpcRequirement("Hatius Cosaintus", NpcID.HATIUS_COSAINTUS), new PlayerQuestStateRequirement(configManager, PlayerQuests.COOKS_HELPER, 4, Operation.GREATER_EQUAL)));
replacedHopleez.setDisplayRequirement(new PlayerQuestStateRequirement(configManager, PlayerQuests.COOKS_HELPER, 4, Operation.GREATER_EQUAL));
replacedHopleez.addWidgetReplacement(new WidgetReplacement(new WidgetDetails(ComponentID.DIALOG_NPC_TEXT), "Hatius Cosaintus", "Hopleez"));
replacedHopleez.addWidgetReplacement(new WidgetReplacement(new WidgetDetails(ComponentID.DIALOG_SPRITE_TEXT), "Hatius", "Hopleez"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public ReplacedNpc createReplacedNpc(int[] model, WorldPoint wp, int npcIDToRepl
String groupID = "global";
ReplacedNpc extendedRuneliteObject = new ReplacedNpc(client, clientThread, wp, model, npcIDToReplace);
// Should this be here or a separate 'activate' step?
for (NPC clientNpc : client.getNpcs())
for (NPC clientNpc : client.getTopLevelWorldView().npcs())
{
if (clientNpc.getId() == npcIDToReplace)
{
Expand All @@ -209,7 +209,7 @@ public ReplacedNpc createReplacedNpc(String groupID, int[] model, WorldPoint wp,
{
ReplacedNpc extendedRuneliteObject = new ReplacedNpc(client, clientThread, wp, model, npcIDToReplace);
// Should this be here or a separate 'activate' step?
for (NPC clientNpc : client.getNpcs())
for (NPC clientNpc : client.getTopLevelWorldView().npcs())
{
if (clientNpc.getId() == npcIDToReplace)
{
Expand Down Expand Up @@ -287,6 +287,7 @@ boolean shouldDraw(Renderable renderable, boolean drawingUI)
ReplacedNpc replacedNpc = (ReplacedNpc) extendedRuneliteObject;
if (replacedNpc.getNpc() == npc)
{
replacedNpc.activate();
Point p = client.getMouseCanvasPosition();
boolean passesRequirementToShowReplacement = replacedNpc.getDisplayReq() == null || replacedNpc.getDisplayReq().check(client);
// is hovered
Expand Down Expand Up @@ -720,7 +721,7 @@ private void renderRedClick(Graphics2D graphics)

private boolean isNpcOnTile(ExtendedRuneliteObject extendedRuneliteObject)
{
for (NPC npc : client.getNpcs())
for (NPC npc : client.getTopLevelWorldView().npcs())
{
WorldPoint wpNpc = npc.getWorldLocation();
WorldPoint rlObjWp = WorldPoint.fromLocalInstance(client, extendedRuneliteObject.getRuneliteObject().getLocation());
Expand Down Expand Up @@ -776,6 +777,7 @@ public void onNpcDespawned(NpcDespawned event)
if (event.getNpc().getId() == replacedNpc.getNpcIDToReplace())
{
replacedNpc.setNpc(null);
replacedNpc.disable();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/questhelper/steps/MultiNpcStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected boolean npcIsCompositionMatch(NPC npc)
public void scanForNpcs()
{
super.scanForNpcs();
for (NPC npc : client.getNpcs())
for (NPC npc : client.getTopLevelWorldView().npcs())
{
addNpcToListGivenMatchingID(npc, this::npcIsCompositionMatch, baseNPCs);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/questhelper/steps/NpcStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void startUp()

public void scanForNpcs()
{
for (NPC npc : client.getNpcs())
for (NPC npc : client.getTopLevelWorldView().npcs())
{
addNpcToListGivenMatchingID(npc, this::npcPassesChecks, npcs);
}
Expand Down

0 comments on commit 1a84c2b

Please sign in to comment.