steel_core/behavior/items/
place_on_water_block_item.rs1use steel_macros::item_behavior;
2use steel_registry::blocks::BlockRef;
3
4use crate::behavior::item_utils::get_player_pov_hit_result;
5use crate::behavior::{BlockItem, InteractionResult, ItemBehavior, UseItemContext, UseOnContext};
6use crate::world::ClipFluid;
7
8#[item_behavior]
10pub struct PlaceOnWaterBlockItem {
11 #[json_arg(vanilla_blocks, json = "block")]
13 pub base: BlockItem,
14}
15
16impl PlaceOnWaterBlockItem {
17 #[must_use]
19 pub const fn new(block: BlockRef) -> Self {
20 Self {
21 base: BlockItem::new(block),
22 }
23 }
24}
25
26impl ItemBehavior for PlaceOnWaterBlockItem {
27 fn use_on(&self, _context: &mut UseOnContext) -> InteractionResult {
28 InteractionResult::Pass
29 }
30 fn use_item(&self, context: &mut UseItemContext) -> InteractionResult {
31 let mut hit_result =
32 get_player_pov_hit_result(context.world, context.player, ClipFluid::SourceOnly);
33 hit_result.block_pos = hit_result.block_pos.above();
34 self.base.use_on(&mut UseOnContext {
35 player: context.player,
36 hand: context.hand,
37 hit_result,
38 world: context.world,
39 inv: context.inv.clone(),
40 })
41 }
42}