Interface DynamicRegistryManagerSetupContext
- All Known Implementing Classes:
DynamicRegistryManagerSetupContextImpl
@NonExtendable
public interface DynamicRegistryManagerSetupContext
Represents the
RegistryAccess setup context provided in the RegistryEvents.DYNAMIC_REGISTRY_SETUP event.
Modified to work on Fabric
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordRepresents a map of known registries. -
Method Summary
Modifier and TypeMethodDescriptiondefault @Nullable DynamicRegistryManagerSetupContext.RegistryMapgetRegistries(@NotNull Set<net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>>> registryKeys) Gets the registries requested by their keys.default <V> voidmonitor(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<V>> registryKey, Consumer<RegistryMonitor<V>> action) Attempts to create a new registry monitor for the given registry.default <V> @NotNull Optional<V> register(@NotNull net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<V>> registryKey, @NotNull net.minecraft.resources.ResourceLocation id, @NotNull Supplier<V> gameObjectSupplier) Attempts to safely register a game object into the given registry.@NotNull net.minecraft.core.RegistryAccessReturns the registry access that is being currently setup.@NotNull net.minecraft.server.packs.resources.ResourceManagerReturns the resource manager that is used to setup the dynamic registries.default voidwithRegistries(@NotNull Consumer<DynamicRegistryManagerSetupContext.RegistryMap> action, @NotNull Set<net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>>> registryKeys) Executes the given action if all the provided registry keys are present in theRegistryAccess.
-
Method Details
-
registryManager
@Contract(pure=true) @NotNull @NotNull net.minecraft.core.RegistryAccess registryManager()Returns the registry access that is being currently setup.- Returns:
- the registry access that is being currently setup
-
resourceManager
@Contract(pure=true) @NotNull @NotNull net.minecraft.server.packs.resources.ResourceManager resourceManager()Returns the resource manager that is used to setup the dynamic registries.- Returns:
- the resource manager that is used to setup the dynamic registries
-
register
@NotNull default <V> @NotNull Optional<V> register(@NotNull @NotNull net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<V>> registryKey, @NotNull @NotNull net.minecraft.resources.ResourceLocation id, @NotNull @NotNull Supplier<V> gameObjectSupplier) Attempts to safely register a game object into the given registry.This method is preferred instead of
Registry.register(Registry, ResourceLocation, Object)as it makes sure to not overwrite data-pack-provided entries, it also makes sure the registry exists.- Type Parameters:
V- the type of game object to register- Parameters:
registryKey- the key of the registry to register intoid- the identifier of the game object to registergameObjectSupplier- the supplier of the game object to register- Returns:
- the optional game object, if the registry is present then the optional is filled, or empty otherwise
-
getRegistries
@Contract(pure=true) @Nullable default @Nullable DynamicRegistryManagerSetupContext.RegistryMap getRegistries(@NotNull @NotNull Set<net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>>> registryKeys) Gets the registries requested by their keys.If one of the queried registries isn't found, then this method will return
null.- Parameters:
registryKeys- the keys of the registries to get- Returns:
- the registry map if all the queried registries have been found, or
nullotherwise
-
withRegistries
default void withRegistries(@NotNull @NotNull Consumer<DynamicRegistryManagerSetupContext.RegistryMap> action, @NotNull @NotNull Set<net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>>> registryKeys) Executes the given action if all the provided registry keys are present in theRegistryAccess.- Parameters:
action- the actionregistryKeys- the registry keys to check
-
monitor
default <V> void monitor(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<V>> registryKey, Consumer<RegistryMonitor<V>> action) Attempts to create a new registry monitor for the given registry.- Type Parameters:
V- the type of values held in the registry- Parameters:
registryKey- the key of the registry to monitoraction- the monitor callback
-