Class Register<R>

java.lang.Object
net.xun.lib.common.api.registries.Register<R>
Type Parameters:
R - The base type of objects being registered (e.g. Block, Item)
All Implemented Interfaces:
Iterable<R>
Direct Known Subclasses:
NeoForgeRegister, Register.Blocks, Register.Items

public abstract class Register<R> extends Object implements Iterable<R>
Abstract base class for registry management that simplifies registration of game objects.

This class provides a convenient way to register objects to Minecraft registries with automatic holder binding. It supports iteration over registered objects and handles both block and item registration through specialized inner classes.

  • Constructor Details

    • Register

      protected Register(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<R>> registry, String namespace)
      Constructs a new register instance.
      Parameters:
      registry - The resource key of the target registry
      namespace - The namespace for registered objects
  • Method Details

    • create

      public static <T> Register<T> create(net.minecraft.core.Registry<T> registry, String namespace)
      Creates a register for the specified registry and namespace.
      Type Parameters:
      T - The registry object type
      Parameters:
      registry - The target registry
      namespace - The namespace for registered objects
      Returns:
      A new register instance
    • create

      public static <T> Register<T> create(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registry, String namespace)
      Creates a register for the specified registry key and namespace.
      Type Parameters:
      T - The registry object type
      Parameters:
      registry - The resource key of the target registry
      namespace - The namespace for registered objects
      Returns:
      A new register instance
    • createBlocks

      public static Register.Blocks createBlocks(String namespace)
      Creates a specialized block register for the given namespace.
      Parameters:
      namespace - The namespace for registered blocks
      Returns:
      A new block register
    • createItems

      public static Register.Items createItems(String namespace)
      Creates a specialized item register for the given namespace.
      Parameters:
      namespace - The namespace for registered items
      Returns:
      A new item register
    • getRegistryKey

      public net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<R>> getRegistryKey()
      Gets the resource key of the target registry.
      Returns:
      The registry resource key
    • getEntries

      public Collection<RegistryHolder<R,?>> getEntries()
      Gets all registry holder entries.
      Returns:
      Collection of registry holders
    • getNamespace

      public String getNamespace()
      Gets the namespace for registered objects.
      Returns:
      The namespace
    • register

      public <T extends R> RegistryHolder<R,T> register(String name, Supplier<T> supplier)
      Registers a new object to this registry.

      For certain registries (attributes, mob effects, data component types), binding happens immediately during registration.

      Type Parameters:
      T - The concrete type of the object to register
      Parameters:
      name - The name of the object (without namespace)
      supplier - Supplier providing the object instance
      Returns:
      The created registry holder
    • createHolder

      protected <T extends R> RegistryHolder<R,T> createHolder(net.minecraft.resources.ResourceKey<R> key, Supplier<T> supplier)
    • iterator

      @NotNull public @NotNull Iterator<R> iterator()
      Specified by:
      iterator in interface Iterable<R>
      Returns:
      Iterator over registered values
    • register

      public void register()
      Performs final registration by binding all holders to the actual registry.

      This should be called during mod initialization after the registry is available. Note: Certain registry types are bound immediately and skip this step.

    • bind

      protected abstract <T extends R> void bind(RegistryHolder<R,T> holder)
      Binds a registry holder to the actual registry entry.
      Type Parameters:
      T - The concrete type of the registered object
      Parameters:
      holder - The registry holder to bind