Class DeferredRegister<T>

java.lang.Object
net.neoforged.neoforge.registries.DeferredRegister<T>
Type Parameters:
T - the base registry type
Direct Known Subclasses:
DeferredAttachmentTypes, DeferredEntityTypes, DeferredRegister.Blocks, DeferredRegister.DataComponents, DeferredRegister.Items

public class DeferredRegister<T> extends Object
A helper class to aid in registering objects to modded and vanilla registries and provide deferred suppliers to access those objects.

This class maintains a list of all suppliers for entries and registers them during the proper RegisterEvent event, after being registered to an event bus.

Suppliers should return new instances every time they are invoked.

To create an instance of this helper class, use any of the three factory methods: create(Registry, String), create(ResourceKey, String), or create(ResourceLocation, String). There are also specialized subclasses of this helper for Blocks and Items, created through createBlocks(String) and createItems(String) respectively. (Be sure to store the concrete type of those subclasses, rather than storing them generically as DeferredRegister<Block> or DeferredRegister<Item>.)

Here are some common examples for using this class:


 private static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID);
 private static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MODID);
 private static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(BuiltInRegistries.BLOCK_ENTITY_TYPE, MODID);

 // If you don't care about the actual Block class, use the simple variants
 public static final DeferredBlock<Block> ROCK_BLOCK = BLOCKS.registerSimpleBlock("rock", Block.Properties.create(Material.ROCK));
 public static final DeferredItem<BlockItem> ROCK_ITEM = ITEMS.registerSimpleBlockItem(ROCK_BLOCK, new Item.Properties());

 // Otherwise, use the regular (non-'simple') variants
 public static final DeferredBlock<SpecialRockBlock> SPECIAL_ROCK_BLOCK = BLOCKS.registerBlock("special_rock",
         SpecialRockBlock::new, Block.Properties.create(Material.ROCK));
 // (#registerSimpleBlockItem does not have a non-'simple' variant -- register an item in the usual way)
 public static final DeferredItem<SpecialRockItem> SPECIAL_ROCK_ITEM = ITEMS.register("special_rock",
         () -> new SpecialRockItem(SPECIAL_ROCK_BLOCK.get(), new Item.Properties()))

 // (Can be DeferredHolder<BlockEntityType<?>, BlockEntityType<RockBlockEntity>> if you prefer)
 public static final Supplier<BlockEntityType<RockBlockEntity>> ROCK_BLOCK_ENTITY = BLOCK_ENTITIES.register("rock",
         () -> BlockEntityType.Builder.of(RockBlockEntity::new, ROCK_BLOCK.get()).build(null));

 public ExampleMod(IEventBus modBus) {
     ITEMS.register(modBus);
     BLOCKS.register(modBus);
     BLOCK_ENTITIES.register(modBus);
 }
 
See Also: