Interface DynamicRegistry<T>
- Type Parameters:
T
- The type of the registry entries
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:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A key for aProtocolObject
in aDynamicRegistry
. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @NotNull DynamicRegistry
<T> static <T> @NotNull DynamicRegistry
<T> create
(@NotNull String id, @NotNull BinaryTagSerializer<T> nbtType) Creates a new empty registry of the given type.static <T extends ProtocolObject>
@NotNull DynamicRegistry<T> create
(@NotNull String id, @NotNull BinaryTagSerializer<T> nbtType, @NotNull Registries registries, Registry.Resource resource) Creates a new empty registry of the given type.static <T extends ProtocolObject>
@NotNull DynamicRegistry<T> create
(@NotNull String id, @NotNull BinaryTagSerializer<T> nbtType, Registry.Resource resource, Registry.Container.Loader<T> loader) Creates a new empty registry of the given type.static <T extends ProtocolObject>
@NotNull DynamicRegistry<T> create
(@NotNull String id, @NotNull BinaryTagSerializer<T> nbtType, Registry.Resource resource, Registry.Container.Loader<T> loader, @Nullable Comparator<String> idComparator) Creates a new empty registry of the given type.get
(int id) default T
get
(@NotNull DynamicRegistry.Key<T> key) get
(@NotNull NamespaceID namespace) default int
getId
(@NotNull DynamicRegistry.Key<T> key) Returns the protocol ID associated with the givenDynamicRegistry.Key
, or -1 if none is registered.int
getId
(@NotNull NamespaceID id) Returns the protocol ID associated with the givenNamespaceID
, or -1 if none is registered.@Nullable DynamicRegistry.Key
<T> getKey
(int id) @Nullable DynamicRegistry.Key
<T> @Nullable NamespaceID
getName
(int id) @Nullable DataPack
getPack
(int id) default @Nullable DataPack
getPack
(@NotNull DynamicRegistry.Key<T> key) @NotNull String
id()
default DynamicRegistry.Key
<T> Register an object to this registry, overwriting the previous entry if any is present.default DynamicRegistry.Key
<T> default DynamicRegistry.Key
<T> register
(@NotNull NamespaceID id, T object) default DynamicRegistry.Key
<T> register
(@NotNull NamespaceID id, T object, @Nullable DataPack pack) @NotNull SendablePacket
registryDataPacket
(@NotNull Registries registries, boolean excludeVanilla) Returns aSendablePacket
potentially excluding vanilla entries if possible.boolean
remove
(@NotNull NamespaceID namespaceId) Removes an object from this registry.values()
Returns the entries in this registry as an immutable list.
-
Method Details
-
create
-
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
-
get
-
get
-
get
-
getKey
-
getKey
-
getName
-
getPack
-
getPack
-
getId
Returns the protocol ID associated with the givenNamespaceID
, or -1 if none is registered.- See Also:
-
getId
Returns the protocol ID associated with the givenDynamicRegistry.Key
, or -1 if none is registered.- See Also:
-
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
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
totrue
.- 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
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
totrue
.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 propertyminestom.registry.unsafe-remove
is not set totrue
-
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. viaregister(NamespaceID, T)
.- Parameters:
registries
- Registries providerexcludeVanilla
- Whether to exclude vanilla entries- Returns:
- A
SendablePacket
containing the registry data
-