Package net.minestom.server.item
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final @NotNull ItemStackConstant AIR item.static final @NotNull BinaryTagSerializer<ItemStack> static final NetworkBuffer.Type<ItemStack> static final NetworkBuffer.Type<ItemStack> -
Method Summary
Modifier and TypeMethodDescriptionintamount()default @NotNull HoverEvent<HoverEvent.ShowItem> asHoverEvent(@NotNull UnaryOperator<HoverEvent.ShowItem> op) builder()Converts this itemstack back into a builder (starting from the current state).static @NotNull ItemStack.Builder@NotNull ItemStackconsume(int amount) static @NotNull ItemStackcopyWithOperator(@NotNull ItemStack itemStack, @NotNull UnaryOperator<Component> operator) static @NotNull ItemStackfromItemNBT(@NotNull net.kyori.adventure.nbt.CompoundBinaryTag nbtCompound) Converts this item to an NBT tag containing the id (material), count (amount), and components.default <T> @UnknownNullability TReads the specified tag.default booleanisAir()boolean@NotNull Materialmaterial()default intstatic @NotNull ItemStackstatic @NotNull ItemStackstatic @NotNull ItemStackof(@NotNull Material material, int amount, @NotNull DataComponentMap components) static @NotNull ItemStackof(@NotNull Material material, @NotNull DataComponentMap components) static @NotNull Collection<Component> textComponents(@NotNull ItemStack itemStack) @NotNull net.kyori.adventure.nbt.CompoundBinaryTagConverts this item to an NBT tag containing the id (material), count (amount), and components (diff)@NotNull ItemStackwith(@NotNull Consumer<@NotNull ItemStack.Builder> consumer) default @NotNull ItemStackwith(@NotNull DataComponent<Unit> component) Returns a new ItemStack with the givenUnitcomponent applied.default <T> @NotNull ItemStackwith(@NotNull DataComponent<T> component, @NotNull UnaryOperator<T> operator) Applies a transformation to the value of a component, only if present.<T> @NotNull ItemStackwith(@NotNull DataComponent<T> component, T value) Returns a new ItemStack with the given component set to the given value.@NotNull ItemStackwithAmount(int amount) default @NotNull ItemStackwithAmount(@NotNull IntUnaryOperator intUnaryOperator) default @NotNull ItemStackwithCustomModelData(@NotNull List<Float> floats, @NotNull List<Boolean> flags, @NotNull List<String> strings, @NotNull List<RGBLike> colors) default @NotNull ItemStackwithCustomName(@NotNull Component customName) default @NotNull ItemStackwithGlowing(boolean glowing) default @NotNull ItemStackwithItemModel(@NotNull String model) default @NotNull ItemStackdefault @NotNull ItemStack@NotNull ItemStackwithMaterial(@NotNull Material material) default @NotNull ItemStackwithMaxStackSize(int maxStackSize) @NotNull ItemStackwithout(@NotNull DataComponent<?> component) Removes the given component from this item.default @NotNull ItemStackdefault <T> @NotNull ItemStackMethods inherited from interface net.minestom.server.component.DataComponent.Holder
get, get, hasMethods inherited from interface net.kyori.adventure.text.event.HoverEventSource
asHoverEventMethods inherited from interface net.minestom.server.tag.TagReadable
hasTag
-
Field Details
-
NETWORK_TYPE
-
STRICT_NETWORK_TYPE
-
NBT_TYPE
-
AIR
Constant AIR item. Should be used instead of 'null'.
-
-
Method Details
-
builder
@Contract(value="_ -> new", pure=true) @NotNull static @NotNull ItemStack.Builder builder(@NotNull @NotNull Material material) -
of
-
of
-
of
@Contract(value="_ ,_ -> new", pure=true) @NotNull static @NotNull ItemStack of(@NotNull @NotNull Material material, @NotNull @NotNull DataComponentMap components) -
of
@Contract(value="_ ,_, _ -> new", pure=true) @NotNull static @NotNull ItemStack of(@NotNull @NotNull Material material, int amount, @NotNull @NotNull DataComponentMap components) -
fromItemNBT
@NotNull static @NotNull ItemStack fromItemNBT(@NotNull @NotNull 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
-
amount
@Contract(pure=true) int amount() -
with
@Contract(value="_, -> new", pure=true) @NotNull @NotNull ItemStack with(@NotNull @NotNull Consumer<@NotNull ItemStack.Builder> consumer) -
withMaterial
-
withAmount
-
withAmount
@Contract(value="_, -> new", pure=true) @NotNull default @NotNull ItemStack withAmount(@NotNull @NotNull IntUnaryOperator intUnaryOperator) -
with
@Contract(value="_, _ -> new", pure=true) @NotNull <T> @NotNull ItemStack with(@NotNull @NotNull DataComponent<T> component, @NotNull 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) @NotNull default @NotNull ItemStack with(@NotNull @NotNull DataComponent<Unit> component) Returns a new ItemStack with the givenUnitcomponent applied.- Parameters:
component- The unit component to apply- Returns:
- A new ItemStack with the given component applied
-
with
@NotNull default <T> @NotNull ItemStack with(@NotNull @NotNull DataComponent<T> component, @NotNull @NotNull 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 modifyoperator- The transformation function- Returns:
- A new ItemStack if the component was transformed, otherwise this.
-
without
@Contract(value="_, -> new", pure=true) @NotNull @NotNull ItemStack without(@NotNull @NotNull 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
ItemComponent.FOODis 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
-
withLore
-
withLore
-
withItemModel
-
withCustomModelData
-
withGlowing
@Contract(value="_ -> new", pure=true) @NotNull default @NotNull ItemStack withGlowing(boolean glowing) -
withoutExtraTooltip
-
maxStackSize
@Contract(pure=true) default int maxStackSize() -
withMaxStackSize
@Contract(value="_ -> new", pure=true) @NotNull default @NotNull ItemStack withMaxStackSize(int maxStackSize) -
withTag
-
getTag
Description copied from interface:TagReadableReads the specified tag.- Specified by:
getTagin interfaceTagReadable- Type Parameters:
T- the tag type- Parameters:
tag- the tag to read- Returns:
- the read tag, null if not present
-
consume
-
isAir
@Contract(pure=true) default boolean isAir() -
isSimilar
-
builder
Converts this itemstack back into a builder (starting from the current state).- Returns:
- this itemstack, as a builder.
-
toItemNBT
@NotNull @NotNull 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
@NotNull default @NotNull HoverEvent<HoverEvent.ShowItem> asHoverEvent(@NotNull @NotNull UnaryOperator<HoverEvent.ShowItem> op) - Specified by:
asHoverEventin interfaceHoverEventSource<HoverEvent.ShowItem>
-
textComponents
@NotNull static @NotNull Collection<Component> textComponents(@NotNull @NotNull ItemStack itemStack) -
copyWithOperator
@NotNull static @NotNull ItemStack copyWithOperator(@NotNull @NotNull ItemStack itemStack, @NotNull @NotNull UnaryOperator<Component> operator)
-