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
    Modifier and Type
    Class
    Description
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final net.minecraft.core.Registry<?>
     
    private final net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    RegisterEvent(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>> registryKey, net.minecraft.core.Registry<?> registry)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    net.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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 to
      name - the name of the object to register as its key
      valueSupplier - 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 again getRegistryKey()
      Returns:
      The registry typed to the given registry key if it matches getRegistryKey(), or null if it does not match.