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, DeferredItem
-
Nested Class Summary
Nested classes/interfaces inherited from interface 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 TypeMethodDescriptionbooleanReturns 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(Identifier registryName, Identifier 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<? extends Registry<R>> registryKey, Identifier 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.booleanget()Gets the object stored by this DeferredHolder, if this holder is bound.<Z> @Nullable ZgetData(DataMapType<R, Z> type) Returns the data of the given type that is attached to this object, ornullif one isn't.Returns the holder that this holder wraps.getId()getKey()Get the resource key held by this Holder, or null if none is present.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.booleanDeprecated.booleanis(Identifier id) Returns true if the passed Identifier is the same as the ID of the target object.booleanis(ResourceKey<R> key) Returns true if the passed ResourceKey is the same as this holder's resource key.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.Methods inherited from interface Holder
getRegisteredNameMethods inherited from interface IHolderExtension
unwrapLookup
-
Field Details
-
key
The resource key of the target object. -
holder
-
-
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, Identifier 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(Identifier registryName, Identifier 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
-
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
Description copied from interface:IHolderExtensionGet the resource key held by this Holder, or null if none is present. This method will be overriden by Holder implementations to avoid allocation associated withHolder.unwrapKey()- Specified by:
getKeyin interfaceIHolderExtension<R>- Returns:
- The ResourceKey of the object pointed to by this DeferredHolder.
-
equals
-
hashCode
-
toString
-
isBound
-
areComponentsBound
public boolean areComponentsBound()- Specified by:
areComponentsBoundin interfaceHolder<R>
-
components
- Specified by:
componentsin interfaceHolder<R>
-
is
Returns true if the passed Identifier 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
-
is
-
getData
Returns the data of the given type that is attached to this object, ornullif one isn't. -
tags
-
unwrap
Returns anEither.left()containing the resource key of this holder. -
unwrapKey
Returns the resource key of this holder.- Specified by:
unwrapKeyin interfaceHolder<R>- Returns:
- a present optional containing the resource key of this holder
-
kind
-
canSerializeIn
- Specified by:
canSerializeInin interfaceHolder<R>
-
getDelegate
Description copied from interface:IHolderExtensionReturns the holder that this holder wraps. Used byRegistry.safeCastToReference(Holder)to resolve the underlyingHolder.Referencefor delegating holders.- Specified by:
getDelegatein interfaceIHolderExtension<R>- Returns:
- the holder that this holder wraps
-