pub struct Stack { /* private fields */ }Expand description
A non-empty item stack as the client holds it.
count is a Java int in vanilla (sent as a byte before 26.1). 1.8 keeps stacks with a
count of zero or less as real stacks (they render as a red “0”); later versions treat them as
empty, so their Inventory never stores one.
The fields are private so the representation can change without breaking users: read them
with Stack::id, Stack::count, Stack::damage, Stack::data, build stacks with
Stack::new and the with_* methods.
Implementations§
Source§impl Stack
impl Stack
Sourcepub fn item_name(&self, v: Version) -> Option<&'static str>
pub fn item_name(&self, v: Version) -> Option<&'static str>
Item registry name without minecraft: (None when the id is unknown to the version).
Sourcepub fn max_stack_size(&self, v: Version) -> i32
pub fn max_stack_size(&self, v: Version) -> i32
Largest stack of this item (ItemStack.getMaxStackSize; 26.1 reads the component).
Sourcepub fn max_damage(&self, v: Version) -> Option<i32>
pub fn max_damage(&self, v: Version) -> Option<i32>
Durability (None for items without one).
Sourcepub fn is_damageable(&self, v: Version) -> bool
pub fn is_damageable(&self, v: Version) -> bool
Whether the stack loses durability (isDamageable: it has durability and is not
unbreakable).
Sourcepub fn damage_value(&self, v: Version) -> i32
pub fn damage_value(&self, v: Version) -> i32
Damage taken (0 when not damageable; 1.8 / 1.12 items with variants use the damage field as the variant, not as damage).
Sourcepub fn unbreakable(&self, v: Version) -> bool
pub fn unbreakable(&self, v: Version) -> bool
Unbreakable (1.8 – 1.16.5 tag, 26.1 component, including the item default).
Sourcepub fn custom_name(&self, v: Version) -> Option<ItemText>
pub fn custom_name(&self, v: Version) -> Option<ItemText>
The custom name (anvil / plugin name), if any.
Sourcepub fn enchantments(&self, v: Version) -> Vec<Enchantment>
pub fn enchantments(&self, v: Version) -> Vec<Enchantment>
The enchantments (empty when none).
Sourcepub fn stored_enchantments(&self, v: Version) -> Vec<Enchantment>
pub fn stored_enchantments(&self, v: Version) -> Vec<Enchantment>
The stored enchantments of an enchanted book (empty when none).
Source§impl Stack
impl Stack
Sourcepub fn id(&self) -> i32
pub fn id(&self) -> i32
Numeric item id (1.8 / 1.12: legacy id; 1.16.5 / 26.1: item registry id).
Sourcepub fn damage(&self) -> i16
pub fn damage(&self) -> i16
1.8 / 1.12 damage / metadata. Always 0 on 1.16.5 (the Damage NBT tag) and 26.1 (the
damage component); see Stack::damage_value.
Sourcepub fn with_damage(self, damage: i16) -> Stack
pub fn with_damage(self, damage: i16) -> Stack
This stack with another damage / metadata value.
Sourcepub fn new(id: i32, count: i32, damage: i16) -> Stack
pub fn new(id: i32, count: i32, damage: i16) -> Stack
A stack without NBT or component changes.
Sourcepub fn components(&self) -> Option<&ComponentPatch>
pub fn components(&self) -> Option<&ComponentPatch>
The 26.1 component patch, if the stack changes any component.
Sourcepub fn with_count(&self, count: i32) -> Stack
pub fn with_count(&self, count: i32) -> Stack
The same item (id, damage, NBT) with another count.
Sourcepub fn from_legacy(s: ItemStack) -> Stack
pub fn from_legacy(s: ItemStack) -> Stack
Converts a 1.8 wire stack.
Sourcepub fn from_modern(s: ItemStack) -> Stack
pub fn from_modern(s: ItemStack) -> Stack
Converts a 1.16.5 wire stack.
Sourcepub fn from_v775(s: ItemStack) -> Stack
pub fn from_v775(s: ItemStack) -> Stack
Converts a 26.1 wire stack (an empty patch becomes ItemData::None).
Sourcepub fn to_legacy(&self) -> ItemStack
pub fn to_legacy(&self) -> ItemStack
The 1.8 wire form (count truncated to a byte like Java’s writeByte).
Sourcepub fn same_item(&self, other: &Stack) -> bool
pub fn same_item(&self, other: &Stack) -> bool
Same item, damage and data (vanilla’s item + damage check and its NBT check; 26.1
isSameItemSameComponents); counts are not compared.
Sourcepub fn data_eq(&self, other: &Stack) -> bool
pub fn data_eq(&self, other: &Stack) -> bool
Vanilla’s data comparison: NBT both absent, or both present and equal as trees; 26.1 component patches equal as maps.
Sourcepub fn nbt_eq(&self, other: &Stack) -> bool
pub fn nbt_eq(&self, other: &Stack) -> bool
Same as Stack::data_eq (kept from 0.3, where item data was always NBT).
Sourcepub fn equals_exact(&self, other: &Stack) -> bool
pub fn equals_exact(&self, other: &Stack) -> bool
Exact equality as the server checks the clicked item (count, id, damage, NBT).