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<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
public static final RegistryObject<Block> ROCK_BLOCK = BLOCKS.register("rock", () -> new Block(Block.Properties.create(Material.ROCK)));
public static final RegistryObject<Item> 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
-
Field Summary
Modifier and TypeFieldDescriptionprivate Map<RegistryObject<T>,Supplier<? extends T>>
private Set<RegistryObject<T>>
private String
private Supplier<RegistryBuilder<T>>
private boolean
private IForgeRegistry<T>
-
Constructor Summary
ModifierConstructorDescriptionprivate
DeferredRegister(Class<T> base, String modid)
private
DeferredRegister(IForgeRegistry<T> reg, String modid)
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
addEntries(RegistryEvent.Register<?> event)
private void
static <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 void
makeRegistry(String name, Supplier<RegistryBuilder<T>> sup)
For custom registries only, fills theregistryFactory
to be called later seeregister(IEventBus)
CallsRegistryBuilder.setName(net.minecraft.resources.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.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.
-
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 theregistryFactory
to be called later seeregister(IEventBus)
CallsRegistryBuilder.setName(net.minecraft.resources.ResourceLocation)
andRegistryBuilder.setType(java.lang.Class<T>)
automatically.- Parameters:
name
- Path of the registry'sResourceLocation
sup
- Supplier of the RegistryBuilder that is called to filltype
during the NewRegistry event- Returns:
- A supplier of the
IForgeRegistry
created 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()
-