steel_core/behavior/items/
ink_sac.rs1use steel_macros::item_behavior;
4use steel_protocol::packets::game::SoundSource;
5use steel_registry::item_stack::ItemStack;
6use steel_registry::sound_events::{ITEM_GLOW_INK_SAC_USE, ITEM_INK_SAC_USE};
7use steel_utils::types::SignTextSlot;
8
9use crate::behavior::{ItemBehavior, SignApplicator};
10use crate::block_entity::{BlockEntity, entities::SignBlockEntity};
11use crate::player::Player;
12use crate::world::World;
13
14fn apply_glow(world: &World, sign: &SignBlockEntity, slot: SignTextSlot, glowing: bool) -> bool {
15 if !sign.set_glowing(slot, glowing) {
16 return false;
17 }
18
19 let sound = if glowing {
20 &ITEM_GLOW_INK_SAC_USE
21 } else {
22 &ITEM_INK_SAC_USE
23 };
24 world.play_sound(
25 sound,
26 SoundSource::Blocks,
27 sign.get_block_pos(),
28 1.0,
29 1.0,
30 None,
31 );
32 true
33}
34
35#[item_behavior]
37pub struct InkSacItem;
38
39impl ItemBehavior for InkSacItem {
40 fn as_sign_applicator(&self) -> Option<&dyn SignApplicator> {
41 Some(self)
42 }
43}
44
45impl SignApplicator for InkSacItem {
46 fn try_apply_to_sign(
47 &self,
48 world: &World,
49 sign: &SignBlockEntity,
50 slot: SignTextSlot,
51 _item: &ItemStack,
52 _player: &Player,
53 ) -> bool {
54 apply_glow(world, sign, slot, false)
55 }
56}
57
58#[item_behavior]
60pub struct GlowInkSacItem;
61
62impl ItemBehavior for GlowInkSacItem {
63 fn as_sign_applicator(&self) -> Option<&dyn SignApplicator> {
64 Some(self)
65 }
66}
67
68impl SignApplicator for GlowInkSacItem {
69 fn try_apply_to_sign(
70 &self,
71 world: &World,
72 sign: &SignBlockEntity,
73 slot: SignTextSlot,
74 _item: &ItemStack,
75 _player: &Player,
76 ) -> bool {
77 apply_glow(world, sign, slot, true)
78 }
79}