steel_core/behavior/items/
spyglass.rs1use std::sync::Arc;
4
5use steel_macros::item_behavior;
6use steel_registry::item_stack::ItemStack;
7use steel_registry::sound_events;
8use steel_registry::stat::vanilla_stat_types;
9
10use crate::behavior::{InteractionResult, ItemBehavior, ItemUseAnimation, UseItemContext};
11use crate::entity::{Entity, LivingEntity};
12use crate::world::World;
13
14const USE_DURATION: i32 = 1200;
15
16#[item_behavior]
18pub struct SpyglassItem;
19
20impl SpyglassItem {
21 fn stop_using(user: &dyn LivingEntity) {
22 user.play_sound(&sound_events::ITEM_SPYGLASS_STOP_USING, 1.0, 1.0);
23 }
24}
25
26impl ItemBehavior for SpyglassItem {
27 fn use_item(&self, context: &mut UseItemContext) -> InteractionResult {
28 context
29 .player
30 .play_sound(&sound_events::ITEM_SPYGLASS_USE, 1.0, 1.0);
31 context.inv.with_item(|item| {
32 context
33 .player
34 .award_stat(&vanilla_stat_types::ITEM_USED, item.item());
35 });
36 context.player.start_using_item(context.hand);
37 InteractionResult::Consume
38 }
39
40 fn get_use_animation(&self, _stack: &ItemStack) -> ItemUseAnimation {
41 ItemUseAnimation::Spyglass
42 }
43
44 fn get_use_duration(&self, _stack: &ItemStack, _user: &dyn LivingEntity) -> i32 {
45 USE_DURATION
46 }
47
48 fn finish_using(
49 &self,
50 stack: &mut ItemStack,
51 _world: &Arc<World>,
52 user: &dyn LivingEntity,
53 ) -> ItemStack {
54 Self::stop_using(user);
55 stack.copy_with_count(stack.count())
56 }
57
58 fn release_using(
59 &self,
60 _stack: &mut ItemStack,
61 _world: &Arc<World>,
62 user: &dyn LivingEntity,
63 _time_left: i32,
64 ) -> bool {
65 Self::stop_using(user);
66 true
67 }
68}