Skip to content

RegistryHelper

open class RegistryHelper<T : Any>(val registry: DeferredRegister<T>)

A convenience base class for managing a collection of registry entries backed by an Architectury DeferredRegister.

Subclass this object (or class) for each registry you want to populate, declare your entries with by register(...), and call init during your mod's initialization phase.

Important: Always use the by delegation operator when declaring entries to avoid "Registry is frozen" errors that occur when values are accessed before the registry tick.

Example

object MyItems : RegistryHelper<Item>(DeferredRegister.create(modId, Registries.ITEM)) {
    val MY_ITEM by register("my_item") { Item(Item.Properties()) }
}

// In mod init:
MyItems.init()

Parameters

  • T: The base type stored in the target registry.

Inheritors

Constructors

RegistryHelper

constructor(registry: DeferredRegister<T>)

Parameters

  • T: The base type stored in the target registry.

Properties

registry

val registry: DeferredRegister<T>

Functions

getValue

operator fun <V : T> RegistrySupplier<V>.getValue(any: Any?, property: KProperty<*>): V

Kotlin property delegate operator that unwraps a RegistrySupplier to its concrete value.

This enables the idiomatic val MY_ENTRY by register(...) pattern.

init

open fun init()

Registers this helper's DeferredRegister with the game's registry system.

Must be called once during mod initialization.

register

open fun <V : T> register(id: String, supplier: () -> V): RegistrySupplier<V>

Registers a new entry and returns a RegistrySupplier for lazy access.

Return

A RegistrySupplier wrapping the registered entry.

Parameters

  • id: The entry's registry name (without namespace). The mod namespace is prepended automatically.

  • supplier: Factory producing the entry. Must not cache the returned instance.

open fun <V : T> register(id: ResourceLocation, supplier: () -> V): RegistrySupplier<V>

Registers a new entry using a fully-qualified ResourceLocation and returns a RegistrySupplier.

Return

A RegistrySupplier wrapping the registered entry.

Parameters

  • id: The fully-qualified ResourceLocation for the entry.

  • supplier: Factory producing the entry. Must not cache the returned instance.