Interface ItemStack

All Superinterfaces:
DataComponent.Holder, HoverEventSource<HoverEvent.ShowItem>, TagReadable

public sealed interface ItemStack extends TagReadable, DataComponent.Holder, HoverEventSource<HoverEvent.ShowItem>
Represents an immutable item to be placed inside PlayerInventory, Inventory or even on the ground ItemEntity.

An item stack cannot be null, AIR should be used instead.

  • Field Details

  • Method Details

    • builder

      @Contract(value="_ -> new", pure=true) static ItemStack.Builder builder(Material material)
    • of

      @Contract(value="_ -> new", pure=true) static ItemStack of(Material material)
    • of

      @Contract(value="_ ,_ -> new", pure=true) static ItemStack of(Material material, int amount)
    • of

      @Contract(value="_ ,_ -> new", pure=true) static ItemStack of(Material material, DataComponentMap components)
    • of

      @Contract(value="_ ,_, _ -> new", pure=true) static ItemStack of(Material material, int amount, DataComponentMap components)
    • fromItemNBT

      static ItemStack fromItemNBT(net.kyori.adventure.nbt.CompoundBinaryTag nbtCompound)
      Converts this item to an NBT tag containing the id (material), count (amount), and components.
      Parameters:
      nbtCompound - The nbt representation of the item
    • material

      @Contract(pure=true) Material material()
    • amount

      @Contract(pure=true) int amount()
    • componentPatch

      @Contract(pure=true) DataComponentMap componentPatch()
    • with

      @Contract(value="_, -> new", pure=true) ItemStack with(Consumer<ItemStack.Builder> consumer)
    • withMaterial

      @Contract(value="_, -> new", pure=true) ItemStack withMaterial(Material material)
    • withAmount

      @Contract(value="_, -> new", pure=true) ItemStack withAmount(int amount)
    • withAmount

      @Contract(value="_, -> new", pure=true) default ItemStack withAmount(IntUnaryOperator intUnaryOperator)
    • with

      @Contract(value="_, _ -> new", pure=true) <T> ItemStack with(DataComponent<T> component, T value)

      Returns a new ItemStack with the given component set to the given value.

      Note: this should not be used to remove components, see without(DataComponent).

    • with

      @Contract(value="_ -> new", pure=true) default ItemStack with(DataComponent<Unit> component)
      Returns a new ItemStack with the given Unit component applied.
      Parameters:
      component - The unit component to apply
      Returns:
      A new ItemStack with the given component applied
    • with

      default <T> ItemStack with(DataComponent<T> component, UnaryOperator<T> operator)
      Applies a transformation to the value of a component, only if present.
      Type Parameters:
      T - The component type
      Parameters:
      component - The component type to modify
      operator - The transformation function
      Returns:
      A new ItemStack if the component was transformed, otherwise this.
    • without

      @Contract(value="_, -> new", pure=true) ItemStack without(DataComponent<?> component)

      Removes the given component from this item. This will explicitly remove the component from the item, as opposed to reverting back to the default.

      For example, if DataComponents.FOOD is applied to an apple, and then this method is called, the resulting itemstack will not be a food item at all, as opposed to returning to the default apple food type. Likewise, if this method is called on a default apple, it will no longer be a food item.

      Parameters:
      component - The component to remove
      Returns:
      A new ItemStack without the given component
    • withCustomName

      @Contract(value="_, -> new", pure=true) default ItemStack withCustomName(Component customName)
    • withLore

      @Contract(value="_, -> new", pure=true) default ItemStack withLore(Component... lore)
    • withLore

      @Contract(value="_, -> new", pure=true) default ItemStack withLore(List<Component> lore)
    • withItemModel

      @Contract(value="_, -> new", pure=true) default ItemStack withItemModel(String model)
    • withCustomModelData

      @Contract(value="_, _, _, _ -> new", pure=true) default ItemStack withCustomModelData(List<Float> floats, List<Boolean> flags, List<String> strings, List<RGBLike> colors)
    • withGlowing

      @Contract(value="_ -> new", pure=true) default ItemStack withGlowing(boolean glowing)
    • withoutExtraTooltip

      @Contract(value="-> new", pure=true) default ItemStack withoutExtraTooltip()
    • maxStackSize

      @Contract(pure=true) default int maxStackSize()
    • withMaxStackSize

      @Contract(value="_ -> new", pure=true) default ItemStack withMaxStackSize(int maxStackSize)
    • withTag

      @Contract(value="_, _ -> new", pure=true) default <T> ItemStack withTag(Tag<T> tag, @Nullable T value)
    • getTag

      @Contract(pure=true) default <T> @UnknownNullability T getTag(Tag<T> tag)
      Description copied from interface: TagReadable
      Reads the specified tag.
      Specified by:
      getTag in interface TagReadable
      Type Parameters:
      T - the tag type
      Parameters:
      tag - the tag to read
      Returns:
      the read tag, null if not present
    • consume

      @Contract(value="_, -> new", pure=true) ItemStack consume(int amount)
    • damage

      @Contract(value="_, -> new", pure=true) ItemStack damage(int amount)
    • isAir

      @Contract(pure=true) default boolean isAir()
    • isSimilar

      @Contract(pure=true) boolean isSimilar(ItemStack itemStack)
    • builder

      Converts this itemstack back into a builder (starting from the current state).
      Returns:
      this itemstack, as a builder.
    • toItemNBT

      net.kyori.adventure.nbt.CompoundBinaryTag toItemNBT()
      Converts this item to an NBT tag containing the id (material), count (amount), and components (diff)
      Returns:
      The nbt representation of the item
    • asHoverEvent

      Specified by:
      asHoverEvent in interface HoverEventSource<HoverEvent.ShowItem>
    • textComponents

      static Collection<Component> textComponents(ItemStack itemStack)
    • copyWithOperator

      static ItemStack copyWithOperator(ItemStack itemStack, UnaryOperator<Component> operator)