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
impl ItemResource
pub fn of(stack: &ItemStack) -> ItemResource
pub fn of(stack: &ItemStack) -> ItemResource
What stack is, whatever its count.
pub fn as_stack(&self) -> &ItemStack
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>
pub fn to_stack(&self, count: u32) -> Option<ItemStack>
count of it as a stack, or none for an empty result.
pub fn component(&self, id: &ComponentId) -> Option<Tag>
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>
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
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
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
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
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
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>
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>
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>
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>
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>
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>
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>>
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>
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
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>
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>
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
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
impl Clone for ItemResource
§fn clone(&self) -> ItemResource
fn clone(&self) -> ItemResource
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more