Interface ItemVariant

All Superinterfaces:
net.minecraft.core.component.DataComponentGetter, net.minecraft.core.component.DataComponentHolder, TransferVariant<net.minecraft.world.item.Item>, net.minecraft.core.TypedInstance<net.minecraft.world.item.Item>

@NonExtendable public interface ItemVariant extends TransferVariant<net.minecraft.world.item.Item>
An immutable count-less ItemStack, i.e. an immutable association of an item and its data components.

Do not implement, use the static of(...) functions instead.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<ItemVariant>
     
    static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf, ItemVariant>
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieve a blank ItemVariant.
    default net.minecraft.world.item.Item
    Return the item of this variant.
    default boolean
    matches(net.minecraft.world.item.ItemStack stack)
    Return true if the item and tag of this variant match those of the passed stack, and false otherwise.
    of(net.minecraft.world.item.ItemStack stack)
    Retrieve an ItemVariant with the item and tag of a stack.
    of(net.minecraft.world.level.ItemLike item)
    Retrieve an ItemVariant with an item and without a tag.
    of(net.minecraft.world.level.ItemLike item, net.minecraft.core.component.DataComponentPatch components)
    Retrieve an ItemVariant with an item and an optional tag.
    default net.minecraft.world.item.ItemStack
    Create a new item stack with count 1 from this variant.
    default net.minecraft.world.item.ItemStack
    toStack(int count)
    Create a new item stack from this variant.
    default net.minecraft.core.Holder<net.minecraft.world.item.Item>
     
    withComponents(net.minecraft.core.component.DataComponentPatch patch)
    Creates a copy of this ItemVariant with the provided component patch applied.

    Methods inherited from interface net.minecraft.core.component.DataComponentGetter

    getTyped

    Methods inherited from interface net.minecraft.core.component.DataComponentHolder

    get, getAllOfType, getOrDefault, has

    Methods inherited from interface net.minecraft.core.TypedInstance

    is, is, is, is, is, tags
  • Field Details

    • CODEC

      static final com.mojang.serialization.Codec<ItemVariant> CODEC
    • PACKET_CODEC

      static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf, ItemVariant> PACKET_CODEC
  • Method Details

    • blank

      static ItemVariant blank()
      Retrieve a blank ItemVariant.
    • of

      static ItemVariant of(net.minecraft.world.item.ItemStack stack)
      Retrieve an ItemVariant with the item and tag of a stack.
    • of

      static ItemVariant of(net.minecraft.world.level.ItemLike item)
      Retrieve an ItemVariant with an item and without a tag.
    • of

      static ItemVariant of(net.minecraft.world.level.ItemLike item, net.minecraft.core.component.DataComponentPatch components)
      Retrieve an ItemVariant with an item and an optional tag.
    • matches

      default boolean matches(net.minecraft.world.item.ItemStack stack)
      Return true if the item and tag of this variant match those of the passed stack, and false otherwise.
    • getItem

      default net.minecraft.world.item.Item getItem()
      Return the item of this variant.
    • typeHolder

      default net.minecraft.core.Holder<net.minecraft.world.item.Item> typeHolder()
      Specified by:
      typeHolder in interface net.minecraft.core.TypedInstance<net.minecraft.world.item.Item>
    • toStack

      default net.minecraft.world.item.ItemStack toStack()
      Create a new item stack with count 1 from this variant.
    • toStack

      default net.minecraft.world.item.ItemStack toStack(int count)
      Create a new item stack from this variant.
      Parameters:
      count - The count of the returned stack. It may lead to counts higher than maximum stack size.
    • withComponents

      ItemVariant withComponents(net.minecraft.core.component.DataComponentPatch patch)
      Creates a copy of this ItemVariant with the provided component patch applied.
      Specified by:
      withComponents in interface TransferVariant<net.minecraft.world.item.Item>
      Parameters:
      patch - the patch to apply
      Returns:
      the new variant with the patch applied
      See Also:
      • ItemStack.applyComponents(DataComponentPatch)