类 DeferredHolder<R,T extends R>

java.lang.Object
net.neoforged.neoforge.registries.DeferredHolder<R,T>
类型参数:
T - The type of object being held by this DeferredHolder.
所有已实现的接口:
Supplier<T>, Holder<R>, IHolderExtension<R>, IWithData<R>
直接已知子类:
DeferredBlock, DeferredEntityTypeBuilder, DeferredItem

public class DeferredHolder<R,T extends R> extends Object implements Holder<R>, Supplier<T>
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.

  • 字段详细资料

    • key

      protected final ResourceKey<R> key
      The resource key of the target object.
    • holder

      @Nullable private @Nullable Holder<R> holder
      The currently cached value.
  • 构造器详细资料

  • 方法详细资料

    • 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.
      类型参数:
      R - The registry type.
      T - The type of the target value.
      参数:
      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.
      类型参数:
      T - The registry type.
      参数:
      registryName - 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(ResourceKey<R> key)
      Creates a new DeferredHolder targeting the specified value.
      类型参数:
      T - The type of the target value.
      参数:
      key - The resource key of the target value.
    • value

      public T value()
      Gets the object stored by this DeferredHolder, if this holder is bound.
      指定者:
      value 在接口中 Holder<R>
      抛出:
      IllegalStateException - If the backing registry is unavailable.
      NullPointerException - If the underlying Holder has not been populated (the target object is not registered).
    • get

      public T get()
      Gets the object stored by this DeferredHolder, if this holder is bound.
      指定者:
      get 在接口中 Supplier<R>
      抛出:
      IllegalStateException - If the backing registry is unavailable.
      NullPointerException - If the underlying Holder has not been populated (the target object is not registered).
    • asOptional

      public Optional<T> asOptional()
      Returns an optional containing the target object, if bound; otherwise an empty optional.
      返回:
      an optional containing the target object, if bound; otherwise an empty optional
    • getRegistry

      @Nullable protected @Nullable Registry<R> getRegistry()
      Returns the registry that this DeferredHolder is pointing at, or null if it doesn't exist.
      返回:
      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.

      参数:
      throwOnMissingRegistry - If true, an exception will be thrown if the registry is absent.
      抛出:
      IllegalStateException - If throwOnMissingRegistry is true and the backing registry is unavailable.
    • getId

      public ResourceLocation getId()
      返回:
      The ID of the object pointed to by this DeferredHolder.
    • getKey

      public ResourceKey<R> getKey()
      从接口复制的说明: IHolderExtension
      Get 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 with Holder.unwrapKey()
      指定者:
      getKey 在接口中 IHolderExtension<R>
      返回:
      The ResourceKey of the object pointed to by this DeferredHolder.
    • equals

      public boolean equals(Object obj)
      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • isBound

      public boolean isBound()
      返回 true if the underlying object is available。

      If true, the underlying object was added to the registry, and value() or get() can be called.

      指定者:
      isBound 在接口中 Holder<R>
      返回:
      true if the underlying object is available
    • is

      public boolean is(ResourceLocation id)
      返回 true if the passed ResourceLocation is the same as the ID of the target object。
      指定者:
      is 在接口中 Holder<R>
      返回:
      true if the passed ResourceLocation is the same as the ID of the target object
    • is

      public boolean is(ResourceKey<R> key)
      返回 true if the passed ResourceKey is the same as this holder's resource key。
      指定者:
      is 在接口中 Holder<R>
      返回:
      true if the passed ResourceKey is the same as this holder's resource key
    • is

      public boolean is(Predicate<ResourceKey<R>> filter)
      Evaluates the passed predicate against this holder's resource key.
      指定者:
      is 在接口中 Holder<R>
      返回:
      true if the filter matches this DH's resource key
    • is

      public boolean is(TagKey<R> tag)
      返回 true if this holder is a member of the passed tag。
      指定者:
      is 在接口中 Holder<R>
      返回:
      true if this holder is a member of the passed tag
    • is

      @Deprecated public boolean is(Holder<R> holder)
      已过时。
      返回 true if the holder is the same as this holder。
      指定者:
      is 在接口中 Holder<R>
      返回:
      true if the holder is the same as this holder
    • getData

      @Nullable public <Z> Z getData(DataMapType<R,Z> type)
      返回 the data of the given type that is attached to this object, or null if one isn't。
      指定者:
      getData 在接口中 IWithData<R>
      类型参数:
      Z - the type of the data
      参数:
      type - the data type
      返回:
      the data of the given type that is attached to this object, or null if one isn't
    • tags

      public Stream<TagKey<R>> tags()
      返回 all tags present on the underlying object。

      If the underlying object is not bound yet, and empty stream is returned.

      指定者:
      tags 在接口中 Holder<R>
      返回:
      all tags present on the underlying object
    • unwrap

      public com.mojang.datafixers.util.Either<ResourceKey<R>,R> unwrap()
      Returns an Either.left() containing the resource key of this holder.
      指定者:
      unwrap 在接口中 Holder<R>
      API Note:
      This method is implemented for Holder compatibility, but getKey() should be preferred.
    • unwrapKey

      public Optional<ResourceKey<R>> unwrapKey()
      Returns the resource key of this holder.
      指定者:
      unwrapKey 在接口中 Holder<R>
      返回:
      a present optional containing the resource key of this holder
      API Note:
      This method is implemented for Holder compatibility, but getKey() should be preferred.
    • kind

      public Holder.Kind kind()
      指定者:
      kind 在接口中 Holder<R>
    • canSerializeIn

      public boolean canSerializeIn(HolderOwner<R> owner)
      指定者:
      canSerializeIn 在接口中 Holder<R>
    • getDelegate

      public Holder<R> getDelegate()
      从接口复制的说明: IHolderExtension
      返回 the holder that this holder wraps。 Used by Registry.safeCastToReference(net.minecraft.core.Holder<T>) to resolve the underlying Holder.Reference for delegating holders.
      指定者:
      getDelegate 在接口中 IHolderExtension<R>
      返回:
      the holder that this holder wraps