Skip to main content

Slot

Struct Slot 

Source
pub struct Slot {
    pub item_count: i32,
    pub item_id: Option<i32>,
    pub component_data: Vec<u8>,
}
Expand description

A Minecraft item stack, used in inventories, entity equipment, and trade offers.

The Slot type represents an item stack in the Minecraft protocol. It encodes the item count, item ID, and optional component data. An empty slot has item_count = 0 and no other data. A non-empty slot includes the item ID and an optional list of item components (like damage, enchantments, custom name).

Wire format:

  • VarInt item_count (0 = empty slot, > 0 = slot with item)
  • If item_count > 0:
    • VarInt item_id
    • VarInt num_components_to_add
    • VarInt num_components_to_remove
    • Component data (opaque bytes for now)

Fields§

§item_count: i32

The number of items in this stack. 0 means the slot is empty.

§item_id: Option<i32>

The registry ID of the item, if the slot is not empty.

§component_data: Vec<u8>

Raw component data bytes. Full component parsing is deferred to a future implementation — for now, the components are stored as opaque bytes to allow roundtrip encoding.

Implementations§

Source§

impl Slot

Source

pub fn empty() -> Self

Creates an empty slot (no item).

Source

pub fn new(item_id: i32, count: i32) -> Self

Creates a simple slot with an item ID and count, no components.

Source

pub fn is_empty(&self) -> bool

Returns true if the slot is empty (no item).

Trait Implementations§

Source§

impl Clone for Slot

Source§

fn clone(&self) -> Slot

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Slot

Source§

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

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

impl Decode for Slot

Decodes a Slot from the Minecraft protocol format.

Reads the item count. If zero, returns an empty slot. Otherwise reads the item ID and component counts. Items with zero components decode cleanly, allowing correct Vec<Slot> support. Items with components store the raw component data as opaque bytes until a full component parser is implemented.

Source§

fn decode(buf: &mut &[u8]) -> Result<Self>

Reads a slot from the buffer.

Source§

impl Default for Slot

Source§

fn default() -> Slot

Returns the “default value” for a type. Read more
Source§

impl Encode for Slot

Encodes a Slot in the Minecraft protocol format.

Empty slots encode as a single VarInt(0). Non-empty slots encode the item count, item ID, then component data. If no components are present, explicit zero counts are written (VarInt(0) + VarInt(0)).

Source§

fn encode(&self, buf: &mut Vec<u8>) -> Result<()>

Writes the slot to the buffer.

Source§

impl EncodedSize for Slot

Computes the wire size of a Slot.

Source§

impl PartialEq for Slot

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Slot

Auto Trait Implementations§

§

impl Freeze for Slot

§

impl RefUnwindSafe for Slot

§

impl Send for Slot

§

impl Sync for Slot

§

impl Unpin for Slot

§

impl UnsafeUnpin for Slot

§

impl UnwindSafe for Slot

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.