Context Menu API
The context menu system provides OSRS-accurate right-click menus with colored entity names, manifest-driven actions, and centralized dispatching.InventoryActionDispatcher
Centralized inventory action dispatching. Location:packages/client/src/game/systems/InventoryActionDispatcher.ts
dispatchInventoryAction()
Dispatch an inventory action to the appropriate handler.action- The action ID (e.g., “eat”, “wield”, “drop”)ctx- Context containing world, itemId, slot, and optional quantity
ActionResult indicating success/failure
Example:
Supported Actions
| Action | Handler | Description |
|---|---|---|
eat | useItem network message | Consumes food, heals HP |
drink | ITEM_ACTION_SELECTED event | Consumes potion, applies effects |
bury | buryBones network message | Buries bones for Prayer XP |
wield | equipItem network message | Equips weapons/shields |
wear | equipItem network message | Equips armor |
drop | dropItem network message | Drops item on ground |
examine | UI_TOAST + chat message | Shows examine text |
use | ITEM_ACTION_SELECTED event | Enters targeting mode |
cancel | No-op | Closes menu |
Item Helpers
Type detection utilities for inventory actions. Location:packages/shared/src/utils/item-helpers.ts
Type Detection Functions
isFood()
Check if item is food (can be eaten).type === "consumable" + healAmount > 0 + not a potion
Example:
isPotion()
Check if item is a potion (can be drunk).type === "consumable" + id.includes("potion")
isBone()
Check if item is bones (can be buried).id === "bones" or id.endsWith("_bones")
isWeapon()
Check if item is a weapon.equipSlot === "weapon" or equipSlot === "2h" or is2h === true or weaponType != null
isShield()
Check if item is a shield.equipSlot === "shield"
usesWield()
Check if item uses “Wield” action (weapons + shields).isWeapon(item) || isShield(item)
usesWear()
Check if item uses “Wear” action (armor, not weapons/shields).equipable === true and not a weapon/shield
isNotedItem()
Check if item is a bank note.isNoted === true or id.endsWith("_noted")
Primary Action Detection
getPrimaryAction()
Get primary action using manifest-first approach with heuristic fallback.item- Item to checkisNoted- Whether item is a bank note
"eat" | "drink" | "bury" | "wield" | "wear" | "use"
Logic:
- If noted → return “use”
- Check
item.inventoryActions[0]if defined - Heuristic fallback based on item properties
- Final fallback → “use”
getPrimaryActionFromManifest()
Get primary action from manifest’sinventoryActions only.
inventoryActions array, or null if not defined
Example:
Context Menu Colors
Location:packages/shared/src/constants/GameConstants.ts
CONTEXT_MENU_COLORS
OSRS-accurate color constants for context menu entity names.Context Menu Action Structure
ContextMenuAction Interface
Interaction Handlers
Base class for all interaction handlers. Location:packages/shared/src/systems/client/interaction/handlers/BaseInteractionHandler.ts
BaseInteractionHandler
All handlers extend this base class:Handler Registry
| Handler | Entity Types | Primary Action |
|---|---|---|
ItemInteractionHandler | Ground items | Take |
NPCInteractionHandler | NPCs (bankers, shopkeepers) | Talk-to |
MobInteractionHandler | Hostile mobs | Attack |
PlayerInteractionHandler | Other players | Trade |
ResourceInteractionHandler | Trees, rocks, fishing spots | Chop/Mine/Fish |
BankInteractionHandler | Bank booths/chests | Bank |
CookingSourceInteractionHandler | Fires, ranges | Cook |
SmeltingSourceInteractionHandler | Furnaces | Smelt |
SmithingSourceInteractionHandler | Anvils | Smith |
CorpseInteractionHandler | Gravestones, corpses | Loot |
Manifest Integration
Item Manifest
Items can define explicitinventoryActions:
- First action becomes left-click default
- Actions are case-insensitive when dispatched
- If not specified, system uses heuristic detection
- Noted items always use [“Use”, “Drop”, “Examine”]
Supported Manifest Actions
Testing
InventoryActionDispatcher Tests
File:packages/client/src/game/systems/__tests__/InventoryActionDispatcher.test.ts
Coverage: 333 lines, 100% of all actions
Example:
Item Helpers Tests
File:packages/shared/src/utils/__tests__/item-helpers.test.ts
Coverage: 510 lines, all edge cases
Example: