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 allAttributeModifiers on thisItemStackLike.default Collection<AttributeModifier> attributeModifiers(Supplier<? extends AttributeType> attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType) Gets allAttributeModifiers on thisItemStackLike.attributeModifiers(AttributeType attributeType, EquipmentType equipmentType) Gets allAttributeModifiers on thisItemStackLike.default Collection<AttributeModifier> attributeModifiers(AttributeType attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType) Gets allAttributeModifiers on thisItemStackLike.copy()Creates a clone copy of thisCopyableDataHolderas a newCopyableDataHoldersuch that all theValues are safely duplicated to the new instance.booleanisEmpty()Returns true ifquantity()is zero and therefore thisItemStackLikeis empty.default intGets the maximum quantity per stack.intquantity()Gets the quantity of items in this stack.type()Gets theItemTypeof thisItemStackLike.Methods inherited from interface net.kyori.adventure.text.ComponentLike
asComponentMethods inherited from interface org.spongepowered.api.data.persistence.DataSerializable
contentVersion, toContainerMethods inherited from interface net.kyori.adventure.text.event.HoverEventSource
asHoverEvent, asHoverEventMethods inherited from interface org.spongepowered.api.data.SerializableDataHolder
validateRawData
-
Method Details
-
type
ItemType type()Gets theItemTypeof 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 thisItemStackLikeis 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 allAttributeModifiers on thisItemStackLike.- Parameters:
attributeType- TheAttributeTypeof the modifier.equipmentType- TheEquipmentTypethis modifier is applied. to.- Returns:
- A collection of
AttributeModifiers.
-
attributeModifiers
default Collection<AttributeModifier> attributeModifiers(AttributeType attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType) Gets allAttributeModifiers on thisItemStackLike.- Parameters:
attributeType- TheAttributeTypeof the modifier.equipmentType- TheEquipmentTypethis modifier is applied. to.- Returns:
- A collection of
AttributeModifiers.
-
attributeModifiers
default Collection<AttributeModifier> attributeModifiers(Supplier<? extends AttributeType> attributeType, EquipmentType equipmentType) Gets allAttributeModifiers on thisItemStackLike.- Parameters:
attributeType- TheAttributeTypeof the modifier.equipmentType- TheEquipmentTypethis modifier is applied. to.- Returns:
- A collection of
AttributeModifiers.
-
attributeModifiers
Collection<AttributeModifier> attributeModifiers(AttributeType attributeType, EquipmentType equipmentType) Gets allAttributeModifiers on thisItemStackLike.- Parameters:
attributeType- TheAttributeTypeof the modifier.equipmentType- TheEquipmentTypethis modifier is applied. to.- Returns:
- A collection of
AttributeModifiers.
-
asMutable
ItemStack asMutable()Retrieves a mutable form of thisItemStackLike. If this ItemStackLike is already mutable, this would simply return itself. In other cases, a newItemStackis 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 newItemStackis 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 newItemStackSnapshotis created with all knownValues existing on thisItemStackLikeadded as copies to theItemStackSnapshot.- Returns:
- An ItemStackSnapshot
-
copy
ItemStackLike copy()Description copied from interface:CopyableDataHolderCreates a clone copy of thisCopyableDataHolderas a newCopyableDataHoldersuch that all theValues 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:
copyin interfaceCopyableDataHolder- Specified by:
copyin interfaceSerializableDataHolder- Returns:
- The new copy
-