BlockRegistryHelper¶
open class BlockRegistryHelper<T : Block>(modId: String) : RegistryHelper<T>
A RegistryHelper specialised for Block registration that also automatically registers a corresponding BlockItem in the item registry.
Extend this class for each set of blocks in your mod. Each call to block registers both the block and (optionally) its item form.
Example¶
object MyBlocks : BlockRegistryHelper<Block>(modId) {
val MY_BLOCK by block("my_block") { MyBlock(BlockBehaviour.Properties.of()) }
}
// In mod init:
MyBlocks.init()
Parameters¶
-
T: The base block type; must extend Block.
-
modId: The mod ID used as the namespace for registered entries.
Constructors¶
BlockRegistryHelper¶
constructor(modId: String)
Parameters
-
T: The base block type; must extend Block.
-
modId: The mod ID used as the namespace for registered entries.
Properties¶
itemRegistry¶
open val itemRegistry: DeferredRegister<Item>
The DeferredRegister for the item registry, used to register BlockItems.
registry¶
Functions¶
block¶
Registers a block and its associated BlockItem.
The itemSupplier defaults to a plain BlockItem. Pass null to suppress item registration entirely (useful for technical blocks that should not appear in inventories).
Return
A RegistrySupplier for the registered block.
Parameters
-
id: The registry name for both the block and its item.
-
itemSupplier: A factory that produces the BlockItem given the registered block and default Item.Properties. Pass
nullto skip item registration. -
supplier: Factory that produces the block instance.
getValue¶
Kotlin property delegate operator that unwraps a RegistrySupplier to its concrete value.
This enables the idiomatic val MY_ENTRY by register(...) pattern.
init¶
open override fun init()
Registers this helper's DeferredRegister with the game's registry system.
Must be called once during mod initialization.
register¶
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.
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.