Interface DynamicRegistry<T>

Type Parameters:
T - The type of the registry entries
All Superinterfaces:
net.kyori.adventure.key.Keyed, Registry<T>

public sealed interface DynamicRegistry<T> extends Registry<T>

Holds registry data for any of the registries controlled by the server. Entries in registries should be referenced using a RegistryKey object as opposed to the record type. For example, a biome should be stored as `RegistryKey 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

    • fromMap

      @SafeVarargs @NotNull static <T> @NotNull DynamicRegistry<T> fromMap(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull Map.Entry<net.kyori.adventure.key.Key, T>... entries)
    • create

      @Internal @NotNull static <T> @NotNull DynamicRegistry<T> create(@NotNull @NotNull net.kyori.adventure.key.Key key)
    • create

      @Internal @NotNull static <T> @NotNull DynamicRegistry<T> create(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull @NotNull Codec<T> codec)
      Creates a new empty registry of the given type. Should only be used internally.
      See Also:
    • create

      @Internal @NotNull static <T> @NotNull DynamicRegistry<T> create(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull @NotNull Codec<T> codec, @NotNull RegistryData.Resource resource)
      Creates a new registry of the given type. Should only be used internally.
      See Also:
    • create

      @Internal @NotNull static <T> @NotNull DynamicRegistry<T> create(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull @NotNull Codec<T> codec, @Nullable @Nullable Registries registries, @NotNull RegistryData.Resource resource)
      Creates a new registry of the given type. Should only be used internally.
      See Also:
    • create

      @Internal @NotNull static <T> @NotNull DynamicRegistry<T> create(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull @NotNull Codec<T> codec, @Nullable @Nullable Registries registries, @NotNull RegistryData.Resource resource, @Nullable @Nullable Comparator<String> idComparator, @Nullable @Nullable Codec<T> readCodec)
      Creates a new registry of the given type. Should only be used internally.
      See Also:
    • createForEnchantmentsWithSelfReferentialLoadingNightmare

      @Internal @NotNull static @NotNull DynamicRegistry<Enchantment> createForEnchantmentsWithSelfReferentialLoadingNightmare(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull @NotNull Codec<Enchantment> codec, @NotNull RegistryData.Resource resource, @NotNull @NotNull Registries registries)
    • register

      @NotNull default @NotNull RegistryKey<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 @NotNull RegistryKey<T> register(@NotNull @NotNull net.kyori.adventure.key.Key id, @NotNull T object)
    • register

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

      @Internal @NotNull @NotNull RegistryKey<T> register(@NotNull @NotNull net.kyori.adventure.key.Key id, @NotNull T object, @Nullable @Nullable DataPack pack)
    • remove

      boolean remove(@NotNull @NotNull net.kyori.adventure.key.Key key) 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:
      key - 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(@NotNull @NotNull Registries registries, 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(Key, T).

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