Interface DynamicRegistry<T>

Type Parameters:
T - The type of the registry entries

public sealed interface DynamicRegistry<T>

Holds registry data for any of the registries controlled by the server. Entries in registries should be referenced using a DynamicRegistry.Key object as opposed to the record type. For example, a biome should be stored as `DynamicRegistry.Key Biome`, as opposed to `Biome` directly.

Builtin registries should be accessed via a Registries instance (currently implemented by ServerProcess, or from MinecraftServer static methods.

See Also:
  • Method Details

    • create

      @Internal @NotNull static <T> @NotNull DynamicRegistry<T> create(@NotNull @NotNull String id)
    • create

      @Internal @NotNull static <T> @NotNull DynamicRegistry<T> create(@NotNull @NotNull String id, @NotNull @NotNull BinaryTagSerializer<T> nbtType)
      Creates a new empty registry of the given type. Should only be used internally.
      See Also:
    • create

      @Internal @NotNull static <T extends ProtocolObject> @NotNull DynamicRegistry<T> create(@NotNull @NotNull String id, @NotNull @NotNull BinaryTagSerializer<T> nbtType, @NotNull Registry.Resource resource, @NotNull Registry.Container.Loader<T> loader)
      Creates a new empty registry of the given type. Should only be used internally.
      See Also:
    • create

      @Internal @NotNull static <T extends ProtocolObject> @NotNull DynamicRegistry<T> create(@NotNull @NotNull String id, @NotNull @NotNull BinaryTagSerializer<T> nbtType, @NotNull Registry.Resource resource, @NotNull Registry.Container.Loader<T> loader, @Nullable @Nullable Comparator<String> idComparator)
      Creates a new empty registry of the given type. Should only be used internally.
      See Also:
    • create

      @Internal @NotNull static <T extends ProtocolObject> @NotNull DynamicRegistry<T> create(@NotNull @NotNull String id, @NotNull @NotNull BinaryTagSerializer<T> nbtType, @NotNull @NotNull Registries registries, @NotNull Registry.Resource resource)
      Creates a new empty registry of the given type. Should only be used internally.
      See Also:
    • id

      @NotNull @NotNull String id()
    • get

      @Nullable T get(int id)
    • get

      @Nullable T get(@NotNull @NotNull NamespaceID namespace)
    • get

      @Nullable default T get(@NotNull @NotNull DynamicRegistry.Key<T> key)
    • getKey

      @Nullable @Nullable DynamicRegistry.Key<T> getKey(int id)
    • getKey

      @Nullable @Nullable DynamicRegistry.Key<T> getKey(@NotNull T value)
    • getName

      @Nullable @Nullable NamespaceID getName(int id)
    • getPack

      @Nullable @Nullable DataPack getPack(int id)
    • getPack

      @Nullable default @Nullable DataPack getPack(@NotNull @NotNull DynamicRegistry.Key<T> key)
    • getId

      int getId(@NotNull @NotNull NamespaceID id)
      Returns the protocol ID associated with the given NamespaceID, or -1 if none is registered.
      See Also:
    • getId

      default int getId(@NotNull @NotNull DynamicRegistry.Key<T> key)
      Returns the protocol ID associated with the given DynamicRegistry.Key, or -1 if none is registered.
      See Also:
    • values

      @NotNull @NotNull List<T> values()

      Returns the entries in this registry as an immutable list. The indices in the returned list correspond to the protocol ID of each entry.

      Note: The returned list is not guaranteed to update with the registry, it should be fetched again for updated values.

      Returns:
      An immutable list of the entries in this registry.
    • register

      @NotNull default DynamicRegistry.Key<T> register(@NotNull @NotNull String id, @NotNull T object)

      Register an object to this registry, overwriting the previous entry if any is present.

      Note: the new registry will not be sent to existing players. They must be returned to the configuration phase to receive new registry data. See Player.startConfigurationPhase().

      WARNING: Updating an existing entry is an inherently unsafe operation as it may cause desync with existing structures. This behavior is disabled by default, and must be enabled by setting the system property minestom.registry.unsafe-ops to true.

      Parameters:
      object - The entry to register
      Returns:
      The new ID of the registered object
    • register

      @NotNull default DynamicRegistry.Key<T> register(@NotNull @NotNull NamespaceID id, @NotNull T object)
    • register

      @Internal @NotNull default DynamicRegistry.Key<T> register(@NotNull @NotNull String id, @NotNull T object, @Nullable @Nullable DataPack pack)
    • register

      @Internal @NotNull default DynamicRegistry.Key<T> register(@NotNull @NotNull NamespaceID id, @NotNull T object, @Nullable @Nullable DataPack pack)
    • remove

      boolean remove(@NotNull @NotNull NamespaceID namespaceId) throws UnsupportedOperationException

      Removes an object from this registry.

      WARNING: This operation will cause all subsequent IDs to be remapped, meaning that any loaded entry with existing IDs may be incorrect. For example, loading a world with 0=plains, 1=desert, 2=badlands would store those IDs in the palette. If you then deleted entry 1 (desert), any desert biomes in the loaded world would become badlands, and any badlands would become invalid. This behavior is disabled by default, and must be enabled by setting the system property minestom.registry.unsafe-ops to true.

      Note: the new registry will not be sent to existing players. They must be returned to the configuration phase to receive new registry data. See Player.startConfigurationPhase().

      Parameters:
      namespaceId - The id of the entry to remove
      Returns:
      True if the object was removed, false if it was not present
      Throws:
      UnsupportedOperationException - If the system property minestom.registry.unsafe-remove is not set to true
    • registryDataPacket

      @Internal @NotNull @NotNull SendablePacket registryDataPacket(boolean excludeVanilla)

      Returns a SendablePacket potentially excluding vanilla entries if possible. It is never possible to exclude vanilla entries if one has been overridden (e.g. via register(NamespaceID, T).

      Parameters:
      excludeVanilla - Whether to exclude vanilla entries
      Returns:
      A SendablePacket containing the registry data