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§
Sourcefn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Returns the Rust type name of the concrete behavior implementation.
Sourcefn get_name<'a>(&self, stack: &'a ItemStack) -> Cow<'a, TextComponent>
fn get_name<'a>(&self, stack: &'a ItemStack) -> Cow<'a, TextComponent>
Returns vanilla Item.getName(stack).
Sourcefn use_on(&self, _context: &mut UseOnContext<'_>) -> InteractionResult
fn use_on(&self, _context: &mut UseOnContext<'_>) -> InteractionResult
Called when this item is used on a block.
Sourcefn use_item(&self, context: &mut UseItemContext<'_>) -> InteractionResult
fn use_item(&self, context: &mut UseItemContext<'_>) -> InteractionResult
Called when this item is used (e.g. right click in air).
Sourcefn interact_living_entity(
&self,
_stack: &mut ItemStack,
_player: &Player,
_target: &dyn LivingEntity,
_hand: InteractionHand,
) -> InteractionResult
fn interact_living_entity( &self, _stack: &mut ItemStack, _player: &Player, _target: &dyn LivingEntity, _hand: InteractionHand, ) -> InteractionResult
Called by vanilla ItemStack.interactLivingEntity.
Sourcefn get_item_damage_source(
&self,
_attacker: &dyn LivingEntity,
) -> Option<DamageSource>
fn get_item_damage_source( &self, _attacker: &dyn LivingEntity, ) -> Option<DamageSource>
Returns vanilla Item.getItemDamageSource.
Sourcefn get_attack_damage_bonus(
&self,
_attacker: &dyn LivingEntity,
_victim: &dyn Entity,
_base_damage: f32,
_damage_source: &DamageSource,
) -> f32
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.
Sourcefn hurt_enemy(
&self,
_stack: &mut ItemStack,
_target: &dyn LivingEntity,
_attacker: &dyn LivingEntity,
)
fn hurt_enemy( &self, _stack: &mut ItemStack, _target: &dyn LivingEntity, _attacker: &dyn LivingEntity, )
Called by vanilla Item.hurtEnemy.
Sourcefn post_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, )
Called by vanilla Item.postHurtEnemy.
Sourcefn item_damage_per_attack(&self, stack: &ItemStack) -> Option<i32>
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".