use ghast_data::v1_8::BlockState;
pub use super::legacy::Target;
use super::legacy::{Shape, target, trace};
pub use super::legacy::{eye_position, look_vector, ray_end};
use super::{BlockHit, PickEntity};
use crate::math::Aabb;
use crate::v1_8::{RayShape, ray_shape};
use crate::world::BlockView;
pub const REACH: f64 = 4.5;
pub const CREATIVE_REACH: f64 = 5.0;
#[must_use]
pub fn shape<W: BlockView<State = BlockState>>(world: &W, pos: [i32; 3], liquids: bool) -> Shape {
let r = ray_shape(world, pos[0], pos[1], pos[2], liquids);
if r != RayShape::None && world.block(pos[0], pos[1], pos[2]).block().id() == 36 {
return Shape::Never;
}
match r {
RayShape::None => Shape::Skip,
RayShape::Bounds(b) => Shape::One(b),
RayShape::Stairs(p) => {
let mut boxes = [Aabb::FULL; 8];
let mut len = 0u8;
for b in p.boxes().into_iter().flatten() {
boxes[usize::from(len)] = b;
len += 1;
}
Shape::Many(boxes, len)
}
}
}
pub fn clip<W: BlockView<State = BlockState>>(
world: &W,
start: [f64; 3],
end: [f64; 3],
liquids: bool,
return_last: bool,
) -> Option<BlockHit> {
trace(start, end, return_last, |p| shape(world, p, liquids))
}
pub fn pick<W: BlockView<State = BlockState>>(
world: &W,
eye: [f64; 3],
look: [f64; 3],
reach: f64,
) -> Option<BlockHit> {
clip(world, eye, ray_end(eye, look, reach), false, true)
}
pub fn pick_target<W: BlockView<State = BlockState>>(
world: &W,
eye: [f64; 3],
look: [f64; 3],
creative: bool,
player_bb: &Aabb,
entities: &[PickEntity],
) -> Target {
let reach = if creative { CREATIVE_REACH } else { REACH };
target(
pick(world, eye, look, reach),
eye,
look,
reach,
creative,
player_bb,
entities,
)
}