Class EntityTrackerRegistry

java.lang.Object
kr.toxicity.model.api.tracker.EntityTrackerRegistry

public final class EntityTrackerRegistry extends Object
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
  • Method Details

    • registry

      @Nullable public static @Nullable EntityTrackerRegistry registry(@NotNull @NotNull UUID uuid)
      Retrieves a registry by entity UUID.
      Parameters:
      uuid - the entity UUID
      Returns:
      the registry, or null if not found
      Since:
      1.15.2
    • registry

      @Nullable public static @Nullable EntityTrackerRegistry registry(int id)
      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

      public static void registries(@NotNull @NotNull Consumer<EntityTrackerRegistry> consumer)
      Iterates over all active registries.
      Parameters:
      consumer - the consumer to apply
      Since:
      1.15.2
    • registries

      @NotNull public static @NotNull @Unmodifiable List<EntityTrackerRegistry> 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

      @NotNull public @NotNull BaseEntity entity()
      Returns the source entity.
      Returns:
      the entity
      Since:
      1.15.2
    • uuid

      @NotNull public @NotNull UUID 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

      @NotNull public @NotNull @Unmodifiable Collection<EntityTracker> trackers()
      Returns all trackers in this registry.
      Returns:
      the trackers
      Since:
      1.15.2
    • tracker

      @Nullable public @Nullable EntityTracker tracker(@Nullable @Nullable String key)
      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

      @Nullable public @Nullable EntityTracker 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

      public boolean remove(@NotNull @NotNull String key)
      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

      public boolean close(@NotNull Tracker.CloseReason reason)
      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

      public void load(@NotNull @NotNull Stream<TrackerData> stream)
      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

      @NotNull public @NotNull Stream<ModelDisplay> 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

      public boolean isSpawned(@NotNull @NotNull PlatformPlayer player)
      Checks if any tracker is spawned for a player.
      Parameters:
      player - the player
      Returns:
      true if spawned
      Since:
      1.15.2
    • isSpawned

      public boolean isSpawned(@NotNull @NotNull UUID uuid)
      Checks if any tracker is spawned for a player UUID.
      Parameters:
      uuid - the player UUID
      Returns:
      true if spawned
      Since:
      1.15.2
    • spawn

      public boolean spawn(@NotNull @NotNull PlatformPlayer player)
      Spawns trackers for a player.
      Parameters:
      player - the player
      Returns:
      true if spawned successfully
      Since:
      1.15.2
    • spawnIfNotSpawned

      public boolean spawnIfNotSpawned(@NotNull @NotNull PlatformPlayer player)
      Spawns trackers for a player only if not already spawned.
      Parameters:
      player - the player
      Returns:
      true if spawned successfully
      Since:
      1.15.2
    • viewedPlayer

      @NotNull public @NotNull Stream<PlayerChannelHandler> viewedPlayer()
      Returns a stream of all players viewing this registry.
      Returns:
      the players
      Since:
      1.15.2
    • remove

      public boolean remove(@NotNull @NotNull PlatformPlayer player)
      Removes a player from viewing this registry.
      Parameters:
      player - the player
      Returns:
      true if removed successfully
      Since:
      1.15.2
    • hideOption

      @NotNull public @NotNull EntityHideOption hideOption(@NotNull @NotNull UUID uuid)
      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

      @NotNull public @NotNull @Unmodifiable Collection<HitBox> 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