Class DeferredHolder<R,T extends R>
java.lang.Object
net.neoforged.neoforge.registries.DeferredHolder<R,T>
- Type Parameters:
T- The type of object being held by this DeferredHolder.
- Direct Known Subclasses:
DeferredBlock,DeferredItem
A Deferred Holder is a
Holder that is constructed with only a ResourceKey.
It will be populated with the underlying Holder from the registry when available.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minecraft.core.Holder
Holder.Direct<T>, Holder.Kind, Holder.Reference<T> -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDeferredHolder(ResourceKey<R> key) Creates a new DeferredHolder with a ResourceKey. -
Method Summary
Modifier and TypeMethodDescriptionReturns an optional containing the target object, ifbound; otherwise an empty optional.protected final voidbind(boolean throwOnMissingRegistry) Binds this DeferredHolder to the underlying registry and target object.booleancanSerializeIn(HolderOwner<R> owner) static <R,T extends R>
DeferredHolder<R,T> create(ResourceKey<? extends Registry<R>> registryKey, ResourceLocation valueName) Creates a new DeferredHolder targeting the value with the specified name in the specified registry.static <R,T extends R>
DeferredHolder<R,T> create(ResourceKey<R> key) Creates a new DeferredHolder targeting the specified value.static <R,T extends R>
DeferredHolder<R,T> create(ResourceLocation registryName, ResourceLocation valueName) Creates a new DeferredHolder targeting the value with the specified name in the specified registry.booleanget()Gets the object stored by this DeferredHolder, if this holder is bound.getId()getKey()Returns the registry that this DeferredHolder is pointing at, ornullif it doesn't exist.inthashCode()booleanis(Predicate<ResourceKey<R>> filter) Evaluates the passed predicate against this holder's resource key.booleanis(ResourceKey<R> key) Returns true if the passed ResourceKey is the same as this holder's resource key.booleanis(ResourceLocation id) Returns true if the passed ResourceLocation is the same as the ID of the target object.booleanReturns true if this holder is a member of the passed tag.booleanisBound()Returns true if the underlying object is available.kind()tags()Returns all tags present on the underlying object.toString()com.mojang.datafixers.util.Either<ResourceKey<R>,R> unwrap()Returns anEither.left()containing the resource key of this holder.Returns the resource key of this holder.value()Gets the object stored by this DeferredHolder, if this holder is bound.
-
Field Details
-
key
The resource key of the target object. -
holder
The currently cached value.
-
-
Constructor Details
-
DeferredHolder
Creates a new DeferredHolder with a ResourceKey.Attempts to bind immediately if possible.
- Parameters:
key- The resource key of the target object.- See Also:
-
-
Method Details
-
create
public static <R,T extends R> DeferredHolder<R,T> create(ResourceKey<? extends Registry<R>> registryKey, ResourceLocation valueName) Creates a new DeferredHolder targeting the value with the specified name in the specified registry.- Type Parameters:
T- The type of the target value.R- The registry type.- Parameters:
registryKey- The name of the registry the target value is a member of.valueName- The name of the target value.
-
create
public static <R,T extends R> DeferredHolder<R,T> create(ResourceLocation registryName, ResourceLocation valueName) Creates a new DeferredHolder targeting the value with the specified name in the specified registry.- Type Parameters:
T- The registry type.- Parameters:
registryName- The name of the registry the target value is a member of.valueName- The name of the target value.
-
create
Creates a new DeferredHolder targeting the specified value.- Type Parameters:
T- The type of the target value.- Parameters:
key- The resource key of the target value.
-
value
Gets the object stored by this DeferredHolder, if this holder is bound.- Specified by:
valuein interfaceHolder<R>- Throws:
IllegalStateException- If the backing registry is unavailable.NullPointerException- If the underlying Holder has not been populated (the target object is not registered).
-
get
Gets the object stored by this DeferredHolder, if this holder is bound.- Specified by:
getin interfaceSupplier<R>- Throws:
IllegalStateException- If the backing registry is unavailable.NullPointerException- If the underlying Holder has not been populated (the target object is not registered).
-
asOptional
Returns an optional containing the target object, ifbound; otherwise an empty optional.- Returns:
- an optional containing the target object, if
bound; otherwise an empty optional
-
getRegistry
Returns the registry that this DeferredHolder is pointing at, ornullif it doesn't exist.- Returns:
- the registry that this DeferredHolder is pointing at, or
nullif it doesn't exist
-
bind
protected final void bind(boolean throwOnMissingRegistry) Binds this DeferredHolder to the underlying registry and target object.Has no effect if already bound.
- Parameters:
throwOnMissingRegistry- If true, an exception will be thrown if the registry is absent.- Throws:
IllegalStateException- If throwOnMissingRegistry is true and the backing registry is unavailable.
-
getId
- Returns:
- The ID of the object pointed to by this DeferredHolder.
-
getKey
- Returns:
- The ResourceKey of the object pointed to by this DeferredHolder.
-
equals
-
hashCode
public int hashCode() -
toString
-
isBound
public boolean isBound() -
is
Returns true if the passed ResourceLocation is the same as the ID of the target object. -
is
Returns true if the passed ResourceKey is the same as this holder's resource key. -
is
Evaluates the passed predicate against this holder's resource key.- Specified by:
isin interfaceHolder<R>- Returns:
trueif the filter matches this DH's resource key
-
is
Returns true if this holder is a member of the passed tag. -
tags
Returns all tags present on the underlying object.If the underlying object is not bound yet, and empty stream is returned.
-
unwrap
Returns anEither.left()containing the resource key of this holder. -
unwrapKey
Returns the resource key of this holder. -
kind
-
canSerializeIn
- Specified by:
canSerializeInin interfaceHolder<R>
-