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 SummaryNested ClassesModifier and TypeClassDescriptionprivate classprivate static classDeprecated, for removal: This API element is subject to removal in a future version.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate final Map<RegistryObject<T>,Supplier<? extends T>> private final Set<RegistryObject<T>>private final Stringprivate final booleanprivate @Nullable Supplier<RegistryBuilder<?>>private final ResourceKey<? extends Registry<T>>private boolean
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprivateDeferredRegister(ResourceKey<? extends Registry<T>> registryKey, String modid, boolean optionalRegistry) privateDeferredRegister(IForgeRegistry<T> reg, String modid) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds defaults to an existing tag key.static <B> DeferredRegister<B>create(Supplier<IForgeRegistry<B>> reg, String modid) DeferredRegister factory for forge registries that exist after this DeferredRegister is created.static <B> DeferredRegister<B>create(ResourceKey<? extends Registry<B>> key, String modid) DeferredRegister factory for custom forge registries orvanilla registriesto lookup based on the provided registry key.static <B> DeferredRegister<B>create(ResourceLocation registryName, String modid) DeferredRegister factory for custom forge registries orvanilla registriesto 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 registriesto 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 registriesto 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.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 ResourceLocationmakeRegistry(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 voidonFill(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.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- 
registryKey
- 
modid
- 
optionalRegistryprivate final boolean optionalRegistry
- 
entries
- 
entriesView
- 
registryFactory
- 
optionalTags
- 
seenRegisterEventprivate boolean seenRegisterEvent
 
- 
- 
Constructor Details- 
DeferredRegisterprivate DeferredRegister(ResourceKey<? extends Registry<T>> registryKey, String modid, boolean optionalRegistry) 
- 
DeferredRegister
 
- 
- 
Method Details- 
createDeferredRegister 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 wrap
- modid- the namespace for all objects registered to this DeferredRegister
- See Also:
 
- 
createpublic static <B> DeferredRegister<B> create(@Deprecated(forRemoval=true,since="1.20.2") Supplier<IForgeRegistry<B>> reg, String modid) DeferredRegister factory for forge registries that exist after this DeferredRegister is created.- Parameters:
- reg- the forge registry to wrap
- modid- the namespace for all objects registered to this DeferredRegister
- See Also:
 
- 
createDeferredRegister factory for custom forge registries orvanilla registriesto 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 RegistryObjects 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 through- getRegistryKey().
- modid- the namespace for all objects registered to this DeferredRegister
- See Also:
 
- 
createOptionalpublic static <B> DeferredRegister<B> createOptional(ResourceKey<? extends Registry<B>> key, String modid) DeferredRegister factory for the optional existence of custom forge registries orvanilla registriesto 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 RegistryObjects made from this DeferredRegister will never be filled but will not throw an exception.- Parameters:
- key- the key of the registry to reference
- modid- the namespace for all objects registered to this DeferredRegister
- See Also:
 
- 
createDeferredRegister factory for custom forge registries orvanilla registriesto 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 RegistryObjects 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 through- getRegistryName().
- modid- The namespace for all objects registered to this DeferredRegister
- See Also:
 
- 
createOptionalDeferredRegister factory for the optional existence of custom forge registries orvanilla registriesto 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 RegistryObjects 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 through- getRegistryName().
- modid- The namespace for all objects registered to this DeferredRegister
- See Also:
 
- 
registerAdds 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.
 
- 
makeRegistryOnly 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 a- IForgeRegistryduring the- NewRegistryEventevent
- Returns:
- A supplier of the IForgeRegistrycreated by the builder. Will always return null until after theNewRegistryEventevent fires.
 
- 
createTagKeyCreates 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 take- a registry nameor- forge registry.
- See Also:
 
- 
createTagKeyCreates 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 take- a registry nameor- forge 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 take- a registry nameor- forge 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 take- a registry nameor- forge registry.
- See Also:
 
- 
addOptionalTagDefaultspublic 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 take- a registry nameor- forge registry.
- See Also:
 
- 
registerpublic 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.
 
- 
makeRegistryprivate Supplier<IForgeRegistry<T>> makeRegistry(ResourceLocation registryName, Supplier<RegistryBuilder<T>> sup) 
- 
onFill
 
-