Skip to main content

Stack

Struct Stack 

Source
pub struct Stack {
    pub id: i32,
    pub count: i32,
    pub damage: i16,
    pub nbt: Option<RawNbt>,
}
Expand description

A non-empty item stack as the client holds it.

count is a Java int in vanilla (sent as a byte). 1.8 keeps stacks with a count of zero or less as real stacks (they render as a red “0”); 1.16.5 treats them as empty, so a 1.16.5 Inventory never stores one.

Fields§

§id: i32

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

§count: i32

Stack size.

§damage: i16

1.8 damage / metadata. Always 0 on 1.16.5 (damage lives in the Damage NBT tag).

§nbt: Option<RawNbt>

Item NBT exactly as received, if any.

Implementations§

Source§

impl Stack

Source

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

A stack without NBT.

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 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 NBT (vanilla’s item + damage check and its NBT check); counts are not compared.

Source

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

Vanilla’s tag comparison: both absent, or both present and equal as trees.

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