Platform: NPCTracker - Dani-error/velar GitHub Wiki
Source Code
Default Implementation
NPCTracker
is responsible for tracking all spawned NPCs within the platform.
It manages storing, querying, and untracking NPC instances efficiently.
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. |
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>()
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.