Skip to main content

ItemBehavior

Trait ItemBehavior 

Source
pub trait ItemBehavior: Send + Sync {
    // Provided methods
    fn type_name(&self) -> &'static str { ... }
    fn get_name<'a>(&self, stack: &'a ItemStack) -> Cow<'a, TextComponent> { ... }
    fn use_on(&self, _context: &mut UseOnContext<'_>) -> InteractionResult { ... }
    fn use_item(&self, context: &mut UseItemContext<'_>) -> InteractionResult { ... }
    fn interact_living_entity(
        &self,
        _stack: &mut ItemStack,
        _player: &Player,
        _target: &dyn LivingEntity,
        _hand: InteractionHand,
    ) -> InteractionResult { ... }
    fn get_item_damage_source(
        &self,
        _attacker: &dyn LivingEntity,
    ) -> Option<DamageSource> { ... }
    fn get_attack_damage_bonus(
        &self,
        _attacker: &dyn LivingEntity,
        _victim: &dyn Entity,
        _base_damage: f32,
        _damage_source: &DamageSource,
    ) -> f32 { ... }
    fn hurt_enemy(
        &self,
        _stack: &mut ItemStack,
        _target: &dyn LivingEntity,
        _attacker: &dyn LivingEntity,
    ) { ... }
    fn post_hurt_enemy(
        &self,
        _stack: &mut ItemStack,
        _target: &dyn LivingEntity,
        _attacker: &dyn LivingEntity,
    ) { ... }
    fn item_damage_per_attack(&self, stack: &ItemStack) -> Option<i32> { ... }
}
Expand description

Trait defining the behavior of an item.

This trait handles dynamic/functional aspects of items:

  • Use on blocks (placing, interacting)
  • Use in air
  • etc.

Provided Methods§

Source

fn type_name(&self) -> &'static str

Returns the Rust type name of the concrete behavior implementation.

Source

fn get_name<'a>(&self, stack: &'a ItemStack) -> Cow<'a, TextComponent>

Returns vanilla Item.getName(stack).

Source

fn use_on(&self, _context: &mut UseOnContext<'_>) -> InteractionResult

Called when this item is used on a block.

Source

fn use_item(&self, context: &mut UseItemContext<'_>) -> InteractionResult

Called when this item is used (e.g. right click in air).

Source

fn interact_living_entity( &self, _stack: &mut ItemStack, _player: &Player, _target: &dyn LivingEntity, _hand: InteractionHand, ) -> InteractionResult

Called by vanilla ItemStack.interactLivingEntity.

Source

fn get_item_damage_source( &self, _attacker: &dyn LivingEntity, ) -> Option<DamageSource>

Returns vanilla Item.getItemDamageSource.

Source

fn get_attack_damage_bonus( &self, _attacker: &dyn LivingEntity, _victim: &dyn Entity, _base_damage: f32, _damage_source: &DamageSource, ) -> f32

Returns item-specific attack damage added by Item.getAttackDamageBonus.

Source

fn hurt_enemy( &self, _stack: &mut ItemStack, _target: &dyn LivingEntity, _attacker: &dyn LivingEntity, )

Called by vanilla Item.hurtEnemy.

Source

fn post_hurt_enemy( &self, _stack: &mut ItemStack, _target: &dyn LivingEntity, _attacker: &dyn LivingEntity, )

Called by vanilla Item.postHurtEnemy.

Source

fn item_damage_per_attack(&self, stack: &ItemStack) -> Option<i32>

Returns how much durability this weapon consumes after a successful entity hit.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§