pub struct Item {
pub key: Identifier,
pub components: DataComponentMap,
pub craft_remainder: Option<Identifier>,
pub id: OnceLock<usize>,
}Expand description
A Minecraft item type.
Fields§
§key: Identifier§components: DataComponentMap§craft_remainder: Option<Identifier>The item key returned when this item is used in crafting (e.g., “bucket” from milk_bucket).
Stored as an Identifier to avoid circular reference issues during initialization.
id: OnceLock<usize>Cached registry ID, set during registration for O(1) lookup on hot paths.
Implementations§
Source§impl Item
impl Item
Sourcepub fn new(
key: Identifier,
item_name: TextComponent,
craft_remainder: Option<Identifier>,
) -> Self
pub fn new( key: Identifier, item_name: TextComponent, craft_remainder: Option<Identifier>, ) -> Self
Creates an item with Vanilla’s mandatory name and default model components.
pub fn from_block(block: BlockRef, item_name: TextComponent) -> Self
pub fn from_block_custom_name( _block: BlockRef, name: &'static str, item_name: TextComponent, ) -> Self
Sourcepub fn builder_set<T: Component + DowncastType>(
self,
component: DataComponentType<T>,
value: Option<T>,
) -> Self
pub fn builder_set<T: Component + DowncastType>( self, component: DataComponentType<T>, value: Option<T>, ) -> Self
Builder method to set a component on this item. Used during static initialization.
Sourcepub fn get_crafting_remainder(&self) -> ItemStack
pub fn get_crafting_remainder(&self) -> ItemStack
Returns the item stack that remains after this item is used in crafting.
For example, milk_bucket returns an empty bucket.
Sourcepub fn has_tag(&'static self, tag: &Identifier) -> bool
pub fn has_tag(&'static self, tag: &Identifier) -> bool
Returns true if this item is tagged with the given tag.
Trait Implementations§
impl Eq for Item
Source§impl RegistryEntry for Item
impl RegistryEntry for Item
Source§impl RegistryHolderSetEntry for Item
impl RegistryHolderSetEntry for Item
Source§const REGISTRY_NAME: &'static str = "item"
const REGISTRY_NAME: &'static str = "item"
Human-readable registry name used in codec errors.
Source§fn holder_set_by_id(id: usize) -> Option<&'static Self>
fn holder_set_by_id(id: usize) -> Option<&'static Self>
Looks up an entry by its protocol registry ID.
Source§fn holder_set_by_key(key: &Identifier) -> Option<&'static Self>
fn holder_set_by_key(key: &Identifier) -> Option<&'static Self>
Looks up an entry by its registry key.
Source§fn holder_set_tag_exists(tag: &Identifier) -> bool
fn holder_set_tag_exists(tag: &Identifier) -> bool
Returns whether the registry contains this tag.
Source§fn holder_set_tag_contains(entry: &'static Self, tag: &Identifier) -> bool
fn holder_set_tag_contains(entry: &'static Self, tag: &Identifier) -> bool
Returns whether an entry belongs to this tag.
Auto Trait Implementations§
impl !Freeze for Item
impl !RefUnwindSafe for Item
impl !UnwindSafe for Item
impl Send for Item
impl Sync for Item
impl Unpin for Item
impl UnsafeUnpin for Item
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreWraps this value in an
Arc<SyncMutex<>>