Interface ItemStackLike
- All Superinterfaces:
ComponentLike
,CopyableDataHolder
,DataHolder
,DataSerializable
,HoverEventSource<HoverEvent.ShowItem>
,SerializableDataHolder
,ValueContainer
- All Known Subinterfaces:
ItemStack
,ItemStackSnapshot
public interface ItemStackLike
extends SerializableDataHolder, ComponentLike, HoverEventSource<HoverEvent.ShowItem>
Represents a stack of a specific
ItemType
. Supports serialization.
ItemStackLike
have a variety of properties and data. It is advised to
use ValueContainer.get(Key)
in order to retrieve information regarding
this item stack.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.spongepowered.api.data.SerializableDataHolder
SerializableDataHolder.Immutable<I extends SerializableDataHolder.Immutable<I>>, SerializableDataHolder.Mutable
-
Method Summary
Modifier and TypeMethodDescriptionRetrieves an immutable form of thisItemStackLike
.Retrieves a mutable form of thisItemStackLike
.Retrieves a copy in the mutable form of thisItemStackLike
.default Collection
<AttributeModifier> attributeModifiers
(Supplier<? extends AttributeType> attributeType, EquipmentType equipmentType) Gets allAttributeModifier
s on thisItemStackLike
.default Collection
<AttributeModifier> attributeModifiers
(Supplier<? extends AttributeType> attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType) Gets allAttributeModifier
s on thisItemStackLike
.attributeModifiers
(AttributeType attributeType, EquipmentType equipmentType) Gets allAttributeModifier
s on thisItemStackLike
.default Collection
<AttributeModifier> attributeModifiers
(AttributeType attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType) Gets allAttributeModifier
s on thisItemStackLike
.copy()
Creates a clone copy of thisCopyableDataHolder
as a newCopyableDataHolder
such that all theValue
s are safely duplicated to the new instance.boolean
isEmpty()
Returns true ifquantity()
is zero and therefore thisItemStackLike
is empty.default int
Gets the maximum quantity per stack.int
quantity()
Gets the quantity of items in this stack.type()
Gets theItemType
of thisItemStackLike
.Methods inherited from interface net.kyori.adventure.text.ComponentLike
asComponent
Methods inherited from interface org.spongepowered.api.data.persistence.DataSerializable
contentVersion, toContainer
Methods inherited from interface net.kyori.adventure.text.event.HoverEventSource
asHoverEvent, asHoverEvent
Methods inherited from interface org.spongepowered.api.data.SerializableDataHolder
validateRawData
-
Method Details
-
type
ItemType type()Gets theItemType
of thisItemStackLike
.- Returns:
- The item type
-
quantity
int quantity()Gets the quantity of items in this stack. This may exceed the max stack size of the item, and if added to an inventory will then be divided by the max stack.- Returns:
- Quantity of items
-
maxStackQuantity
default int maxStackQuantity()Gets the maximum quantity per stack. By default, returnsItemType.maxStackQuantity()
, unless a different value has been set for this specific stack.- Returns:
- Max stack quantity
-
isEmpty
boolean isEmpty()Returns true ifquantity()
is zero and therefore thisItemStackLike
is empty.In Vanilla empty ItemStacks are not rendered by the client.
- Returns:
- True if this ItemStackLike is empty
-
attributeModifiers
default Collection<AttributeModifier> attributeModifiers(Supplier<? extends AttributeType> attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType) Gets allAttributeModifier
s on thisItemStackLike
.- Parameters:
attributeType
- TheAttributeType
of the modifier.equipmentType
- TheEquipmentType
this modifier is applied. to.- Returns:
- A collection of
AttributeModifier
s.
-
attributeModifiers
default Collection<AttributeModifier> attributeModifiers(AttributeType attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType) Gets allAttributeModifier
s on thisItemStackLike
.- Parameters:
attributeType
- TheAttributeType
of the modifier.equipmentType
- TheEquipmentType
this modifier is applied. to.- Returns:
- A collection of
AttributeModifier
s.
-
attributeModifiers
default Collection<AttributeModifier> attributeModifiers(Supplier<? extends AttributeType> attributeType, EquipmentType equipmentType) Gets allAttributeModifier
s on thisItemStackLike
.- Parameters:
attributeType
- TheAttributeType
of the modifier.equipmentType
- TheEquipmentType
this modifier is applied. to.- Returns:
- A collection of
AttributeModifier
s.
-
attributeModifiers
Collection<AttributeModifier> attributeModifiers(AttributeType attributeType, EquipmentType equipmentType) Gets allAttributeModifier
s on thisItemStackLike
.- Parameters:
attributeType
- TheAttributeType
of the modifier.equipmentType
- TheEquipmentType
this modifier is applied. to.- Returns:
- A collection of
AttributeModifier
s.
-
asMutable
ItemStack asMutable()Retrieves a mutable form of thisItemStackLike
. If this ItemStackLike is already mutable, this would simply return itself. In other cases, a newItemStack
is created with all the data currently available on thisItemStackLike
.- Returns:
- An ItemStack
-
asMutableCopy
ItemStack asMutableCopy()Retrieves a copy in the mutable form of thisItemStackLike
. The newItemStack
is created with all the data currently available on thisItemStackLike
.- Returns:
- A new ItemStack
-
asImmutable
ItemStackSnapshot asImmutable()Retrieves an immutable form of thisItemStackLike
. If this ItemStackLike is already immutable, this would simply return itself. In other cases, a newItemStackSnapshot
is created with all knownValue
s existing on thisItemStackLike
added as copies to theItemStackSnapshot
.- Returns:
- An ItemStackSnapshot
-
copy
ItemStackLike copy()Description copied from interface:CopyableDataHolder
Creates a clone copy of thisCopyableDataHolder
as a newCopyableDataHolder
such that all theValue
s are safely duplicated to the new instance. It is not guaranteed that the returning container is of the same type as this container.- Specified by:
copy
in interfaceCopyableDataHolder
- Specified by:
copy
in interfaceSerializableDataHolder
- Returns:
- The new copy
-