Package net.minecraftforge.registries
Class DeferredRegister<T extends IForgeRegistryEntry<T>>
java.lang.Object
net.minecraftforge.registries.DeferredRegister<T>
- Type Parameters:
T- The base registry type, must be a concrete base class, do not use subclasses or wild cards.
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()); }
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<RegistryObject<T>,Supplier<? extends T>> private final Set<RegistryObject<T>>private final Stringprivate Supplier<RegistryBuilder<T>>private booleanprivate IForgeRegistry<T> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDeferredRegister(Class<T> base, String modid) privateDeferredRegister(IForgeRegistry<T> reg, String modid) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddEntries(RegistryEvent.Register<?> event) private voidstatic <B extends IForgeRegistryEntry<B>>
DeferredRegister<B>Use for custom registries that are made during the NewRegistry event.static <B extends IForgeRegistryEntry<B>>
DeferredRegister<B>create(IForgeRegistry<B> reg, String modid) Use for vanilla/forge registries.private voidmakeRegistry(String name, Supplier<RegistryBuilder<T>> sup) For custom registries only, fills theregistryFactoryto be called later seeregister(IEventBus)CallsRegistryBuilder.setName(net.minecraft.util.ResourceLocation)andRegistryBuilder.setType(java.lang.Class<T>)automatically.<I extends T>
RegistryObject<I>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.voidregister(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.
-
Field Details
-
superType
-
modid
-
entries
private final Map<RegistryObject<T extends IForgeRegistryEntry<T>>,Supplier<? extends T extends IForgeRegistryEntry<T>>> entries -
entriesView
-
type
-
registryFactory
-
seenRegisterEvent
private boolean seenRegisterEvent
-
-
Constructor Details
-
DeferredRegister
-
DeferredRegister
-
-
Method Details
-
create
public static <B extends IForgeRegistryEntry<B>> DeferredRegister<B> create(IForgeRegistry<B> reg, String modid) Use for vanilla/forge registries. See example above. -
create
public static <B extends IForgeRegistryEntry<B>> DeferredRegister<B> create(Class<B> base, String modid) Use for custom registries that are made during the NewRegistry event. -
register
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.
-
makeRegistry
For custom registries only, fills theregistryFactoryto be called later seeregister(IEventBus)CallsRegistryBuilder.setName(net.minecraft.util.ResourceLocation)andRegistryBuilder.setType(java.lang.Class<T>)automatically.- Parameters:
name- Path of the registry'sResourceLocationsup- Supplier of the RegistryBuilder that is called to filltypeduring the NewRegistry event- Returns:
- A supplier of the
IForgeRegistrycreated by the builder.
-
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
- Returns:
- The unmodifiable view of registered entries. Useful for bulk operations on all values.
-
addEntries
-
createRegistry
-
captureRegistry
private void captureRegistry()
-