docs.dev

SDK Game Reference

The game, entities, and threaded packages — world-state facades, actor/tile interaction, sailing, and tick-blocking helpers for worker-thread automation.

World-state reading and acting: the game package (camera, combat, movement, scene, skills, vars, quests, worlds, sailing), the entities package (actor/tile interaction facades), and the threaded package (tick-blocking helpers for NPlugin.loop() automation). Widget-side interaction lives in SDK Widgets Reference. Source of truth: docs/sdk-game-reference.md in the n3Client repository.

Entities (api/src/main/java/dev/n3u/api/entities/)

FacadeSurface (extracted 2026-11-06)
ActorAPIstatic ActorEx getInCombatWith()
NpcAPIsearch() → NpcQuery; interact(NpcEx, int), interact(NpcEx, String...), interact(int npcIndex, int option)
PlayerAPIsearch(), interact(2), getLocal(), isIdle()
TileItemAPIsearch(); interact(TileItemEx, int), interact(item, action, ctrlDown), interact(3/4/5)
TileObjectAPIsearch() → TileObjectQuery; interact(2); getActions(object); get(1), getContains(1)

Verified control flow for every interact: resolve the menu index, then Static.invoke(() -> { ClickManager.click(ClickType.X); client.getPacketWriter().<family>Packet(...); }) — e.g. NpcAPI.interact(int, int) at NpcAPI.java:66-73 sends npcActionPacket(option, npcIndex, false) and WidgetAPI.interact(int, int, int, int) at WidgetAPI.java:76-84 sends widgetActionPacket. Null targets are no-ops (NpcAPI.interact(NpcEx, ...) returns when npc == null).

Game facades (api/src/main/java/dev/n3u/api/game/)

Method names extracted from source 2026-11-06 (counts omitted — they drift with edits; the line-cited signatures were individually verified).

FacadeCoverage
MovementAPIgetDestinationWorldPoint, getRunEnergy, isRunEnabled, toggleRun, staminaInEffect, isMoving, walkToWorldPoint (3 overloads, MovementAPI.java:100-115), walkAproxWorldPoint, walkRelativeToWorldPoint, walkTowards, cardinalWalk, canPathTo; movement interactions fire ClickManager.click(ClickType.MOVEMENT) (MovementAPI.java:120)
SceneAPIreachableTiles, getAll, getAt, getSurrounding, getHoveredTile, pathTo, checkPointsTo, isReachable, filterReachable, hasLineOfSightTo, losTileNextTo, getTile
CombatAPIretaliate toggle, poison/venom/antifire states, spec energy/toggle, teleblock ticks, setAttackStyle/getAttackStyle, getHealth, inMultiWay, isInPvpArea
SkillAPIgetLevel, getBoostedLevel, getExperience(At), getExperienceToNextLevel, getTotalLevel(Boosted), getRewardWidget, canSelectReward
VarAPIgetVar, getVarp, getVarcInteger, getVarcString, setVarcInteger, setVarcString, setVar
GameAPIlogout, getWildyLevel, isLoggedIn, isOnLoginScreen, getPlaytimeInMinutes, getMembershipDays, isInCutscene, isScreenFading, invokeMenuAction (5- and 6-parameter overloads; generic clicks with ClickType.GENERIC, GameAPI.java:157,175)
CameraAPIyaw/pitch get/set (units and degrees), rotate*, turn*, tilt*, lookAt, face*, reset, getCompassDirection, isMoving, deltas
QuestAPIgetState, getQuests, isCompleted, isInProgress, isNotStarted, hasState
WorldsAPIgetCurrentWorld, createDefaultQuery, hop and hopRandomMembers/hopRandomF2p/hopNextMembers/hopPreviousMembers/hopNextF2p/hopPreviousF2p — each returns a StepHandler to execute on a worker thread; inMembersWorld
ClientScriptAPIcloseNumericInputDialogue, switchTabs, runScript — raw clientscript invocation
HouseAPI / HouseOptionsAPIoutside location; building mode, teleport-inside, door render mode

Sailing (api/src/main/java/dev/n3u/api/game/sailing/)

SailingAPI (boat state incl. isOnBoat(), SailingAPI.java:155, helm varbit check :72, navigation actions), BoatStatsAPI, Heading, MoveMode, NoticeBoardAPI, SailingRenderUtil, SailingTab. Boat pathing itself lives in the pathfinder module (SDK Pathfinder Reference).

Threaded helpers (api/src/main/java/dev/n3u/api/threaded/)

For NPlugin.loop()-style worker-thread automation. All of these sleep and therefore throw on the client thread.

  • Delays — tick()/tick(int) sleep until GameManager.getTickCount() advances, aborting with RuntimeException("Task cancelled") when the task is interrupted/cancelled; wait(ms) hard-refuses the client thread via a stack-trace exception; waitUntil(Supplier) (void), waitUntil(Supplier, long timeoutMS) / waitUntil(Supplier, int ticks) (both two-argument; no three-argument form), waitUntilIdle(), waitUntilOnTile(2) (api/src/main/java/dev/n3u/api/threaded/Delays.java).
  • Dialogues — processDialogues() / processDialogues(String... options), waitForDialogues(), continueAllDialogue(): tick-driven dialogue advancement.
  • Cannon — place/spot/reload/repair/pickup, ballsLeft, isPlaced, ensure() convenience, cachedIsPlaced.
  • GrandExchange — buy(id, quantity, boolean noted) (GrandExchange.java:100), buy(id, quantity, boolean noted, int tries) (:21), and the price-based buy(id, quantity, int price) (:51) / buy(id, quantity, int price, boolean noted) (:75); sell(id, quantity, boolean immediate) (:156): full offer workflows with waiting.
  • Minigames — teleport/hop helpers over the minigame tab: canTeleport, teleport(1), open, hopToSuggestedWorld, isOpen/isTabOpen, getLastMinigameTeleportUsage, Destination lookup.

Data and control flow

Read facades query Client/wrapper state directly; write facades hop to the client thread with Static.invoke and emit one packet each. Actor index-based sends (interact(int index, int option)) use the client's current index allocation — the actor-wrapper overloads resolve getIndex() on the calling thread at call time, and only the packet send hops to the client thread via Static.invoke (NpcAPI.java:29-35, PlayerAPI.java:31-34); never reuse indices from a previous tick.

Callers

NPlugin subclasses in plugins/ (e.g. plugins/src/main/java/dev/n3u/plugins/breakhandler/BreakHandlerPlugin.java), the Script DSL examples, handler builders, and WalkerPath's step engine (dialogue, prayer, inventory interactions during walks).

Worked example — combat loop with safe thread usage

import dev.n3u.api.entities.NpcAPI;
import dev.n3u.api.entities.PlayerAPI;
import dev.n3u.api.threaded.Delays;
import dev.n3u.data.wrappers.NpcEx;
import dev.n3u.util.NPlugin;
import net.runelite.client.plugins.PluginDescriptor;

@PluginDescriptor(name = "Cow kicker")
public class CowKickerPlugin extends NPlugin
{
    @Override
    public void loop() throws Exception
    {
        if (PlayerAPI.isIdle())                       // cheap read, worker thread OK
        {
            NpcEx cow = NpcAPI.search()
                    .withName("Cow")
                    .alive()
                    .sortNearest()
                    .first();
            if (cow != null)
            {
                NpcAPI.interact(cow, "Attack");       // hops to client thread internally
            }
        }
        Delays.tick();                                // sleep one game tick; throws if cancelled
    }
}

Expected result: while idle, the nearest living cow is attacked; the loop consumes one tick per iteration. Failure handling: no target → first() returns null and the loop retries next tick; cancellation (haltLoop) surfaces as RuntimeException("Task cancelled") from Delays.tick() and NPlugin logs it as an interruption (api/src/main/java/dev/n3u/util/NPlugin.java:43-49).

Thread affinity summary

  • Reads (isIdle, search()...first(), var/skill getters): cheap, usable from any thread, but evaluate close to use.
  • Writes (interact*, walkToWorldPoint, camera setters): wrap their packets in Static.invoke — safe from worker threads; never sleep inside them.
  • threaded package: worker-thread only; Delays.wait throws on the client thread.

Tests

No entity/game/threaded class has a dedicated automated test (git ls-files "api/src/test/java", 2026-11-06 — only widget, pathfinder-map, and UI tests exist). The repository tracks a follow-up for fixture tests of at least MovementAPI destination math and Delays tick/cancel semantics.

Known limits

  • GrandExchange/Minigames/Cannon workflows embed internal waits; their timeouts are constants in source, not config — treat long stalls as workflow failure and re-run.
  • CameraAPI writes animate toward targets; setters set goals, not instant orientations (target-vs-current getter pairs in the surface list).
  • QuestAPI/SkillAPI reward-widget members depend on interface layout of the current gamepack (open question: not exercised live in this documentation pass).

On this page