Class RegistryItem<T extends net.minecraft.world.item.Item>

java.lang.Object
net.xun.lib.common.api.registries.RegistryHolder<net.minecraft.world.item.Item,T>
net.xun.lib.common.api.registries.RegistryItem<T>
Type Parameters:
T - The concrete item type (must extend Item)
All Implemented Interfaces:
Supplier<T>, net.minecraft.core.Holder<net.minecraft.world.item.Item>, net.minecraft.world.level.ItemLike, net.neoforged.neoforge.common.extensions.IHolderExtension<net.minecraft.world.item.Item>, net.neoforged.neoforge.registries.datamaps.IWithData<net.minecraft.world.item.Item>

public class RegistryItem<T extends net.minecraft.world.item.Item> extends RegistryHolder<net.minecraft.world.item.Item,T> implements net.minecraft.world.level.ItemLike
A specialized registry holder implementation for items that implements ItemLike.

This class provides convenient methods for working with items, including creating item stacks of varying sizes.

  • 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 inherited from class net.xun.lib.common.api.registries.RegistryHolder

    key
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    RegistryItem(net.minecraft.resources.ResourceKey<net.minecraft.world.item.Item> key, Supplier<T> supplier)
    Constructs a new item registry holder.
  • Method Summary

    Modifier and Type
    Method
    Description
    net.minecraft.world.item.Item
    Gets this item instance.
    void
    bind(net.minecraft.core.Holder<net.minecraft.world.item.Item> holder)
    Binds this holder to a concrete registry holder.
    static <T extends net.minecraft.world.item.Item>
    RegistryItem<T>
    createItem(net.minecraft.resources.ResourceKey<net.minecraft.world.item.Item> key, Supplier<T> supplier)
    Creates a new item registry holder using a ResourceKey.
    static <T extends net.minecraft.world.item.Item>
    RegistryItem<T>
    createItem(net.minecraft.resources.ResourceLocation key, Supplier<T> supplier)
    Creates a new item registry holder using a ResourceLocation.
    net.minecraft.world.item.ItemStack
    Creates an ItemStack of this item with a count of 1.
    net.minecraft.world.item.ItemStack
    toStack(int count)
    Creates an ItemStack of this item with the specified count.

    Methods inherited from class net.xun.lib.common.api.registries.RegistryHolder

    canSerializeIn, create, equals, get, getSupplier, hashCode, holder, is, is, is, is, is, isBound, kind, tags, unwrap, unwrapKey, value

    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
  • Constructor Details

    • RegistryItem

      protected RegistryItem(net.minecraft.resources.ResourceKey<net.minecraft.world.item.Item> key, Supplier<T> supplier)
      Constructs a new item registry holder.
      Parameters:
      key - The resource key identifying the item
      supplier - Supplier providing the item instance
  • Method Details

    • toStack

      public net.minecraft.world.item.ItemStack toStack()
      Creates an ItemStack of this item with a count of 1.
      Returns:
      The created item stack
      Throws:
      IllegalStateException - If the created stack is unexpectedly empty
    • toStack

      public net.minecraft.world.item.ItemStack toStack(int count)
      Creates an ItemStack of this item with the specified count.
      Parameters:
      count - The stack size
      Returns:
      The created item stack
      Throws:
      IllegalStateException - If the created stack is unexpectedly empty
    • createItem

      public static <T extends net.minecraft.world.item.Item> RegistryItem<T> createItem(net.minecraft.resources.ResourceLocation key, Supplier<T> supplier)
      Creates a new item registry holder using a ResourceLocation.
      Type Parameters:
      T - The concrete item type
      Parameters:
      key - The resource location identifying the item
      supplier - Supplier providing the item instance
      Returns:
      The created registry holder
    • createItem

      public static <T extends net.minecraft.world.item.Item> RegistryItem<T> createItem(net.minecraft.resources.ResourceKey<net.minecraft.world.item.Item> key, Supplier<T> supplier)
      Creates a new item registry holder using a ResourceKey.
      Type Parameters:
      T - The concrete item type
      Parameters:
      key - The resource key identifying the item
      supplier - Supplier providing the item instance
      Returns:
      The created registry holder
    • asItem

      public net.minecraft.world.item.Item asItem()
      Gets this item instance.
      Specified by:
      asItem in interface net.minecraft.world.level.ItemLike
      Returns:
      The item itself
    • bind

      public void bind(net.minecraft.core.Holder<net.minecraft.world.item.Item> holder)
      Binds this holder to a concrete registry holder.
      Overrides:
      bind in class RegistryHolder<net.minecraft.world.item.Item,T extends net.minecraft.world.item.Item>
      Parameters:
      holder - The concrete holder from the registry