Class DynamicRegistries
Basic usage
Custom dynamic registries can be registered withregister(ResourceKey, Codec). These registries will not be
synced to the client.
The list of all world registries, whether from vanilla or mods, can be accessed using
getWorldRegistries().
The list of all bootstrapping registries, whether from vanilla or mods, can be accessed using
* getBootstrappingRegistries().
Tags for the entries of a custom registry must be placed in
/tags/<registry namespace>/<registry path>/. For example, the tags for the example
registry below would be placed in /tags/my_mod/my_data/.
Synchronization
Dynamic registries are not synchronized to the client by default. To register a synced dynamic registry, you can replace theregister(ResourceKey, Codec) call
with a call to registerSynced(ResourceKey, Codec, SyncOption...).
If you want to use a different codec for syncing, e.g. to skip unnecessary data,
you can use the overload with two codecs: registerSynced(ResourceKey, Codec, Codec, SyncOption...).
Synced dynamic registries can also be prevented from syncing if they have no entries.
This is useful for compatibility with clients that might not have your dynamic registry.
This behavior can be enabled by passing the DynamicRegistries.SyncOption.SKIP_WHEN_EMPTY flag to registerSynced.
Examples
public static final ResourceKey<Registry<MyData>> MY_DATA_KEY = ResourceKey.create(Identifier.fromNamespaceAndPath("modid", "my_data"));
// Option 1: Register a non-synced registry
DynamicRegistries.register(MY_DATA_KEY, MyData.CODEC);
// Option 2a: Register a synced registry
DynamicRegistries.registerSynced(MY_DATA_KEY, MyData.CODEC);
// Option 2b: Register a synced registry with a different network codec
DynamicRegistries.registerSynced(MY_DATA_KEY, MyData.CODEC, MyData.NETWORK_CODEC);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumFlags for configuring dynamic registry syncing. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Unmodifiable List<net.minecraft.resources.RegistryDataLoader.RegistryData<?>> Returns an unmodifiable list of all bootstrapping dynamic registries, including modded ones.static @Unmodifiable List<net.minecraft.resources.RegistryDataLoader.RegistryData<?>> Deprecated.static @Unmodifiable List<net.minecraft.resources.RegistryDataLoader.RegistryData<?>> Returns an unmodifiable list of all world registries, including modded ones.static <T> voidregister(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> key, com.mojang.serialization.Codec<T> codec) Registers a non-synced dynamic registry.static <T> voidregisterSynced(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> key, com.mojang.serialization.Codec<T> serverCodec, com.mojang.serialization.Codec<T> clientCodec, DynamicRegistries.SyncOption... options) Registers a synced dynamic registry.static <T> voidregisterSynced(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> key, com.mojang.serialization.Codec<T> codec, DynamicRegistries.SyncOption... options) Registers a synced dynamic registry.
-
Method Details
-
getWorldRegistries
public static @Unmodifiable List<net.minecraft.resources.RegistryDataLoader.RegistryData<?>> getWorldRegistries()Returns an unmodifiable list of all world registries, including modded ones.The list will not reflect any changes caused by later registrations.
- Returns:
- an unmodifiable list of all dynamic registries
- API Note:
- A world registry is defined as a registry which is loaded from datapacks.
Those registries are loaded by the game at different times, and some are not patched.
-
getBootstrappingRegistries
public static @Unmodifiable List<net.minecraft.resources.RegistryDataLoader.RegistryData<?>> getBootstrappingRegistries()Returns an unmodifiable list of all bootstrapping dynamic registries, including modded ones.The list will not reflect any changes caused by later registrations.
- Returns:
- an unmodifiable list of all bootstrapping registries
- API Note:
- A bootstrapping registry is defined as a registry with entries being data generated in vanilla from its own registry builder.
Those registries are the ones that should be built for data generation backends.
For example, it does not include theminecraft:dimensionregistry.
-
getDynamicRegistries
@Deprecated public static @Unmodifiable List<net.minecraft.resources.RegistryDataLoader.RegistryData<?>> getDynamicRegistries()Deprecated.Either usegetWorldRegistries()if you wish to get all world registries, includingminecraft:dimension, or usegetBootstrappingRegistries()if you wish to avoid the latter. -
register
public static <T> void register(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> key, com.mojang.serialization.Codec<T> codec) Registers a non-synced dynamic registry.The entries of the registry will be loaded from data packs at the file path
data/<entry namespace>/<registry namespace>/<registry path>/<entry path>.json.- Type Parameters:
T- the entry type of the registry- Parameters:
key- the unique key of the registrycodec- the codec used to load registry entries from data packs
-
registerSynced
public static <T> void registerSynced(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> key, com.mojang.serialization.Codec<T> codec, DynamicRegistries.SyncOption... options) Registers a synced dynamic registry.The entries of the registry will be loaded from data packs at the file path
data/<entry namespace>/<registry namespace>/<registry path>/<entry path>.json.The registry will be synced from the server to players' clients using the same codec that is used to load the registry.
If the object contained in the registry is complex and contains a lot of data that is not relevant on the client, another codec for networking can be specified with
registerSynced(ResourceKey, Codec, Codec, SyncOption...).- Type Parameters:
T- the entry type of the registry- Parameters:
key- the unique key of the registrycodec- the codec used to load registry entries from data packs and the networkoptions- options to configure syncing
-
registerSynced
public static <T> void registerSynced(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> key, com.mojang.serialization.Codec<T> serverCodec, com.mojang.serialization.Codec<T> clientCodec, DynamicRegistries.SyncOption... options) Registers a synced dynamic registry.The entries of the registry will be loaded from data packs at the file path
data/<entry namespace>/<registry namespace>/<registry path>/<entry path>.jsonThe registry will be synced from the server to players' clients using the given client codec. The client codec is also used for writing synced entries on the server, so it cannot depend on client-only code.
The client codec must be able to read data encoded by the server codec. This is because client-sided registry entries are sometimes read directly from a data pack using the client codec.
- Type Parameters:
T- the entry type of the registry- Parameters:
key- the unique key of the registryserverCodec- the codec used to load registry entries on the serverclientCodec- the codec used to load registry entries on the client and sync them from the serveroptions- options to configure syncing
-
getWorldRegistries()if you wish to get all world registries, includingminecraft:dimension, or usegetBootstrappingRegistries()if you wish to avoid the latter.