Class DeferredRegister<T>
- Type Parameters:
T
- The base registry type
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
Modifier and TypeClassDescriptionstatic class
private static class
-
Field Summary
Modifier and TypeFieldDescriptionprivate final Map<RegistryObject<T>,
Supplier<? extends T>> private final Set<RegistryObject<T>>
private final String
private final boolean
private @Nullable Supplier<RegistryBuilder<?>>
private final ResourceKey<? extends Registry<T>>
private boolean
-
Constructor Summary
ModifierConstructorDescriptionprivate
DeferredRegister
(ResourceKey<? extends Registry<T>> registryKey, String modid, boolean optionalRegistry) private
DeferredRegister
(IForgeRegistry<T> reg, String modid) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addEntries
(RegisterEvent event) void
Adds defaults to an existing tag key.static <B> DeferredRegister<B>
create
(ResourceKey<? extends Registry<B>> key, String modid) DeferredRegister factory for custom forge registries orvanilla registries
to lookup based on the provided registry key.static <B> DeferredRegister<B>
create
(ResourceLocation registryName, String modid) DeferredRegister factory for custom forge registries orvanilla registries
to lookup based on the provided registry name.static <B> DeferredRegister<B>
create
(IForgeRegistry<B> reg, String modid) DeferredRegister factory for forge registries that exist before this DeferredRegister is created.static <B> DeferredRegister<B>
createOptional
(ResourceKey<? extends Registry<B>> key, String modid) DeferredRegister factory for the optional existence of custom forge registries orvanilla registries
to lookup based on the provided registry key.static <B> DeferredRegister<B>
createOptional
(ResourceLocation registryName, String modid) DeferredRegister factory for the optional existence of custom forge registries orvanilla registries
to lookup based on the provided registry name.createOptionalTagKey
(@NotNull String path, @NotNull Set<? extends Supplier<T>> defaults) Creates a tag key with the current modid and provided path that will use the set of defaults if the tag is not loaded from any datapacks.createOptionalTagKey
(@NotNull ResourceLocation location, @NotNull Set<? extends Supplier<T>> defaults) Creates a tag key with the provided location that will use the set of defaults if the tag is not loaded from any datapacks.private void
createRegistry
(NewRegistryEvent event) createTagKey
(@NotNull String path) Creates a tag key based on the current modid and provided path as the location and the registry name linked to this DeferredRegister.createTagKey
(@NotNull ResourceLocation location) Creates a tag key based on the provided resource location and the registry name linked to this DeferredRegister.ResourceKey<? extends Registry<T>>
@NotNull ResourceLocation
makeRegistry
(Supplier<RegistryBuilder<T>> sup) Only used for custom registries to fill the forge registry held in this DeferredRegister.private Supplier<IForgeRegistry<T>>
makeRegistry
(ResourceLocation registryName, Supplier<RegistryBuilder<T>> sup) private void
onFill
(IForgeRegistry<?> registry) <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
-
registryKey
-
modid
-
optionalRegistry
private final boolean optionalRegistry -
entries
-
entriesView
-
registryFactory
-
optionalTags
-
seenRegisterEvent
private boolean seenRegisterEvent
-
-
Constructor Details
-
DeferredRegister
private DeferredRegister(ResourceKey<? extends Registry<T>> registryKey, String modid, boolean optionalRegistry) -
DeferredRegister
-
-
Method Details
-
create
DeferredRegister factory for forge registries that exist before this DeferredRegister is created.If you have a supplier, do not use this method. Instead, use one of the other factories that takes in a registry key or registry name.
- Parameters:
reg
- the forge registry to wrapmodid
- the namespace for all objects registered to this DeferredRegister- See Also:
-
create
DeferredRegister factory for custom forge registries orvanilla registries
to lookup based on the provided registry key. Supports both registries that already exist or do not exist yet.If the registry is never created, any
RegistryObject
s made from this DeferredRegister will throw an exception. To allow the optional existence of a registry without error, usecreateOptional(ResourceKey, String)
.- Parameters:
key
- the key of the registry to reference. May come from another DeferredRegister throughgetRegistryKey()
.modid
- the namespace for all objects registered to this DeferredRegister- See Also:
-
createOptional
public static <B> DeferredRegister<B> createOptional(ResourceKey<? extends Registry<B>> key, String modid) DeferredRegister factory for the optional existence of custom forge registries orvanilla registries
to lookup based on the provided registry key. Supports both registries that already exist or do not exist yet.If the registry is never created, any
RegistryObject
s made from this DeferredRegister will never be filled but will not throw an exception.- Parameters:
key
- the key of the registry to referencemodid
- the namespace for all objects registered to this DeferredRegister- See Also:
-
create
DeferredRegister factory for custom forge registries orvanilla registries
to lookup based on the provided registry name. Supports both registries that already exist or do not exist yet.If the registry is never created, any
RegistryObject
s made from this DeferredRegister will throw an exception. To allow the optional existence of a registry without error, usecreateOptional(ResourceLocation, String)
.- Parameters:
registryName
- The name of the registry, should include namespace. May come from another DeferredRegister throughgetRegistryName()
.modid
- The namespace for all objects registered to this DeferredRegister- See Also:
-
createOptional
DeferredRegister factory for the optional existence of custom forge registries orvanilla registries
to lookup based on the provided registry name. Supports both registries that already exist or do not exist yet.If the registry is never created, any
RegistryObject
s made from this DeferredRegister will never be filled but will not throw an exception.- Parameters:
registryName
- The name of the registry, should include namespace. May come from another DeferredRegister throughgetRegistryName()
.modid
- The namespace for all objects registered to this DeferredRegister- See Also:
-
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
Only used for custom registries to fill the forge registry held in this DeferredRegister. CallsRegistryBuilder.setName(net.minecraft.resources.ResourceLocation)
automatically.- Parameters:
sup
- Supplier of a RegistryBuilder that initializes aIForgeRegistry
during theNewRegistryEvent
event- Returns:
- A supplier of the
IForgeRegistry
created by the builder. Will always return null until after theNewRegistryEvent
event fires.
-
createTagKey
Creates a tag key based on the current modid and provided path as the location and the registry name linked to this DeferredRegister. To control the namespace, usecreateTagKey(ResourceLocation)
.- Throws:
IllegalStateException
- If the registry name was not set. Use the factories that takea registry name
orforge registry
.- See Also:
-
createTagKey
Creates a tag key based on the provided resource location and the registry name linked to this DeferredRegister. To use the current modid as the namespace, usecreateTagKey(String)
.- Throws:
IllegalStateException
- If the registry name was not set. Use the factories that takea registry name
orforge registry
.- See Also:
-
createOptionalTagKey
@NotNull public @NotNull TagKey<T> createOptionalTagKey(@NotNull @NotNull String path, @NotNull @NotNull Set<? extends Supplier<T>> defaults) Creates a tag key with the current modid and provided path that will use the set of defaults if the tag is not loaded from any datapacks. Useful on the client side when a server may not provide a specific tag. To control the namespace, usecreateOptionalTagKey(ResourceLocation, Set)
.- Throws:
IllegalStateException
- If the registry name was not set. Use the factories that takea registry name
orforge registry
.- See Also:
-
createOptionalTagKey
@NotNull public @NotNull TagKey<T> createOptionalTagKey(@NotNull @NotNull ResourceLocation location, @NotNull @NotNull Set<? extends Supplier<T>> defaults) Creates a tag key with the provided location that will use the set of defaults if the tag is not loaded from any datapacks. Useful on the client side when a server may not provide a specific tag. To use the current modid as the namespace, usecreateOptionalTagKey(String, Set)
.- Throws:
IllegalStateException
- If the registry name was not set. Use the factories that takea registry name
orforge registry
.- See Also:
-
addOptionalTagDefaults
public void addOptionalTagDefaults(@NotNull @NotNull TagKey<T> name, @NotNull @NotNull Set<? extends Supplier<T>> defaults) Adds defaults to an existing tag key. The set of defaults will be bound to the tag if the tag is not loaded from any datapacks. Useful on the client side when a server may not provide a specific tag.- Throws:
IllegalStateException
- If the registry name was not set. Use the factories that takea registry name
orforge registry
.- See Also:
-
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. Seethe example usage
.- Parameters:
bus
- The Mod Specific event bus.
-
getEntries
- Returns:
- The unmodifiable view of registered entries. Useful for bulk operations on all values.
-
getRegistryKey
- Returns:
- The registry key stored in this deferred register. Useful for creating new deferred registers based on an existing one.
-
getRegistryName
- Returns:
- The registry name stored in this deferred register. Useful for creating new deferred registers based on an existing one.
-
makeRegistry
private Supplier<IForgeRegistry<T>> makeRegistry(ResourceLocation registryName, Supplier<RegistryBuilder<T>> sup) -
onFill
-
addEntries
-
createRegistry
-