steel_core/behavior/items/
solid_bucket_item.rs1use steel_macros::item_behavior;
4use steel_registry::{
5 blocks::BlockRef, item_stack::ItemStack, sound_event::SoundEventRef, vanilla_items,
6};
7
8use crate::behavior::items::BlockItem;
9use crate::behavior::{InteractionResult, ItemBehavior, UseOnContext};
10
11#[item_behavior]
13pub struct SolidBucketItem {
14 #[json_arg(vanilla_blocks, json = "block")]
15 _block: BlockRef,
16 #[json_arg(sound_events, json = "place_sound")]
17 place_sound: SoundEventRef,
18 base: BlockItem,
19}
20
21impl SolidBucketItem {
22 #[must_use]
24 pub const fn new(block: BlockRef, place_sound: SoundEventRef) -> Self {
25 Self {
26 _block: block,
27 place_sound,
28 base: BlockItem::new(block),
29 }
30 }
31}
32
33impl ItemBehavior for SolidBucketItem {
34 fn use_on(&self, context: &mut UseOnContext) -> InteractionResult {
35 let result = self.base.place_with_sound_and_block(
36 context.build_place_context(),
37 BlockItem::place_block,
38 self.place_sound,
39 );
40
41 if matches!(result, InteractionResult::Success) && !context.player.has_infinite_materials()
42 {
43 context
44 .inv
45 .with_item(|item| *item = ItemStack::new(&vanilla_items::BUCKET));
46 }
47
48 result
49 }
50}