Class RegisterEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.registries.RegisterEvent
- All Implemented Interfaces:
net.neoforged.fml.event.IModBusEvent
public class RegisterEvent
extends net.neoforged.bus.api.Event
implements net.neoforged.fml.event.IModBusEvent
Fired for each registry when it is ready to have modded objects registered.
This event is fired for all builtin registries from vanilla (see
BuiltInRegistries
) and mods.
This event is fired on the mod-specific event bus, on both logical sides.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final net.minecraft.core.Registry
<?> private final net.minecraft.resources.ResourceKey
<? extends net.minecraft.core.Registry<?>> -
Constructor Summary
ConstructorsConstructorDescriptionRegisterEvent
(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>> registryKey, net.minecraft.core.Registry<?> registry) -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.core.Registry
<?> <T> @Nullable net.minecraft.core.Registry
<T> getRegistry
(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> key) net.minecraft.resources.ResourceKey
<? extends net.minecraft.core.Registry<?>> <T> void
register
(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> registryKey, Consumer<RegisterEvent.RegisterHelper<T>> consumer) Calls the provided consumer with a register helper if the provided registry key matches this event's registry key.<T> void
register
(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> registryKey, net.minecraft.resources.ResourceLocation name, Supplier<T> valueSupplier) Registers the value with the given name to the stored registry if the provided registry key matches this event's registry key.
-
Field Details
-
registryKey
private final net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>> registryKey -
registry
private final net.minecraft.core.Registry<?> registry
-
-
Constructor Details
-
RegisterEvent
RegisterEvent(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>> registryKey, net.minecraft.core.Registry<?> registry)
-
-
Method Details
-
register
public <T> void register(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> registryKey, net.minecraft.resources.ResourceLocation name, Supplier<T> valueSupplier) Registers the value with the given name to the stored registry if the provided registry key matches this event's registry key.- Type Parameters:
T
- the type of the registry- Parameters:
registryKey
- the key of the registry to register the value toname
- the name of the object to register as its keyvalueSupplier
- a supplier of the object value- See Also:
-
register
public <T> void register(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> registryKey, Consumer<RegisterEvent.RegisterHelper<T>> consumer) Calls the provided consumer with a register helper if the provided registry key matches this event's registry key.- Type Parameters:
T
- the type of the registry- Parameters:
registryKey
- the key of the registry to register objects to- See Also:
-
getRegistryKey
public net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>> getRegistryKey()- Returns:
- The registry key linked to this event
-
getRegistry
public net.minecraft.core.Registry<?> getRegistry()- Returns:
- The registry linked to this event
-
getRegistry
@Nullable public <T> @Nullable net.minecraft.core.Registry<T> getRegistry(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> key) - Parameters:
key
- the registry key to compare againgetRegistryKey()
- Returns:
- The registry typed to the given registry key if it matches
getRegistryKey()
, ornull
if it does not match.
-