Class DeferredRegister<T extends IForgeRegistryEntry<T>>

  • Type Parameters:
    T - The base registry type, must be a concrete base class, do not use subclasses or wild cards.

    public class DeferredRegister<T extends IForgeRegistryEntry<T>>
    extends java.lang.Object
    Utility class to help with managing registry entries. Maintains a list of all suppliers for entries and registers them during the proper Register event. Suppliers should return NEW instances every time. Example Usage:
       private static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
       private static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
    
       public static final RegistryObject ROCK_BLOCK = BLOCKS.register("rock", () -> new Block(Block.Properties.create(Material.ROCK)));
       public static final RegistryObject ROCK_ITEM = ITEMS.register("rock", () -> new BlockItem(ROCK_BLOCK.get(), new Item.Properties().group(ItemGroup.MISC)));
    
       public ExampleMod() {
           ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
           BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
       }
    
    • Constructor Detail

      • DeferredRegister

        private DeferredRegister​(java.lang.Class<T> base,
                                 java.lang.String modid)
      • DeferredRegister

        private DeferredRegister​(IForgeRegistry<T> reg,
                                 java.lang.String modid)
    • Method Detail

      • create

        public static <B extends IForgeRegistryEntry<B>> DeferredRegister<B> create​(java.lang.Class<B> base,
                                                                                    java.lang.String modid)
        Use for custom registries that are made during the NewRegistry event.
      • register

        public <I extends TRegistryObject<I> register​(java.lang.String name,
                                                        java.util.function.Supplier<? extends I> sup)
        Adds a new supplier to the list of entries to be registered, and returns a RegistryObject that will be populated with the created entry automatically.
        Parameters:
        name - The new entry's name, it will automatically have the modid prefixed.
        sup - A factory for the new entry, it should return a new instance every time it is called.
        Returns:
        A RegistryObject that will be updated with when the entries in the registry change.
      • register

        public void register​(net.minecraftforge.eventbus.api.IEventBus bus)
        Adds our event handler to the specified event bus, this MUST be called in order for this class to function. See the example usage.
        Parameters:
        bus - The Mod Specific event bus.
      • getEntries

        public java.util.Collection<RegistryObject<T>> getEntries()
        Returns:
        The unmodifiable view of registered entries. Useful for bulk operations on all values.
      • captureRegistry

        private void captureRegistry()