From db4830e83a7dcd28ebfaf728d337ac63c570ac3c Mon Sep 17 00:00:00 2001 From: Levi Schuck Date: Sat, 21 Apr 2018 15:08:35 -0500 Subject: [PATCH] Sort Fishing spots by distance from camera The default sort of fishing spots ends up drawing further things on top of closer things, as it has no relation to the camera. To solve this, convert the camera point to a `LocalPoint` and then sort by comparing local points from the NPC to the camera's point. However, the sort is inverted by `-1 *` so that further things are drawn first, and closer things are drawn last--this way closer things are always on top. Fixes #1737 --- .../client/plugins/fishing/FishingPlugin.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/fishing/FishingPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/fishing/FishingPlugin.java index a1927e48c5..38afc85e86 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/fishing/FishingPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/fishing/FishingPlugin.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2017, Seth + * Copyright (c) 2018, Levi * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,13 +31,16 @@ import com.google.inject.Provides; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Comparator; import java.util.List; import javax.inject.Inject; import javax.inject.Singleton; import lombok.AccessLevel; import lombok.Getter; import net.runelite.api.ChatMessageType; +import net.runelite.api.Client; import net.runelite.api.NPC; +import net.runelite.api.coords.LocalPoint; import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.GameTick; @@ -61,6 +65,9 @@ public class FishingPlugin extends Plugin @Getter(AccessLevel.PACKAGE) private NPC[] fishingSpots; + @Inject + private Client client; + @Inject private QueryRunner queryRunner; @@ -174,8 +181,13 @@ public class FishingPlugin extends Plugin @Subscribe public void checkSpots(GameTick event) { - NPCQuery query = new NPCQuery() + final LocalPoint cameraPoint = new LocalPoint(client.getCameraX(), client.getCameraY()); + + final NPCQuery query = new NPCQuery() .idEquals(Ints.toArray(spotIds)); - fishingSpots = queryRunner.runQuery(query); + NPC[] spots = queryRunner.runQuery(query); + // -1 to make closer things draw last (on top of farther things) + Arrays.sort(spots, Comparator.comparing(npc -> -1 * npc.getLocalLocation().distanceTo(cameraPoint))); + fishingSpots = spots; } }