steel_registry/items/
item.rs1use std::io::{self, Cursor};
7
8use steel_utils::BlockPos;
9use steel_utils::serial::ReadFrom;
10
11use crate::blocks::properties::Direction;
12
13use glam::DVec3;
14
15#[derive(Debug, Clone)]
20pub struct BlockHitResult {
21 pub location: DVec3,
23 pub direction: Direction,
25 pub block_pos: BlockPos,
27 pub miss: bool,
29 pub inside: bool,
31 pub world_border_hit: bool,
33}
34
35impl ReadFrom for BlockHitResult {
36 fn read(data: &mut Cursor<&[u8]>) -> io::Result<Self> {
37 let block_pos = BlockPos::read(data)?;
38 let direction = Direction::read(data)?;
39 let click_x = f32::read(data)?;
41 let click_y = f32::read(data)?;
42 let click_z = f32::read(data)?;
43 let inside = bool::read(data)?;
44 let world_border_hit = bool::read(data)?;
45
46 let location = DVec3::new(
49 f64::from(block_pos.x()) + f64::from(click_x),
50 f64::from(block_pos.y()) + f64::from(click_y),
51 f64::from(block_pos.z()) + f64::from(click_z),
52 );
53
54 Ok(BlockHitResult {
55 location,
56 direction,
57 block_pos,
58 miss: false,
59 inside,
60 world_border_hit,
61 })
62 }
63}