Platform: NPCTracker - Dani-error/velar GitHub Wiki

🎯 NPCTracker

Source Code
Default Implementation


📘 What is NPCTracker?

NPCTracker is responsible for tracking all spawned NPCs within the platform.
It manages storing, querying, and untracking NPC instances efficiently.


🔧 Interface Overview

Method / Property Description
val trackedNPCs: Collection<NPC<W, P, I, E>> Returns all currently tracked NPCs.
fun npcById(entityId: Int): NPC<W, P, I, E>? Finds a tracked NPC by its entity ID.
fun npcByUniqueId(uniqueId: UUID): NPC<W, P, I, E>? Finds a tracked NPC by its unique profile UUID.
fun trackNPC(npc: NPC<W, P, I, E>) Starts tracking a given NPC instance.
fun stopTrackingNPC(npc: NPC<W, P, I, E>) Stops tracking and removes the NPC.

🏗️ Default Implementation: CommonNPCTracker

The provided default tracker uses a thread-safe synchronized set internally to keep track of NPCs.
It provides efficient lookup by entity ID or UUID and basic add/remove tracking methods.

Create a new tracker like this:

val tracker = CommonNPCTracker.newNPCTracker<MyWorld, MyProfile, MyInteract, MyEvent>()

📌 Usage Example

tracker.trackNPC(myNpc) // start tracking an NPC
val foundNpc = tracker.npcById(123) // find by entity id
tracker.stopTrackingNPC(myNpc) // stop tracking

You can create your own custom tracker by implementing the NPCTracker interface to better suit your platform's requirements.

⚠️ **GitHub.com Fallback** ⚠️