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.
- All Implemented Interfaces:
Supplier<T>
,Holder<R>
,IHolderExtension<R>
,IWithData<R>
- Direct Known Subclasses:
DeferredBlock
,DeferredEntityTypeBuilder
,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
-
Constructor Summary
ModifierConstructorDescriptionprotected
DeferredHolder
(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 void
bind
(boolean throwOnMissingRegistry) Binds this DeferredHolder to the underlying registry and target object.boolean
canSerializeIn
(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.boolean
get()
Gets the object stored by this DeferredHolder, if this holder is bound.<Z> Z
getData
(DataMapType<R, Z> type) Returns the data of the given type that is attached to this object, ornull
if one isn't.Returns the holder that this holder wraps.getId()
getKey()
Returns the registry that this DeferredHolder is pointing at, ornull
if it doesn't exist.int
hashCode()
boolean
is
(Predicate<ResourceKey<R>> filter) Evaluates the passed predicate against this holder's resource key.boolean
Deprecated.boolean
is
(ResourceKey<R> key) Returns true if the passed ResourceKey is the same as this holder's resource key.boolean
is
(ResourceLocation id) Returns true if the passed ResourceLocation is the same as the ID of the target object.boolean
Returns true if this holder is a member of the passed tag.boolean
isBound()
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.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.minecraft.core.Holder
getRegisteredName
Methods inherited from interface net.neoforged.neoforge.common.extensions.IHolderExtension
unwrapLookup
-
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:
R
- The registry type.T
- The type of the target value.- 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:
value
in 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:
get
in 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, ornull
if it doesn't exist.- Returns:
- the registry that this DeferredHolder is pointing at, or
null
if 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:
is
in interfaceHolder<R>
- Returns:
true
if the filter matches this DH's resource key
-
is
Returns true if this holder is a member of the passed tag. -
is
Deprecated.Returnstrue
if theholder
is the same as this holder. -
getData
Returns the data of the given type that is attached to this object, ornull
if one isn't. -
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.- Specified by:
unwrapKey
in interfaceHolder<R>
- Returns:
- a present optional containing the resource key of this holder
-
kind
-
canSerializeIn
- Specified by:
canSerializeIn
in interfaceHolder<R>
-
getDelegate
Description copied from interface:IHolderExtension
Returns the holder that this holder wraps. Used byRegistry.safeCastToReference(net.minecraft.core.Holder<T>)
to resolve the underlyingHolder.Reference
for delegating holders.- Specified by:
getDelegate
in interfaceIHolderExtension<R>
- Returns:
- the holder that this holder wraps
-