Skip to content

ADeferredRegistryHolder

abstract class ADeferredRegistryHolder<T> : Map<ResourceLocation, RegistrySupplier<out T>> 

A registry holder that stores every registered entry in a Map keyed by its ResourceLocation, providing O(1) lookup by id string as well as property delegation via by register(...).

This class wraps an Architectury DeferredRegister and exposes the registered suppliers through the Map interface. Use it as a base for per-registry object singletons.

Note: Always use by register(...) (delegation) rather than calling .get() eagerly, to avoid touching the registry before it is unfrozen.

Example

object MyItems : ADeferredRegistryHolder<Item>(MyMod.MOD, Registries.ITEM) {
    val MY_ITEM by register("my_item") { Item(Item.Properties()) }
}
// In mod init:
MyItems.init()

Parameters

  • T: The registry entry type.

Constructors

ADeferredRegistryHolder

constructor(mod: Mod, registryKey: ResourceKey<Registry<T>>)

Properties

entries

open override val entries: Set<Map.Entry<ResourceLocation, RegistrySupplier<out T>>>

keys

open override val keys: Set<ResourceLocation>

size

open override val size: Int

values

open override val values: Collection<RegistrySupplier<out T>>

Functions

containsKey

open override fun containsKey(key: ResourceLocation): Boolean

containsValue

open override fun containsValue(value: RegistrySupplier<out T>): Boolean

get

open operator override fun get(key: ResourceLocation): RegistrySupplier<out T>?
operator fun get(id: String): RegistrySupplier<out T>?

Looks up a registered entry by its unqualified id (namespaced under mod automatically).

getValue

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

Property delegate operator that unwraps a RegistrySupplier to its concrete value.

init

open fun init()

Registers the underlying DeferredRegister, then schedules initClient to run on the client, at the earliest point registration APIs that depend on registryKey's registry already being populated (e.g. Architectury's MenuRegistry.registerScreenFactory, or registering a renderer for a BlockEntityType this holder just registered) are safe to call - see waitForRegistry. Must be called once during mod initialization.

isEmpty

open override fun isEmpty(): Boolean

listen

fun listen(listener: () -> Unit)