Skip to main content

ItemStackTemplate

Struct ItemStackTemplate 

Source
pub struct ItemStackTemplate {
    item: ItemRef,
    count: i32,
    components: DataComponentPatch,
    components_hash: Option<i32>,
}
Expand description

A persistable, non-empty item identity, count, and component patch.

Fields§

§item: ItemRef§count: i32§components: DataComponentPatch§components_hash: Option<i32>

Implementations§

Source§

impl ItemStackTemplate

Source

pub const MIN_COUNT: i32 = 1

Source

pub const MAX_COUNT: i32 = 99

Source

pub fn new(item: ItemRef) -> Self

Creates the common count-one template with no component changes.

Source

pub fn with_count(item: ItemRef, count: i32) -> Self

Creates a template with a validated persistent count and no component changes.

Source

pub fn try_with_count_and_patch( item: ItemRef, count: i32, components: DataComponentPatch, ) -> Result<Self>

Creates a template after validating its complete persistent codec shape.

Source

pub(crate) fn from_extracted( item: ItemRef, count: i32, components: DataComponentPatch, components_hash: i32, ) -> Self

Constructs a template from build-time validated Vanilla extractor data.

This avoids persistent codec validation during registry bootstrap because registry-aware component codecs cannot consult REGISTRY until it has been completely built and published.

Source

pub fn from_stack(stack: &ItemStack) -> Result<Self>

Copies a non-empty stack into its immutable template representation.

Source

pub(crate) fn validate_persistent_encoding(&self) -> Result<()>

Source

pub const fn item(&self) -> ItemRef

Source

pub const fn count(&self) -> i32

Source

pub const fn components(&self) -> &DataComponentPatch

Source

pub fn create(&self) -> ItemStack

Source

pub fn apply( &self, count: i32, additional_components: &DataComponentPatch, ) -> ItemStack

Creates this template over an existing component patch, matching Vanilla’s ItemStackTemplate.apply precedence rules.

Source

pub fn to_hover_event(&self) -> Result<HoverEvent>

Creates the Vanilla hover event for this item template.

Source

pub(crate) fn to_nbt_tag_ref(&self) -> NbtTag

Source

pub(crate) fn from_nbt_identifier(value: &str) -> Option<Self>

Source

pub(crate) fn from_nbt_compound(compound: NbtCompound<'_, '_>) -> Option<Self>

Source

fn from_stream( item: ItemRef, count: i32, components: DataComponentPatch, ) -> Result<Self>

Source

pub fn get_effective_value_raw( &self, key: &Identifier, ) -> Option<&ComponentData>

Gets the effective raw component value from the patch or item prototype.

Source

pub fn get<T: Component + DowncastType>( &self, component: DataComponentType<T>, ) -> Option<&T>

Gets an effective typed component value from the patch or item prototype.

Source

pub(crate) fn max_stack_size(&self) -> i32

Trait Implementations§

Source§

impl Clone for ItemStackTemplate

Source§

fn clone(&self) -> ItemStackTemplate

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 ItemStackTemplate

Source§

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

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

impl FromNbtTag for ItemStackTemplate

Source§

fn from_nbt_tag(tag: NbtTag<'_, '_>) -> Option<Self>

§

fn from_optional_nbt_tag( tag: Option<NbtTag<'_, '_>>, ) -> Result<Option<Self>, DeserializeError>

Source§

impl HashComponent for ItemStackTemplate

Source§

fn hash_component(&self, hasher: &mut ComponentHasher)

Hashes this value into the given hasher.
Source§

fn compute_hash(&self) -> i32

Computes the hash of this value.
Source§

impl PartialEq for ItemStackTemplate

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl ReadFrom for ItemStackTemplate

Source§

fn read(data: &mut Cursor<&[u8]>) -> Result<Self>

Reads data from a cursor.
Source§

impl StructuralPartialEq for ItemStackTemplate

Source§

impl ToNbtTag for ItemStackTemplate

Source§

fn to_nbt_tag(self) -> NbtTag

§

fn to_optional_nbt_tag(self) -> Option<NbtTag>

Source§

impl WriteTo for ItemStackTemplate

Source§

fn write(&self, writer: &mut impl Write) -> Result<()>

Writes data to a writer.

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoShared for T

Source§

fn into_shared(self) -> Arc<Mutex<RawMutex, Self>>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more