steel_core/behavior/items/
egg.rs1use std::sync::Arc;
8
9use steel_macros::item_behavior;
10use steel_protocol::packets::game::SoundSource;
11use steel_registry::{sound_events, vanilla_entities};
12
13use super::throw_projectile::{ThrowParams, throw_item_projectile};
14use crate::behavior::context::{InteractionResult, UseItemContext};
15use crate::behavior::item::ItemBehavior;
16use crate::entity::entities::ThrownEggEntity;
17use crate::entity::next_entity_id;
18
19const THROW: ThrowParams = ThrowParams {
21 sound: &sound_events::ENTITY_EGG_THROW,
22 sound_source: SoundSource::Players,
23 sound_volume: 0.5,
24 y_offset: 0.0,
25 power: 1.5,
26 uncertainty: 1.0,
27};
28
29#[item_behavior(class = "EggItem")]
31pub struct EggItem;
32
33impl ItemBehavior for EggItem {
34 fn use_item(&self, context: &mut UseItemContext) -> InteractionResult {
35 let world = context.world;
36 throw_item_projectile(context, &THROW, |spawn_pos| {
37 ThrownEggEntity::new(
38 &vanilla_entities::EGG,
39 next_entity_id(),
40 spawn_pos,
41 Arc::downgrade(world),
42 )
43 });
44 InteractionResult::Success
45 }
46}