Item Highlighter

AdvancedOverlay

Highlights specific items on the ground. Shows how to iterate through tiles and draw highlights.

20 min read

What It Does

Highlights specific items on the ground. Shows how to iterate through tiles and draw highlights.

Source Code

java
1package com.example;
2
3import net.runelite.api.Client;
4import net.runelite.api.events.ItemSpawned;
5import net.runelite.api.events.ItemDespawned;
6import net.runelite.api.TileItem;
7import net.runelite.api.coords.WorldPoint;
8import net.runelite.client.eventbus.Subscribe;
9import net.runelite.client.ui.overlay.Overlay;
10import net.runelite.client.ui.overlay.OverlayManager;
11import net.runelite.client.ui.overlay.OverlayLayer;
12import net.runelite.client.plugins.Plugin;
13import net.runelite.client.plugins.PluginDescriptor;
14import javax.inject.Inject;
15import java.awt.*;
16import java.util.HashSet;
17import java.util.Set;
18
19@PluginDescriptor(
20    name = "Item Highlighter",
21    description = "Highlights items on ground"
22)
23public class ItemHighlighterPlugin extends Plugin {
24    @Inject
25    private Client client;
26
27    @Inject
28    private OverlayManager overlayManager;
29
30    private final int[] highlightedItems = {995, 385}; // Coins, Shark
31    private final Set<TileItem> trackedItems = new HashSet<>();
32
33    @Subscribe
34    public void onItemSpawned(ItemSpawned event) {
35        TileItem item = event.getItem();
36        for (int itemId : highlightedItems) {
37            if (item.getId() == itemId) {
38                trackedItems.add(item);
39                break;
40            }
41        }
42    }
43
44    @Subscribe
45    public void onItemDespawned(ItemDespawned event) {
46        trackedItems.remove(event.getItem());
47    }
48
49    private final Overlay overlay = new Overlay() {
50        @Override
51        public Dimension render(Graphics2D graphics) {
52            // Only render tracked items (much better performance)
53            for (TileItem item : trackedItems) {
54                WorldPoint worldPoint = item.getTile().getWorldLocation();
55                net.runelite.api.coords.LocalPoint localPoint = 
56                    net.runelite.api.coords.LocalPoint.fromWorld(client, worldPoint);
57                if (localPoint != null) {
58                    Point screenPoint = net.runelite.api.Perspective
59                        .localToCanvas(client, localPoint, client.getPlane());
60                    if (screenPoint != null) {
61                        graphics.setColor(new Color(255, 255, 0, 100));
62                        graphics.fillOval(screenPoint.x - 10, screenPoint.y - 10, 20, 20);
63                        graphics.setColor(Color.YELLOW);
64                        graphics.drawOval(screenPoint.x - 10, screenPoint.y - 10, 20, 20);
65                    }
66                }
67            }
68
69            return null;
70        }
71    };
72
73    {
74        overlay.setLayer(OverlayLayer.ABOVE_SCENE);
75    }
76
77    @Override
78    protected void startUp() {
79        overlayManager.add(overlay);
80    }
81
82    @Override
83    protected void shutDown() {
84        overlayManager.remove(overlay);
85    }
86}

Code Annotations

Line 25

Array of item IDs to highlight

Line 32

Iterate through all tiles in scene

Line 37

Check if tile has ground items

Line 40

Draw highlight circle

API Classes Used

Client
ItemSpawned
ItemDespawned
Overlay

Key Concepts

  • Array of item IDs to highlight
  • Iterate through all tiles in scene
  • Check if tile has ground items
  • Draw highlight circle

Next Steps

  • Learn about Scene and Tile API
  • Filter items by ID
  • Add configurable item list