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
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSpecialized register implementation for blocks.static classSpecialized register implementation for items. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract <T extends R>
voidbind(RegistryHolder<R, T> holder) Binds a registry holder to the actual registry entry.static <T> Register<T> Creates a register for the specified registry and namespace.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.static Register.BlockscreateBlocks(String namespace) Creates a specialized block register for the given namespace.protected <T extends R>
RegistryHolder<R, T> createHolder(net.minecraft.resources.ResourceKey<R> key, Supplier<T> supplier) static Register.ItemscreateItems(String namespace) Creates a specialized item register for the given namespace.Gets all registry holder entries.Gets the namespace for registered objects.net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<R>> Gets the resource key of the target registry.iterator()voidregister()Performs final registration by binding all holders to the actual registry.<T extends R>
RegistryHolder<R, T> Registers a new object to this registry.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Method Details
-
create
Creates a register for the specified registry and namespace.- Type Parameters:
T- The registry object type- Parameters:
registry- The target registrynamespace- 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 registrynamespace- The namespace for registered objects- Returns:
- A new register instance
-
createBlocks
Creates a specialized block register for the given namespace.- Parameters:
namespace- The namespace for registered blocks- Returns:
- A new block register
-
createItems
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
Gets all registry holder entries.- Returns:
- Collection of registry holders
-
getNamespace
Gets the namespace for registered objects.- Returns:
- The namespace
-
register
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
-
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
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
-