Package kr.toxicity.model.api.tracker
Class EntityTrackerRegistry
java.lang.Object
kr.toxicity.model.api.tracker.EntityTrackerRegistry
Manages all entity trackers for a specific entity.
This registry handles the lifecycle of trackers attached to an entity, including loading, saving, spawning, and despawning. It acts as a central hub for accessing and manipulating models on an entity.
- Since:
- 1.15.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents a hitbox that has an entity mounted on it. -
Method Summary
Modifier and TypeMethodDescriptionbooleanclose()Closes the registry.booleanclose(Tracker.CloseReason reason) Closes the registry with a specific reason.@NotNull EntityTrackercreate(@NotNull String key, @NotNull Function<EntityTrackerRegistry, EntityTracker> supplier) Creates a new tracker in this registry.voiddespawn()Despawns all trackers in the registry.@NotNull Stream<ModelDisplay> displays()Returns a stream of all displays from all trackers.@NotNull BaseEntityentity()Returns the source entity.@Nullable EntityTrackerfirst()Returns the first tracker in the registry.@NotNull EntityTrackergetOrCreate(@NotNull String key, @NotNull Function<EntityTrackerRegistry, EntityTracker> supplier) Gets or creates a tracker in this registry.static @NotNull EntityTrackerRegistrygetOrCreate(@NotNull BaseEntity entity) Gets or creates a registry for a base entity.booleanChecks if any hitbox has a controlling passenger.booleanChecks if any hitbox has a passenger.@NotNull EntityHideOptionhideOption(@NotNull UUID uuid) Returns the hide option for a specific player.@NotNull @Unmodifiable Collection<HitBox> hitBoxes()Returns a collection of all active hitboxes for this registry.intid()Returns the entity ID.booleanisClosed()Checks if the registry is closed.booleanChecks if any tracker is spawned for a player UUID.booleanisSpawned(@NotNull PlatformPlayer player) Checks if any tracker is spawned for a player.voidload()Loads trackers from the entity's persistent data.voidload(@NotNull Stream<TrackerData> stream) Loads trackers from a stream of data.@NotNull @Unmodifiable Map<UUID, EntityTrackerRegistry.MountedHitBox> Returns the map of currently mounted hitboxes.voidrefresh()Refreshes the registry state.static @NotNull @Unmodifiable List<EntityTrackerRegistry> Returns a list of all active registries.static voidregistries(@NotNull Consumer<EntityTrackerRegistry> consumer) Iterates over all active registries.static @Nullable EntityTrackerRegistryregistry(int id) Retrieves a registry by entity ID.static @Nullable EntityTrackerRegistryRetrieves a registry by entity UUID.static @Nullable EntityTrackerRegistryregistry(@NotNull BaseEntity entity) Retrieves a registry for a base entity.voidreload()Reloads the registry, refreshing all trackers.booleanRemoves a tracker from the registry.booleanremove(@NotNull PlatformPlayer player) Removes a player from viewing this registry.voidsave()Saves the current tracker state to the entity's persistent data.@NotNull com.google.gson.JsonArraySerializes the registry state to a JSON array.booleanspawn(@NotNull PlatformPlayer player) Spawns trackers for a player.booleanspawnIfNotSpawned(@NotNull PlatformPlayer player) Spawns trackers for a player only if not already spawned.@Nullable EntityTrackerRetrieves a tracker by key.@NotNull @Unmodifiable Collection<EntityTracker> trackers()Returns all trackers in this registry.@NotNull UUIDuuid()Returns the entity UUID.@NotNull Stream<PlayerChannelHandler> Returns a stream of all players viewing this registry.
-
Method Details
-
registry
Retrieves a registry by entity UUID.- Parameters:
uuid- the entity UUID- Returns:
- the registry, or null if not found
- Since:
- 1.15.2
-
registry
Retrieves a registry by entity ID.- Parameters:
id- the entity ID- Returns:
- the registry, or null if not found
- Since:
- 1.15.2
-
registry
@Nullable public static @Nullable EntityTrackerRegistry registry(@NotNull @NotNull BaseEntity entity) Retrieves a registry for a base entity.- Parameters:
entity- the base entity- Returns:
- the registry, or null if the entity has no model data
- Since:
- 1.15.2
-
registries
Iterates over all active registries.- Parameters:
consumer- the consumer to apply- Since:
- 1.15.2
-
registries
Returns a list of all active registries.- Returns:
- the list of registries
- Since:
- 1.15.2
-
getOrCreate
@Internal @NotNull public static @NotNull EntityTrackerRegistry getOrCreate(@NotNull @NotNull BaseEntity entity) Gets or creates a registry for a base entity.- Parameters:
entity- the base entity- Returns:
- the registry
- Since:
- 1.15.2
-
entity
Returns the source entity.- Returns:
- the entity
- Since:
- 1.15.2
-
uuid
Returns the entity UUID.- Returns:
- the UUID
- Since:
- 1.15.2
-
id
public int id()Returns the entity ID.- Returns:
- the ID
- Since:
- 1.15.2
-
trackers
Returns all trackers in this registry.- Returns:
- the trackers
- Since:
- 1.15.2
-
tracker
Retrieves a tracker by key.- Parameters:
key- the key (model ID), or null for the first tracker- Returns:
- the tracker, or null if not found
- Since:
- 1.15.2
-
first
Returns the first tracker in the registry.- Returns:
- the first tracker, or null if empty
- Since:
- 1.15.2
-
create
@Internal @NotNull public @NotNull EntityTracker create(@NotNull @NotNull String key, @NotNull @NotNull Function<EntityTrackerRegistry, EntityTracker> supplier) Creates a new tracker in this registry.- Parameters:
key- the key (model ID)supplier- the supplier to create the tracker- Returns:
- the created tracker
- Since:
- 1.15.2
-
getOrCreate
@Internal @NotNull public @NotNull EntityTracker getOrCreate(@NotNull @NotNull String key, @NotNull @NotNull Function<EntityTrackerRegistry, EntityTracker> supplier) Gets or creates a tracker in this registry.- Parameters:
key- the key (model ID)supplier- the supplier to create the tracker- Returns:
- the tracker
- Since:
- 1.15.2
-
remove
Removes a tracker from the registry.- Parameters:
key- the key (model ID)- Returns:
- true if removed successfully
- Since:
- 1.15.2
-
isClosed
public boolean isClosed()Checks if the registry is closed.- Returns:
- true if closed
- Since:
- 1.15.2
-
close
public boolean close()Closes the registry.- Returns:
- true if closed successfully
- Since:
- 1.15.2
-
close
Closes the registry with a specific reason.- Parameters:
reason- the close reason- Returns:
- true if closed successfully
- Since:
- 1.15.2
-
reload
public void reload()Reloads the registry, refreshing all trackers.- Since:
- 1.15.2
-
refresh
public void refresh()Refreshes the registry state.- Since:
- 1.15.2
-
despawn
public void despawn()Despawns all trackers in the registry.- Since:
- 1.15.2
-
load
Loads trackers from a stream of data.- Parameters:
stream- the data stream- Since:
- 1.15.2
-
load
public void load()Loads trackers from the entity's persistent data.- Since:
- 1.15.2
-
save
public void save()Saves the current tracker state to the entity's persistent data.- Since:
- 1.15.2
-
displays
Returns a stream of all displays from all trackers.- Returns:
- the displays
- Since:
- 1.15.2
-
serialize
@NotNull public @NotNull com.google.gson.JsonArray serialize()Serializes the registry state to a JSON array.- Returns:
- the JSON array
- Since:
- 1.15.2
-
isSpawned
Checks if any tracker is spawned for a player.- Parameters:
player- the player- Returns:
- true if spawned
- Since:
- 1.15.2
-
isSpawned
Checks if any tracker is spawned for a player UUID.- Parameters:
uuid- the player UUID- Returns:
- true if spawned
- Since:
- 1.15.2
-
spawn
Spawns trackers for a player.- Parameters:
player- the player- Returns:
- true if spawned successfully
- Since:
- 1.15.2
-
spawnIfNotSpawned
Spawns trackers for a player only if not already spawned.- Parameters:
player- the player- Returns:
- true if spawned successfully
- Since:
- 1.15.2
-
viewedPlayer
Returns a stream of all players viewing this registry.- Returns:
- the players
- Since:
- 1.15.2
-
remove
Removes a player from viewing this registry.- Parameters:
player- the player- Returns:
- true if removed successfully
- Since:
- 1.15.2
-
hideOption
Returns the hide option for a specific player.- Parameters:
uuid- the player UUID- Returns:
- the hide option
- Since:
- 1.15.2
-
mountedHitBox
@NotNull public @NotNull @Unmodifiable Map<UUID,EntityTrackerRegistry.MountedHitBox> mountedHitBox()Returns the map of currently mounted hitboxes.- Returns:
- the mounted hitboxes
- Since:
- 1.15.2
-
hitBoxes
Returns a collection of all active hitboxes for this registry.- Returns:
- the hitboxes
- Since:
- 2.2.0
-
hasPassenger
public boolean hasPassenger()Checks if any hitbox has a passenger.- Returns:
- true if there is a passenger
- Since:
- 1.15.2
-
hasControllingPassenger
public boolean hasControllingPassenger()Checks if any hitbox has a controlling passenger.- Returns:
- true if there is a controlling passenger
- Since:
- 1.15.2
-