use ghast_data::v1_12::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_12::{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 {
match ray_shape(world, pos[0], pos[1], pos[2], liquids) {
RayShape::None => Shape::Skip,
RayShape::Never => Shape::Never,
RayShape::Bounds(b) => Shape::One(b),
RayShape::Boxes { boxes, len } => {
let mut all = [Aabb::FULL; 8];
all[..4].copy_from_slice(&boxes);
Shape::Many(all, 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,
)
}
pub const ITEM_REACH: f64 = 5.0;
pub fn item_ray<W: BlockView<State = BlockState>>(
world: &W,
eye: [f64; 3],
look: [f64; 3],
liquids: bool,
) -> Option<BlockHit> {
let mut first = true;
trace(eye, ray_end(eye, look, ITEM_REACH), false, |p| {
let start = std::mem::replace(&mut first, false);
if !liquids {
let valid = (0..256).contains(&p[1])
&& (-30_000_000..30_000_000).contains(&p[0])
&& (-30_000_000..30_000_000).contains(&p[2]);
let s = if valid {
world.block(p[0], p[1], p[2])
} else {
BlockState::AIR
};
if !s.selection().has_collision_box && (start || s.block().material().name != "portal")
{
return Shape::Skip;
}
}
shape(world, p, liquids)
})
}