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.
public class DeferredRegister<T extends IForgeRegistryEntry<T>> extends java.lang.ObjectUtility 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 Modifier and Type Class Description static classDeferredRegister.EventDispatcher
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<RegistryObject<T>,java.util.function.Supplier<? extends T>>entriesprivate java.util.Set<RegistryObject<T>>entriesViewprivate java.lang.Stringmodidprivate java.util.function.Supplier<RegistryBuilder<T>>registryFactoryprivate booleanseenRegisterEventprivate java.lang.Class<T>superTypeprivate IForgeRegistry<T>type
-
Constructor Summary
Constructors Modifier Constructor Description privateDeferredRegister(java.lang.Class<T> base, java.lang.String modid)privateDeferredRegister(IForgeRegistry<T> reg, java.lang.String modid)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddEntries(RegistryEvent.Register<?> event)private voidcaptureRegistry()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.static <B extends IForgeRegistryEntry<B>>
DeferredRegister<B>create(IForgeRegistry<B> reg, java.lang.String modid)Use for vanilla/forge registries.private voidcreateRegistry(RegistryEvent.NewRegistry event)java.util.Collection<RegistryObject<T>>getEntries()java.util.function.Supplier<IForgeRegistry<T>>makeRegistry(java.lang.String name, java.util.function.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>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.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 Detail
-
superType
private final java.lang.Class<T extends IForgeRegistryEntry<T>> superType
-
modid
private final java.lang.String modid
-
entries
private final java.util.Map<RegistryObject<T extends IForgeRegistryEntry<T>>,java.util.function.Supplier<? extends T extends IForgeRegistryEntry<T>>> entries
-
entriesView
private final java.util.Set<RegistryObject<T extends IForgeRegistryEntry<T>>> entriesView
-
type
private IForgeRegistry<T extends IForgeRegistryEntry<T>> type
-
registryFactory
private java.util.function.Supplier<RegistryBuilder<T extends IForgeRegistryEntry<T>>> registryFactory
-
seenRegisterEvent
private boolean seenRegisterEvent
-
-
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(IForgeRegistry<B> reg, java.lang.String modid)
Use for vanilla/forge registries. See example above.
-
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 T> RegistryObject<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.
-
makeRegistry
public java.util.function.Supplier<IForgeRegistry<T>> makeRegistry(java.lang.String name, java.util.function.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.- 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
public java.util.Collection<RegistryObject<T>> getEntries()
- Returns:
- The unmodifiable view of registered entries. Useful for bulk operations on all values.
-
addEntries
private void addEntries(RegistryEvent.Register<?> event)
-
createRegistry
private void createRegistry(RegistryEvent.NewRegistry event)
-
captureRegistry
private void captureRegistry()
-
-