Class RegistryObject<T>
- All Implemented Interfaces:
- Supplier<T>
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate static final RegistryObject<?>private @Nullable ResourceKey<T>private final @Nullable ResourceLocationprivate final booleanprivate T
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprivateprivateRegistryObject(ResourceLocation name, ResourceLocation registryName, String modid, boolean optionalRegistry) privateRegistryObject(ResourceLocation name, IForgeRegistry<?> registry) 
- 
Method SummaryModifier and TypeMethodDescriptionstatic <T,U extends T> 
 RegistryObject<U>create(ResourceLocation name, ResourceKey<? extends Registry<T>> registryKey, String modid) Factory for aRegistryObjectthat stores the value of an object from a registry once it is ready based on a lookup of the provided registry key.static <T,U extends T> 
 RegistryObject<U>create(ResourceLocation name, ResourceLocation registryName, String modid) Factory for aRegistryObjectthat stores the value of an object from a registry once it is ready based on a lookup of the provided registry name.static <T,U extends T> 
 RegistryObject<U>create(ResourceLocation name, IForgeRegistry<T> registry) Factory for aRegistryObjectthat stores the value of an object from the provided forge registry once it is ready.static <T,U extends T> 
 RegistryObject<U>createOptional(ResourceLocation name, ResourceKey<? extends Registry<T>> registryKey, String modid) Factory for aRegistryObjectthat optionally stores the value of an object from a registry once it is ready if the registry exists based on a lookup of the provided registry key.static <T,U extends T> 
 RegistryObject<U>createOptional(ResourceLocation name, ResourceLocation registryName, String modid) Factory for aRegistryObjectthat optionally stores the value of an object from a registry once it is ready if the registry exists based on a lookup of the provided registry name.private static <T> RegistryObject<T>empty()booleanIf a mod object is present, and the mod object matches the given predicate, return anRegistryObjectdescribing the value, otherwise return an emptyRegistryObject.<U> Optional<U>If a value is present, apply the providedOptional-bearing mapping function to it, return that result, otherwise return an emptyOptional.get()Retrieves the wrapped object in the registry.Returns an optionalHolderinstance pointing to this RegistryObject's name and value.getId()@Nullable ResourceKey<T>getKey()Returns the resource key that points to the registry and name of this registry object.inthashCode()voidIf a mod object is present, invoke the specified consumer with the object, otherwise do nothing.booleanReturntrueif there is a mod object present, otherwisefalse.<U> Supplier<U>If a mod object is present, lazily apply the provided mapping function to it, returning a supplier for the transformed result.<U> Optional<U>If a mod object is present, apply the provided mapping function to it, and if the result is non-null, return anOptionaldescribing the result.Return the mod object if present, otherwise returnother.Return the mod object if present, otherwise invokeotherand return the result of that invocation.orElseThrow(Supplier<? extends X> exceptionSupplier) Return the contained mod object, if present, otherwise throw an exception to be created by the provided supplier.private static booleanregistryExists(ResourceLocation registryName) stream()(package private) voidupdateReference(Registry<? extends T> registry) (package private) voidupdateReference(ResourceLocation registryName) (package private) voidupdateReference(IForgeRegistry<? extends T> registry) (package private) voidupdateReference(RegisterEvent event) 
- 
Field Details- 
name
- 
key
- 
optionalRegistryprivate final boolean optionalRegistry
- 
value
- 
holder
- 
EMPTY
 
- 
- 
Constructor Details- 
RegistryObjectprivate RegistryObject()
- 
RegistryObject
- 
RegistryObjectprivate RegistryObject(ResourceLocation name, ResourceLocation registryName, String modid, boolean optionalRegistry) 
 
- 
- 
Method Details- 
createpublic static <T,U extends T> RegistryObject<U> create(ResourceLocation name, IForgeRegistry<T> registry) Factory for aRegistryObjectthat stores the value of an object from the provided forge registry once it is ready.- Parameters:
- name- the name of the object to look up in the forge registry
- registry- the forge registry
- Returns:
- a RegistryObjectthat stores the value of an object from the provided forge registry once it is ready
 
- 
createpublic static <T,U extends T> RegistryObject<U> create(ResourceLocation name, ResourceKey<? extends Registry<T>> registryKey, String modid) Factory for aRegistryObjectthat stores the value of an object from a registry once it is ready based on a lookup of the provided registry key.If a registry with the given key cannot be found, an exception will be thrown when trying to fill this RegistryObject. Use createOptional(ResourceLocation, ResourceKey, String)for RegistryObjects of optional registries.- Parameters:
- name- the name of the object to look up in a registry
- registryKey- the key of the registry. Supports lookups on- BuiltInRegistriesand- RegistryManager.ACTIVE.
- modid- the mod id calling context
- Returns:
- a RegistryObjectthat stores the value of an object from a registry once it is ready
- See Also:
 
- 
createOptionalpublic static <T,U extends T> RegistryObject<U> createOptional(ResourceLocation name, ResourceKey<? extends Registry<T>> registryKey, String modid) Factory for aRegistryObjectthat optionally stores the value of an object from a registry once it is ready if the registry exists based on a lookup of the provided registry key.If a registry with the given key cannot be found, it will be silently ignored and this RegistryObject will not be filled. Use create(ResourceLocation, ResourceKey, String)for RegistryObjects that should throw exceptions on missing registry.- Parameters:
- name- the name of the object to look up in a registry
- registryKey- the key of the registry. Supports lookups on- BuiltInRegistriesand- RegistryManager.ACTIVE.
- modid- the mod id calling context
- Returns:
- a RegistryObjectthat stores the value of an object from a registry once it is ready
- See Also:
 
- 
createpublic static <T,U extends T> RegistryObject<U> create(ResourceLocation name, ResourceLocation registryName, String modid) Factory for aRegistryObjectthat stores the value of an object from a registry once it is ready based on a lookup of the provided registry name.If a registry with the given name cannot be found, an exception will be thrown when trying to fill this RegistryObject. Use createOptional(ResourceLocation, ResourceLocation, String)for RegistryObjects of optional registries.- Parameters:
- name- the name of the object to look up in a registry
- registryName- the name of the registry. Supports lookups on- BuiltInRegistriesand- RegistryManager.ACTIVE.
- modid- the mod id calling context
- Returns:
- a RegistryObjectthat stores the value of an object from a registry once it is ready
- See Also:
 
- 
createOptionalpublic static <T,U extends T> RegistryObject<U> createOptional(ResourceLocation name, ResourceLocation registryName, String modid) Factory for aRegistryObjectthat optionally stores the value of an object from a registry once it is ready if the registry exists based on a lookup of the provided registry name.If a registry with the given name cannot be found, it will be silently ignored and this RegistryObject will not be filled. Use create(ResourceLocation, ResourceLocation, String)for RegistryObjects that should throw exceptions on missing registry.- Parameters:
- name- the name of the object to look up in a registry
- registryName- the name of the registry. Supports lookups on- BuiltInRegistriesand- RegistryManager.ACTIVE.
- modid- the mod id calling context
- Returns:
- a RegistryObjectthat stores the value of an object from a registry once it is ready
- See Also:
 
- 
empty
- 
getRetrieves the wrapped object in the registry. This value will automatically be updated when the backing registry is updated.- Specified by:
- getin interface- Supplier<T>
- Throws:
- NullPointerException- If the value is null. Use- isPresent()to check if the value exists first.
- See Also:
 
- 
updateReference
- 
updateReference
- 
updateReference
- 
updateReference
- 
registryExists
- 
getId
- 
getKeyReturns the resource key that points to the registry and name of this registry object. Nullable only if this RegistryObject is empty and has no name.- Returns:
- the resource key that points to the registry and name of this registry object
 
- 
stream
- 
isPresentpublic boolean isPresent()Returntrueif there is a mod object present, otherwisefalse.- Returns:
- trueif there is a mod object present, otherwise- false
 
- 
ifPresentIf a mod object is present, invoke the specified consumer with the object, otherwise do nothing.- Parameters:
- consumer- block to be executed if a mod object is present
- Throws:
- NullPointerException- if mod object is present and- consumeris null
 
- 
filterIf a mod object is present, and the mod object matches the given predicate, return anRegistryObjectdescribing the value, otherwise return an emptyRegistryObject.- Parameters:
- predicate- a predicate to apply to the mod object, if present
- Returns:
- an RegistryObjectdescribing the value of thisRegistryObjectif a mod object is present and the mod object matches the given predicate, otherwise an emptyRegistryObject
- Throws:
- NullPointerException- if the predicate is null
 
- 
mapIf a mod object is present, apply the provided mapping function to it, and if the result is non-null, return anOptionaldescribing the result. Otherwise return an emptyOptional.- Type Parameters:
- U- The type of the result of the mapping function
- Parameters:
- mapper- a mapping function to apply to the mod object, if present
- Returns:
- an Optionaldescribing the result of applying a mapping function to the mod object of thisRegistryObject, if a mod object is present, otherwise an emptyOptional
- Throws:
- NullPointerException- if the mapping function is null
- API Note:
- This method supports post-processing on optional values, without the need to explicitly check for a return status.
 
- 
flatMapIf a value is present, apply the providedOptional-bearing mapping function to it, return that result, otherwise return an emptyOptional. This method is similar tomap(Function), but the provided mapper is one whose result is already anOptional, and if invoked,flatMapdoes not wrap it with an additionalOptional.- Type Parameters:
- U- The type parameter to the- Optionalreturned by
- Parameters:
- mapper- a mapping function to apply to the mod object, if present the mapping function
- Returns:
- the result of applying an Optional-bearing mapping function to the value of thisOptional, if a value is present, otherwise an emptyOptional
- Throws:
- NullPointerException- if the mapping function is null or returns a null result
 
- 
lazyMapIf a mod object is present, lazily apply the provided mapping function to it, returning a supplier for the transformed result. If this object is empty, or the mapping function returnsnull, the supplier will returnnull.- Type Parameters:
- U- The type of the result of the mapping function
- Parameters:
- mapper- A mapping function to apply to the mod object, if present
- Returns:
- A Supplierlazily providing the result of applying a mapping function to the mod object of thisRegistryObject, if a mod object is present, otherwise a supplier returningnull
- Throws:
- NullPointerException- if the mapping function is- null
- API Note:
- This method supports post-processing on optional values, without the need to explicitly check for a return status.
 
- 
orElseReturn the mod object if present, otherwise returnother.- Parameters:
- other- the mod object to be returned if there is no mod object present, may be null
- Returns:
- the mod object, if present, otherwise other
 
- 
orElseGetReturn the mod object if present, otherwise invokeotherand return the result of that invocation.- Parameters:
- other- a- Supplierwhose result is returned if no mod object is present
- Returns:
- the mod object if present otherwise the result of other.get()
- Throws:
- NullPointerException- if mod object is not present and- otheris null
 
- 
orElseThrowReturn the contained mod object, if present, otherwise throw an exception to be created by the provided supplier.- Type Parameters:
- X- Type of the exception to be thrown
- Parameters:
- exceptionSupplier- The supplier which will return the exception to be thrown
- Returns:
- the present mod object
- Throws:
- X- if there is no mod object present
- NullPointerException- if no mod object is present and- exceptionSupplieris null
- API Note:
- A method reference to the exception constructor with an empty
 argument list can be used as the supplier. For example,
 IllegalStateException::new
 
- 
getHolderReturns an optionalHolderinstance pointing to this RegistryObject's name and value.This should only be used in cases where vanilla code requires passing in a Holder. Mod-written code should rely on RegistryObjects or Suppliers instead. The returned optional will be empty if the registry does not exist or if returns false.- Returns:
- an optional Holderinstance pointing to this RegistryObject's name and value
 
- 
equals
- 
hashCodepublic int hashCode()
 
-