Interface ItemStack
-
- All Superinterfaces:
ComponentLike
,CopyableDataHolder
,DataHolder
,DataHolder.Mutable
,DataSerializable
,HoverEventSource<HoverEvent.ShowItem>
,SerializableDataHolder
,SerializableDataHolder.Mutable
,ValueContainer
public interface ItemStack extends SerializableDataHolder.Mutable, ComponentLike, HoverEventSource<HoverEvent.ShowItem>
Represents a stack of a specificItemType
. Supports serialization and can be compared using the comparators listed inItemStackComparators
.ItemStack
s have a variety of properties and data. It is advised to useValueContainer.get(Key)
in order to retrieve information regarding this item stack.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ItemStack.Builder
static interface
ItemStack.Factory
-
Nested classes/interfaces inherited from interface org.spongepowered.api.data.DataHolder
DataHolder.Immutable<I extends DataHolder.Immutable<I>>, DataHolder.Mutable
-
Nested classes/interfaces inherited from interface org.spongepowered.api.data.SerializableDataHolder
SerializableDataHolder.Immutable<I extends SerializableDataHolder.Immutable<I>>, SerializableDataHolder.Mutable
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
addAttributeModifier(java.util.function.Supplier<? extends AttributeType> attributeType, AttributeModifier modifier, EquipmentType equipmentType)
Adds anAttributeModifier
to this item stack.default void
addAttributeModifier(java.util.function.Supplier<? extends AttributeType> attributeType, AttributeModifier modifier, DefaultedRegistryReference<? extends EquipmentType> equipmentType)
Adds anAttributeModifier
to this item stack.void
addAttributeModifier(AttributeType attributeType, AttributeModifier modifier, EquipmentType equipmentType)
Adds anAttributeModifier
to this item stack.default void
addAttributeModifier(AttributeType attributeType, AttributeModifier modifier, DefaultedRegistryReference<? extends EquipmentType> equipmentType)
Adds anAttributeModifier
to this item stack.default java.util.Collection<AttributeModifier>
attributeModifiers(java.util.function.Supplier<? extends AttributeType> attributeType, EquipmentType equipmentType)
Gets allAttributeModifier
s on this item stack.default java.util.Collection<AttributeModifier>
attributeModifiers(java.util.function.Supplier<? extends AttributeType> attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType)
Gets allAttributeModifier
s on this item stack.java.util.Collection<AttributeModifier>
attributeModifiers(AttributeType attributeType, EquipmentType equipmentType)
Gets allAttributeModifier
s on this item stack.default java.util.Collection<AttributeModifier>
attributeModifiers(AttributeType attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType)
Gets allAttributeModifier
s on this item stack.static ItemStack.Builder
builder()
Creates a newItemStack.Builder
to build anItemStack
.ItemStack
copy()
Creates a clone copy of thisCopyableDataHolder
as a newCopyableDataHolder
such that all theValue
s are safely duplicated to the new instance.ItemStackSnapshot
createSnapshot()
Gets theItemStackSnapshot
of thisItemStack
.static ItemStack
empty()
Returns an emptyItemStack
.boolean
equalTo(ItemStack that)
boolean
isEmpty()
Returns true ifquantity()
is zero and therefore this ItemStack is empty.int
maxStackQuantity()
Gets the maximum quantity per stack.static ItemStack
of(java.util.function.Supplier<? extends ItemType> itemType)
static ItemStack
of(java.util.function.Supplier<? extends ItemType> itemType, int quantity)
static ItemStack
of(ItemType itemType)
static ItemStack
of(ItemType itemType, int quantity)
int
quantity()
Gets the quantity of items in this stack.void
setQuantity(int quantity)
Sets the quantity in this stack.ItemType
type()
-
Methods inherited from interface net.kyori.adventure.text.ComponentLike
asComponent
-
Methods inherited from interface org.spongepowered.api.data.DataHolder.Mutable
copyFrom, copyFrom, offer, offer, offer, offer, offerAll, offerAll, offerAll, offerAll, offerAll, offerAll, offerSingle, offerSingle, offerSingle, offerSingle, remove, remove, remove, removeAll, removeAll, removeAll, removeAll, removeAll, removeAll, removeKey, removeKey, removeSingle, removeSingle, transform, transform, tryOffer, tryOffer, tryOffer, undo
-
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
-
Methods inherited from interface org.spongepowered.api.data.SerializableDataHolder.Mutable
setRawData
-
-
-
-
Method Detail
-
builder
static ItemStack.Builder builder()
Creates a newItemStack.Builder
to build anItemStack
.- Returns:
- The new builder
-
of
static ItemStack of(java.util.function.Supplier<? extends ItemType> itemType, int quantity)
- Parameters:
itemType
- The item typequantity
- The quantity- Returns:
- The new item stack
-
of
static ItemStack of(ItemType itemType, int quantity)
- Parameters:
itemType
- The item typequantity
- The quantity- Returns:
- The new item stack
-
of
static ItemStack of(java.util.function.Supplier<? extends ItemType> itemType)
- Parameters:
itemType
- The item type- Returns:
- The new item stack
-
of
static ItemStack of(ItemType itemType)
- Parameters:
itemType
- The item type- Returns:
- The new item stack
-
type
ItemType type()
- 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
-
setQuantity
void setQuantity(int quantity) throws java.lang.IllegalArgumentException
Sets the quantity in this stack.- Parameters:
quantity
- Quantity- Throws:
java.lang.IllegalArgumentException
- If quantity set exceeds themaxStackQuantity()
-
maxStackQuantity
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
-
createSnapshot
ItemStackSnapshot createSnapshot()
Gets theItemStackSnapshot
of thisItemStack
. All knownValue
s existing on thisItemStack
are added as copies to theItemStackSnapshot
.- Returns:
- The newly created item stack snapshot
-
equalTo
boolean equalTo(ItemStack that)
Returns true if the specifiedItemStack
has the same stack size,ItemType
, and data. Note that this method is not an overrider ofObject.equals(Object)
in order to maintain compatibility with the base game. Therefore, ItemStacks may not behave as expected when using them in equality based constructs such asMap
s orSet
s.- Parameters:
that
- ItemStack to compare- Returns:
- True if this equals the ItemStack
-
isEmpty
boolean isEmpty()
Returns true ifquantity()
is zero and therefore this ItemStack is empty.In Vanilla empty ItemStacks are not rendered by the client.
- Returns:
- True if this ItemStack is empty
-
attributeModifiers
default java.util.Collection<AttributeModifier> attributeModifiers(java.util.function.Supplier<? extends AttributeType> attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType)
Gets allAttributeModifier
s on this item stack.- Parameters:
attributeType
- TheAttributeType
of the modifier.equipmentType
- TheEquipmentType
this modifier is applied to.- Returns:
- A collection of
AttributeModifier
s.
-
attributeModifiers
default java.util.Collection<AttributeModifier> attributeModifiers(AttributeType attributeType, DefaultedRegistryReference<? extends EquipmentType> equipmentType)
Gets allAttributeModifier
s on this item stack.- Parameters:
attributeType
- TheAttributeType
of the modifier.equipmentType
- TheEquipmentType
this modifier is applied to.- Returns:
- A collection of
AttributeModifier
s.
-
attributeModifiers
default java.util.Collection<AttributeModifier> attributeModifiers(java.util.function.Supplier<? extends AttributeType> attributeType, EquipmentType equipmentType)
Gets allAttributeModifier
s on this item stack.- Parameters:
attributeType
- TheAttributeType
of the modifier.equipmentType
- TheEquipmentType
this modifier is applied to.- Returns:
- A collection of
AttributeModifier
s.
-
attributeModifiers
java.util.Collection<AttributeModifier> attributeModifiers(AttributeType attributeType, EquipmentType equipmentType)
Gets allAttributeModifier
s on this item stack.- Parameters:
attributeType
- TheAttributeType
of the modifier.equipmentType
- TheEquipmentType
this modifier is applied to.- Returns:
- A collection of
AttributeModifier
s.
-
addAttributeModifier
default void addAttributeModifier(java.util.function.Supplier<? extends AttributeType> attributeType, AttributeModifier modifier, EquipmentType equipmentType)
Adds anAttributeModifier
to this item stack.- Parameters:
attributeType
- The attribute type.modifier
- The attribute modifier.equipmentType
- The equipment type this modifier will apply under.
-
addAttributeModifier
default void addAttributeModifier(AttributeType attributeType, AttributeModifier modifier, DefaultedRegistryReference<? extends EquipmentType> equipmentType)
Adds anAttributeModifier
to this item stack.- Parameters:
attributeType
- The attribute type.modifier
- The attribute modifier.equipmentType
- The equipment type this modifier will apply under.
-
addAttributeModifier
default void addAttributeModifier(java.util.function.Supplier<? extends AttributeType> attributeType, AttributeModifier modifier, DefaultedRegistryReference<? extends EquipmentType> equipmentType)
Adds anAttributeModifier
to this item stack.- Parameters:
attributeType
- The attribute type.modifier
- The attribute modifier.equipmentType
- The equipment type this modifier will apply under.
-
addAttributeModifier
void addAttributeModifier(AttributeType attributeType, AttributeModifier modifier, EquipmentType equipmentType)
Adds anAttributeModifier
to this item stack.- Parameters:
attributeType
- The attribute type.modifier
- The attribute modifier.equipmentType
- The equipment type this modifier will apply under.
-
copy
ItemStack 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
- Specified by:
copy
in interfaceSerializableDataHolder.Mutable
- Returns:
- The new copy
-
-