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.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()); }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DeferredRegister.EventDispatcher
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<RegistryObject<T>,java.util.function.Supplier<? extends T>>
entries
private java.util.Set<RegistryObject<T>>
entriesView
private java.lang.String
modid
private java.util.function.Supplier<RegistryBuilder<T>>
registryFactory
private boolean
seenRegisterEvent
private java.lang.Class<T>
superType
private IForgeRegistry<T>
type
-
Constructor Summary
Constructors Modifier Constructor Description private
DeferredRegister(java.lang.Class<T> base, java.lang.String modid)
private
DeferredRegister(IForgeRegistry<T> reg, java.lang.String modid)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addEntries(RegistryEvent.Register<?> event)
private void
captureRegistry()
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 void
createRegistry(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 theregistryFactory
to 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.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 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 theregistryFactory
to be called later seeregister(IEventBus)
CallsRegistryBuilder.setName(net.minecraft.util.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
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()
-
-