Class RegistryHolder<R,T extends R>

java.lang.Object
net.xun.lib.common.api.registries.RegistryHolder<R,T>
Type Parameters:
R - The base registry type (e.g. Item)
T - The concrete type of the held object (must extend R)
All Implemented Interfaces:
Supplier<T>, net.minecraft.core.Holder<R>, net.neoforged.neoforge.common.extensions.IHolderExtension<R>, net.neoforged.neoforge.registries.datamaps.IWithData<R>
Direct Known Subclasses:
RegistryBlock, RegistryItem

public class RegistryHolder<R,T extends R> extends Object implements net.minecraft.core.Holder<R>, Supplier<T>
A registry-backed holder implementation that wraps a registry entry and its supplier.

This class acts as a bridge between Holder and Supplier, allowing lazy initialization and late binding to actual registry entries.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.minecraft.core.Holder

    net.minecraft.core.Holder.Direct<T>, net.minecraft.core.Holder.Kind, net.minecraft.core.Holder.Reference<T>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final net.minecraft.resources.ResourceKey<R>
    Resource key identifying the held object in the registry
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    RegistryHolder(net.minecraft.resources.ResourceKey<R> key, Supplier<T> supplier)
    Creates a new RegistryHolder instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bind(net.minecraft.core.Holder<R> holder)
    Binds this holder to a concrete registry holder.
    boolean
    canSerializeIn(net.minecraft.core.HolderOwner<R> holderOwner)
    static <R, T extends R>
    RegistryHolder<R,T>
    create(net.minecraft.resources.ResourceKey<R> key, Supplier<T> supplier)
     
    boolean
    get()
    Gets the underlying supplier for the held object.
    int
    net.minecraft.core.Holder<R>
    Gets the underlying registry holder.
    boolean
    is(Predicate<net.minecraft.resources.ResourceKey<R>> predicate)
    boolean
    is(net.minecraft.core.Holder<R> holder)
    Deprecated.
    boolean
    is(net.minecraft.resources.ResourceKey<R> resourceKey)
    boolean
    is(net.minecraft.resources.ResourceLocation resourceLocation)
    boolean
    is(net.minecraft.tags.TagKey<R> tagKey)
    boolean
    net.minecraft.core.Holder.Kind
    Stream<net.minecraft.tags.TagKey<R>>
    com.mojang.datafixers.util.Either<net.minecraft.resources.ResourceKey<R>,R>
    Optional<net.minecraft.resources.ResourceKey<R>>

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.minecraft.core.Holder

    getRegisteredName

    Methods inherited from interface net.neoforged.neoforge.common.extensions.IHolderExtension

    getDelegate, getKey, unwrapLookup

    Methods inherited from interface net.neoforged.neoforge.registries.datamaps.IWithData

    getData
  • Field Details

    • key

      protected final net.minecraft.resources.ResourceKey<R> key
      Resource key identifying the held object in the registry
  • Constructor Details

    • RegistryHolder

      protected RegistryHolder(net.minecraft.resources.ResourceKey<R> key, Supplier<T> supplier)
      Creates a new RegistryHolder instance.
      Parameters:
      key - Resource key identifying the object in the registry
      supplier - Supplier providing the concrete instance of the object
  • Method Details

    • create

      public static <R, T extends R> RegistryHolder<R,T> create(net.minecraft.resources.ResourceKey<R> key, Supplier<T> supplier)
    • getSupplier

      public Supplier<T> getSupplier()
      Gets the underlying supplier for the held object.
      Returns:
      The supplier providing the concrete instance
    • bind

      public void bind(net.minecraft.core.Holder<R> holder)
      Binds this holder to a concrete registry holder.

      This should be called during registry initialization to link the holder to the actual registry entry.

      Parameters:
      holder - The concrete holder from the registry
      Throws:
      IllegalStateException - If already bound
    • holder

      public net.minecraft.core.Holder<R> holder()
      Gets the underlying registry holder.
      Returns:
      The bound holder instance
    • value

      @NotNull public R value()
      Specified by:
      value in interface net.minecraft.core.Holder<R>
      Throws:
      NullPointerException - If accessed before binding
    • get

      public T get()
      Specified by:
      get in interface Supplier<R>
      Throws:
      NullPointerException - If accessed before binding
    • isBound

      public boolean isBound()
      Specified by:
      isBound in interface net.minecraft.core.Holder<R>
    • is

      public boolean is(net.minecraft.resources.ResourceLocation resourceLocation)
      Specified by:
      is in interface net.minecraft.core.Holder<R>
    • is

      public boolean is(net.minecraft.resources.ResourceKey<R> resourceKey)
      Specified by:
      is in interface net.minecraft.core.Holder<R>
    • is

      public boolean is(Predicate<net.minecraft.resources.ResourceKey<R>> predicate)
      Specified by:
      is in interface net.minecraft.core.Holder<R>
    • is

      public boolean is(net.minecraft.tags.TagKey<R> tagKey)
      Specified by:
      is in interface net.minecraft.core.Holder<R>
    • is

      @Deprecated public boolean is(net.minecraft.core.Holder<R> holder)
      Deprecated.
      Specified by:
      is in interface net.minecraft.core.Holder<R>
    • tags

      public Stream<net.minecraft.tags.TagKey<R>> tags()
      Specified by:
      tags in interface net.minecraft.core.Holder<R>
    • unwrap

      public com.mojang.datafixers.util.Either<net.minecraft.resources.ResourceKey<R>,R> unwrap()
      Specified by:
      unwrap in interface net.minecraft.core.Holder<R>
    • unwrapKey

      public Optional<net.minecraft.resources.ResourceKey<R>> unwrapKey()
      Specified by:
      unwrapKey in interface net.minecraft.core.Holder<R>
    • kind

      public net.minecraft.core.Holder.Kind kind()
      Specified by:
      kind in interface net.minecraft.core.Holder<R>
    • canSerializeIn

      public boolean canSerializeIn(net.minecraft.core.HolderOwner<R> holderOwner)
      Specified by:
      canSerializeIn in interface net.minecraft.core.Holder<R>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object