Skip to main content

Stack

Struct Stack 

Source
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

Source

pub fn item_name(&self, v: Version) -> Option<&'static str>

Item registry name without minecraft: (None when the id is unknown to the version).

Source

pub fn max_stack_size(&self, v: Version) -> i32

Largest stack of this item (ItemStack.getMaxStackSize; 26.1 reads the component).

Source

pub fn max_damage(&self, v: Version) -> Option<i32>

Durability (None for items without one).

Source

pub fn is_damageable(&self, v: Version) -> bool

Whether the stack loses durability (isDamageable: it has durability and is not unbreakable).

Source

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).

Source

pub fn unbreakable(&self, v: Version) -> bool

Unbreakable (1.8 – 1.16.5 tag, 26.1 component, including the item default).

Source

pub fn custom_name(&self, v: Version) -> Option<ItemText>

The custom name (anvil / plugin name), if any.

Source

pub fn lore(&self, v: Version) -> Vec<ItemText>

The lore lines (empty when none).

Source

pub fn enchantments(&self, v: Version) -> Vec<Enchantment>

The enchantments (empty when none).

Source

pub fn stored_enchantments(&self, v: Version) -> Vec<Enchantment>

The stored enchantments of an enchanted book (empty when none).

Source

pub fn potion(&self, v: Version) -> Option<String>

The potion type (minecraft:healing on 1.12 / 1.16.5; healing on 26.1), when the stack names one (1.8 encodes potions in the damage value: None).

Source§

impl Stack

Source

pub fn id(&self) -> i32

Numeric item id (1.8 / 1.12: legacy id; 1.16.5 / 26.1: item registry id).

Source

pub fn count(&self) -> i32

Stack size.

Source

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.

Source

pub fn data(&self) -> &ItemData

NBT or data components exactly as received.

Source

pub fn with_data(self, data: ItemData) -> Stack

This stack with another item data.

Source

pub fn with_damage(self, damage: i16) -> Stack

This stack with another damage / metadata value.

Source

pub fn new(id: i32, count: i32, damage: i16) -> Stack

A stack without NBT or component changes.

Source

pub fn nbt(&self) -> Option<&RawNbt>

The NBT (1.8 – 1.16.5), if any.

Source

pub fn with_nbt(self, nbt: Option<RawNbt>) -> Stack

This stack with its NBT replaced.

Source

pub fn components(&self) -> Option<&ComponentPatch>

The 26.1 component patch, if the stack changes any component.

Source

pub fn with_count(&self, count: i32) -> Stack

The same item (id, damage, NBT) with another count.

Source

pub fn from_legacy(s: ItemStack) -> Stack

Converts a 1.8 wire stack.

Source

pub fn from_modern(s: ItemStack) -> Stack

Converts a 1.16.5 wire stack.

Source

pub fn from_v775(s: ItemStack) -> Stack

Converts a 26.1 wire stack (an empty patch becomes ItemData::None).

Source

pub fn to_v775(&self) -> ItemStack

The 26.1 wire form (any NBT is dropped: 26.1 has none).

Source

pub fn to_legacy(&self) -> ItemStack

The 1.8 wire form (count truncated to a byte like Java’s writeByte).

Source

pub fn to_modern(&self) -> ItemStack

The 1.16.5 wire form.

Source

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.

Source

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.

Source

pub fn nbt_eq(&self, other: &Stack) -> bool

Same as Stack::data_eq (kept from 0.3, where item data was always NBT).

Source

pub fn equals_exact(&self, other: &Stack) -> bool

Exact equality as the server checks the clicked item (count, id, damage, NBT).

Trait Implementations§

Source§

impl Clone for Stack

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Stack

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Stack

Source§

impl Hash for Stack

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Stack

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Stack

Auto Trait Implementations§

§

impl !Freeze for Stack

§

impl Forget for Stack

§

impl Move for Stack

§

impl RefUnwindSafe for Stack

§

impl Send for Stack

§

impl Sync for Stack

§

impl Unpin for Stack

§

impl UnsafeUnpin for Stack

§

impl UnwindSafe for Stack

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.