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 ClassesModifier and TypeInterfaceDescriptionstatic interfacestatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ItemStackConstant AIR item.static final NetworkBuffer.Type<ItemStack> static final NetworkBuffer.Type<ItemStack> static final NetworkBuffer.Type<ItemStack> -
Method Summary
Modifier and TypeMethodDescriptionintamount()default HoverEvent<HoverEvent.ShowItem> builder()Converts this itemstack back into a builder (starting from the current state).static ItemStack.Builderconsume(int amount) static ItemStackcopyWithOperator(ItemStack itemStack, UnaryOperator<Component> operator) damage(int amount) static ItemStackfromItemNBT(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()booleanmaterial()default intstatic ItemStackstatic ItemStackstatic ItemStackof(Material material, int amount, DataComponentMap components) static ItemStackof(Material material, DataComponentMap components) static Collection<Component> textComponents(ItemStack itemStack) Converts this item to an NBT tag containing the id (material), count (amount), and components (diff)with(Consumer<ItemStack.Builder> consumer) default ItemStackwith(DataComponent<Unit> component) Returns a new ItemStack with the givenUnitcomponent applied.default <T> ItemStackwith(DataComponent<T> component, UnaryOperator<T> operator) Applies a transformation to the value of a component, only if present.<T> ItemStackwith(DataComponent<T> component, T value) Returns a new ItemStack with the given component set to the given value.withAmount(int amount) default ItemStackwithAmount(IntUnaryOperator intUnaryOperator) default ItemStackwithCustomModelData(List<Float> floats, List<Boolean> flags, List<String> strings, List<RGBLike> colors) default ItemStackwithCustomName(Component customName) default ItemStackwithGlowing(boolean glowing) default ItemStackwithItemModel(String model) default ItemStackdefault ItemStackwithMaterial(Material material) default ItemStackwithMaxStackSize(int maxStackSize) without(DataComponent<?> component) Removes the given component from this item.default ItemStackdefault <T> ItemStackMethods inherited from interface DataComponent.Holder
get, get, hasMethods inherited from interface HoverEventSource
asHoverEventMethods inherited from interface TagReadable
hasTag
-
Field Details
-
NETWORK_TYPE
-
UNTRUSTED_NETWORK_TYPE
-
STRICT_NETWORK_TYPE
-
CODEC
-
AIR
Constant AIR item. Should be used instead of 'null'.
-
-
Method Details
-
builder
-
of
-
of
-
of
-
of
-
fromItemNBT
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
-
componentPatch
-
with
-
withMaterial
-
withAmount
-
withAmount
@Contract(value="_, -> new", pure=true) default ItemStack withAmount(IntUnaryOperator intUnaryOperator) -
with
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
-
with
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
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.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
-
withoutExtraTooltip
-
maxStackSize
-
withMaxStackSize
-
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
-
damage
-
isAir
-
isSimilar
-
builder
ItemStack.Builder builder()Converts this itemstack back into a builder (starting from the current state).- Returns:
- this itemstack, as a builder.
-
toItemNBT
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:
asHoverEventin interfaceHoverEventSource<HoverEvent.ShowItem>
-
textComponents
-
copyWithOperator
-