Skip to main content

ItemResource

Struct ItemResource 

pub struct ItemResource(/* private fields */);
Expand description

An item and its components, without a count, as NeoForge’s ItemResource: what a slot holds. An empty slot holds none.

Implementations§

§

impl ItemResource

pub fn of(stack: &ItemStack) -> ItemResource

What stack is, whatever its count.

pub fn item(&self) -> ItemKey

The item’s process-local identity.

pub fn as_stack(&self) -> &ItemStack

Borrow the resource’s single-item stack without cloning its component patch.

pub fn to_stack(&self, count: u32) -> Option<ItemStack>

count of it as a stack, or none for an empty result.

pub fn matches(&self, stack: &ItemStack) -> bool

Whether stack is this item with these components.

pub fn component(&self, id: &ComponentId) -> Option<Tag>

This item’s own value of component id in its patch, as saved (minecraft:damage on a worn sword); none where it keeps the item’s default or has the component removed.

pub fn value(&self, host: &dyn Host, id: &ComponentId) -> Option<Tag>

This item’s value of component id (ItemResource.get): its own, else the item’s default (host.item_default_component), none where it has the component removed or the item hasn’t one.

pub fn damageable(&self, host: &dyn Host) -> bool

ItemStack.isDamageableItem: maximum damage and damage components are present, and the unbreakable component is absent, after this stack’s patch.

pub fn foil(&self, host: &dyn Host) -> bool

ItemStack.hasFoil: the effective glint override wins, otherwise a item-specific foil applies (lodestone compass or nonempty enchantments).

pub fn rarity(&self, host: &dyn Host) -> ItemRarity

ItemStack.getRarity: the effective rarity, upgraded for a nonempty enchantments component; removing rarity restores common before the upgrade.

pub fn enchantable(&self, host: &dyn Host) -> bool

ItemStack.isEnchantable: the effective enchantable component is present and the enchantments component is present but empty.

pub fn repairable(&self, host: &dyn Host, material: &ItemResource) -> bool

ItemStack.isValidRepairItem: whether material belongs to the effective repairable component’s item holder set. The comparison is by item identity/tag, not its count, damage or components.

pub fn use_duration(&self, host: &dyn Host) -> Option<i32>

Item.getUseDuration and its item overrides, in ticks, including the same use-duration Part as gameplay. Uses the host’s current acting-player context for Parts; vanilla’s current implementations need no player argument. None for an unknown item or a host without the engine backend.

pub fn bar(&self, host: &dyn Host) -> Option<ItemBar>

ItemStack.isBarVisible, getBarWidth and getBarColor: the visible vanilla durability or bundle bar, after effective components. None when no bar is visible. Client drawing hooks can later replace this bar.

pub fn entity_attack_range( &self, host: &dyn Host, attacker: LivingRef, ) -> Option<ItemAttackRange>

AttackRange.defaultFor or this stack’s effective attack-range component for attacker. Returns None for an unavailable actor or item. Does not equip this stack.

pub fn damage_source( &self, host: &dyn Host, attacker: LivingRef, ) -> Option<ItemDamageSource>

ItemStack.getDamageSource: component override, item-specific source (mace smash), then the attacker’s ordinary melee source. None for an unavailable actor or damage type.

pub fn can_be_hurt_by( &self, host: &dyn Host, source: &ItemDamageSource, ) -> Option<bool>

ItemStack.canBeHurtBy: whether this item itself can be hurt by source, after effective damage-resistant components. This is not wearer protection. None for an unknown item or damage type.

pub fn attack_damage_bonus( &self, host: &dyn Host, attacker: LivingRef, target: EntityRef, base_damage: f32, ) -> Option<f32>

Preview the stack’s attack bonus against target, including enchantments and mace fall damage. Returns the additional damage above base_damage. Uses a cloned RNG snapshot: a read never consumes world RNG. This is a preview under the current state; a later attack may roll differently. The queried stack is never equipped. None for unavailable handles or actors and targets outside the host’s active level.

pub fn tooltip( &self, host: &dyn ClientHost, advanced: bool, creative: bool, ) -> Option<Vec<TooltipElement>>

Standard tooltip text, with explicit advanced and creative flags and the client’s current viewer context. Uses the same line builder as inventory tooltips and skips mod callbacks, so a tooltip hook can safely request another item’s base lines. Returns None without a client backend, or when the item cannot be resolved.

pub fn enchant_randomly( &self, host: &mut dyn ServerHost, level: LevelRef, power: i32, pool: &Identifier, ) -> Result<Option<ItemResource>, StackWriteError>

Roll compatible enchantments from the named enchantment tag with the active server level’s random source. Returns a detached resource, converting a book to an enchanted book when selected. None means the request was refused or the roll chose nothing. A valid roll consumes random draws even if the caller discards the result. To store the result, use the normal transactional item-place or capability write.

pub fn has_enchantment_effect( &self, host: &dyn Host, effect: EnchantmentEffect, ) -> bool

Whether an enchantment on this item has effect effect (EnchantmentHelper.has), by the enchantments’ definitions, data packs’ included, not their ids.

pub fn equippable_slot(&self, host: &dyn Host) -> Option<String>

The slot this item is equipped to (Equippable.slot): head, chest, legs, feet, body, mainhand, offhand or saddle, by its equippable component after the stack’s own patch; none where it is not equippable. Whether a given entity may wear it is another question, not answered here.

pub fn with_component( &self, host: &dyn Host, id: &ComponentId, value: Tag, ) -> Result<ItemResource, StackError>

This item with component id set to value (ItemResource.with, as vanilla’s PatchedDataComponentMap.set): a removal of it dropped, and the stack’s own value too where value is the item’s default (host.item_default_component), so the stack is the plain item again. A stack changes where it lives by an exchange of one of it for this: place.exchange(host, tx, &changed, 1), which splits it off a bigger stack, in the transaction.

pub fn without_component( &self, host: &dyn Host, id: &ComponentId, ) -> ItemResource

This item without component id (ItemResource.without, as vanilla’s PatchedDataComponentMap.remove): its own value dropped and, where the item has the component by default (host.item_default_component), a removal recorded in its patch ("!minecraft:max_damage": {}), saved and sent as vanilla’s are.

Trait Implementations§

§

impl Clone for ItemResource

§

fn clone(&self) -> ItemResource

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
§

impl Debug for ItemResource

§

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

Formats the value using the given formatter. Read more
§

impl Eq for ItemResource

§

impl PartialEq for ItemResource

§

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

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

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

Inequality operator !=. Read more
§

impl Wire for ItemResource

§

const MIN: usize = crate::ItemStack::MIN

Minimum encoded size, used to reject impossible collection lengths.
§

fn put(&self, out: &mut Writer)

Encodes this value, recording failures on the writer.
§

fn take(input: &mut Reader<'_>) -> Result<ItemResource, WireError>

Decodes one value, leaving any following bytes for the caller.
§

fn put_owned(self, out: &mut Writer)

Consumes owned data when a resource’s ownership must cross the boundary.

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.

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.

§

impl<T> Put for T
where T: Wire,

§

fn put_to(&self, out: &mut Writer)

Writes it.
§

impl<T> Record for T
where T: Wire,

§

fn encode(&self, out: &mut Writer)

Writes the argument into a hook call.
§

fn apply(&mut self, bytes: &[u8]) -> Result<(), WireError>

Applies one complete reply, refusing malformed or trailing bytes atomically.
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.