#[cfg(feature = "v26_1")]
pub(crate) use ghast_data::v26_1 as shared;
#[cfg(all(feature = "v26_2", not(feature = "v26_1")))]
pub(crate) use ghast_data::v26_2 as shared;
#[cfg(all(feature = "v26_3", not(any(feature = "v26_1", feature = "v26_2"))))]
pub(crate) use ghast_data::v26_3 as shared;
use shared::{StatePhys, VoxelShapeRef};
pub trait Rules: 'static {
type State: Copy + PartialEq;
const PROTOCOL: i32;
const AIR: Self::State;
fn phys(s: Self::State) -> StatePhys;
#[cfg(feature = "v26_1")]
fn block(s: Self::State) -> &'static ghast_data::v26_1::BlockData;
#[cfg(feature = "v26_1")]
#[inline]
fn friction(s: Self::State) -> f32 {
Self::block(s).friction
}
#[cfg(not(feature = "v26_1"))]
fn friction(s: Self::State) -> f32;
#[cfg(feature = "v26_1")]
#[inline]
fn speed_factor(s: Self::State) -> f32 {
Self::block(s).speed_factor
}
#[cfg(not(feature = "v26_1"))]
fn speed_factor(s: Self::State) -> f32;
#[cfg(feature = "v26_1")]
#[inline]
fn jump_factor(s: Self::State) -> f32 {
Self::block(s).jump_factor
}
#[cfg(not(feature = "v26_1"))]
fn jump_factor(s: Self::State) -> f32;
#[cfg(feature = "v26_1")]
#[inline]
fn block_flags(s: Self::State) -> u32 {
Self::block(s).flags
}
#[cfg(not(feature = "v26_1"))]
fn block_flags(s: Self::State) -> u32;
#[cfg(feature = "v26_1")]
#[inline]
fn offset(s: Self::State) -> Option<(f32, f32, bool)> {
Self::block(s).offset
}
#[cfg(not(feature = "v26_1"))]
fn offset(s: Self::State) -> Option<(f32, f32, bool)>;
#[cfg(feature = "v26_1")]
#[inline]
fn block_name(s: Self::State) -> &'static str {
Self::block(s).name
}
#[cfg(not(feature = "v26_1"))]
fn block_name(s: Self::State) -> &'static str;
fn voxel(i: u16) -> &'static VoxelShapeRef;
const FULL_CUBE_VOXEL: u16;
const SCAFFOLDING_BOTTOM_VOXEL: u16;
const POWDER_SNOW_FALLING_VOXEL: u16;
const POSITION_THRESHOLD_SQ: f64;
const POSITION_REMINDER: i32;
const HORIZONTAL_CUTOFF_SQ: f64;
const RESTITUTION: bool = false;
#[inline]
fn bounce_restitution(s: Self::State) -> f32 {
if Self::phys(s).kind() == shared::BlockKind::SlimeBlock as u8 {
1.0
} else if Self::block_flags(s) & shared::block_flags::BED != 0 {
0.75
} else {
0.0
}
}
const TELEPORT_CONFIRM_POSE: bool = false;
const LIQUID_SCAN_CLOSED: bool = false;
const BOUNCE_ABOVE_GRAVITY: bool = false;
const EYE_CAMERA_HEIGHT: bool = false;
#[inline]
fn sturdy_down(s: Self::State) -> bool {
let _ = s;
false
}
const FLOW_BLOCKED_BY_SIGNS: bool = false;
const SEND_AFTER_ENTITIES: bool = false;
const GLIDE_START_NOT_IN_LAVA: bool = false;
const ENTITY_QUERY_UP_STEP: bool = false;
}
#[cfg(feature = "v26_1")]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct V26_1;
#[cfg(feature = "v26_1")]
impl Rules for V26_1 {
type State = ghast_data::v26_1::BlockState;
const PROTOCOL: i32 = 775;
const AIR: Self::State = ghast_data::v26_1::BlockState::AIR;
#[inline]
fn phys(s: Self::State) -> StatePhys {
s.phys()
}
#[inline]
fn block(s: Self::State) -> &'static ghast_data::v26_1::BlockData {
s.block().data()
}
#[inline]
fn voxel(i: u16) -> &'static VoxelShapeRef {
&ghast_data::v26_1::voxel_shapes()[usize::from(i)]
}
const FULL_CUBE_VOXEL: u16 = ghast_data::v26_1::FULL_CUBE_VOXEL;
const SCAFFOLDING_BOTTOM_VOXEL: u16 = ghast_data::v26_1::SCAFFOLDING_BOTTOM_VOXEL;
const POWDER_SNOW_FALLING_VOXEL: u16 = ghast_data::v26_1::POWDER_SNOW_FALLING_VOXEL;
const POSITION_THRESHOLD_SQ: f64 = 2.0e-4 * 2.0e-4;
const POSITION_REMINDER: i32 = 20;
const HORIZONTAL_CUTOFF_SQ: f64 = 9.0e-6;
}
#[cfg(feature = "v26_2")]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct V26_2;
#[cfg(feature = "v26_2")]
impl Rules for V26_2 {
type State = ghast_data::v26_2::BlockState;
const PROTOCOL: i32 = 776;
const AIR: Self::State = ghast_data::v26_2::BlockState::AIR;
#[inline]
fn phys(s: Self::State) -> StatePhys {
s.phys()
}
#[cfg(feature = "v26_1")]
fn block(s: Self::State) -> &'static ghast_data::v26_1::BlockData {
let stone = ghast_data::v26_1::BlockState::from_id(1).map(|s| s.block());
match ghast_data::v26_1::Block::from_name(s.block().name()).or(stone) {
Some(b) => b.data(),
None => ghast_data::v26_1::BlockState::AIR.block().data(),
}
}
#[inline]
fn friction(s: Self::State) -> f32 {
s.block().data().friction
}
#[inline]
fn speed_factor(s: Self::State) -> f32 {
s.block().data().speed_factor
}
#[inline]
fn jump_factor(s: Self::State) -> f32 {
s.block().data().jump_factor
}
#[inline]
fn block_flags(s: Self::State) -> u32 {
s.block().data().flags
}
#[inline]
fn offset(s: Self::State) -> Option<(f32, f32, bool)> {
s.block().data().offset
}
#[inline]
fn block_name(s: Self::State) -> &'static str {
s.block().name()
}
#[inline]
fn voxel(i: u16) -> &'static VoxelShapeRef {
&ghast_data::v26_2::voxel_shapes()[usize::from(i)]
}
const FULL_CUBE_VOXEL: u16 = ghast_data::v26_2::FULL_CUBE_VOXEL;
const SCAFFOLDING_BOTTOM_VOXEL: u16 = ghast_data::v26_2::SCAFFOLDING_BOTTOM_VOXEL;
const POWDER_SNOW_FALLING_VOXEL: u16 = ghast_data::v26_2::POWDER_SNOW_FALLING_VOXEL;
const POSITION_THRESHOLD_SQ: f64 = 2.0e-4 * 2.0e-4;
const POSITION_REMINDER: i32 = 20;
const HORIZONTAL_CUTOFF_SQ: f64 = 9.0e-6;
const RESTITUTION: bool = true;
}
#[cfg(feature = "v26_3")]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct V26_3;
#[cfg(feature = "v26_3")]
impl Rules for V26_3 {
type State = ghast_data::v26_3::BlockState;
const PROTOCOL: i32 = 777;
const AIR: Self::State = ghast_data::v26_3::BlockState::AIR;
#[inline]
fn phys(s: Self::State) -> StatePhys {
s.phys()
}
#[cfg(feature = "v26_1")]
fn block(s: Self::State) -> &'static ghast_data::v26_1::BlockData {
let stone = ghast_data::v26_1::BlockState::from_id(1).map(|s| s.block());
match ghast_data::v26_1::Block::from_name(s.block().name()).or(stone) {
Some(b) => b.data(),
None => ghast_data::v26_1::BlockState::AIR.block().data(),
}
}
#[inline]
fn friction(s: Self::State) -> f32 {
s.block().data().friction
}
#[inline]
fn speed_factor(s: Self::State) -> f32 {
s.block().data().speed_factor
}
#[inline]
fn jump_factor(s: Self::State) -> f32 {
s.block().data().jump_factor
}
#[inline]
fn block_flags(s: Self::State) -> u32 {
s.block().data().flags
}
#[inline]
fn offset(s: Self::State) -> Option<(f32, f32, bool)> {
s.block().data().offset
}
#[inline]
fn block_name(s: Self::State) -> &'static str {
s.block().name()
}
#[inline]
fn voxel(i: u16) -> &'static VoxelShapeRef {
&ghast_data::v26_3::voxel_shapes()[usize::from(i)]
}
const FULL_CUBE_VOXEL: u16 = ghast_data::v26_3::FULL_CUBE_VOXEL;
const SCAFFOLDING_BOTTOM_VOXEL: u16 = ghast_data::v26_3::SCAFFOLDING_BOTTOM_VOXEL;
const POWDER_SNOW_FALLING_VOXEL: u16 = ghast_data::v26_3::POWDER_SNOW_FALLING_VOXEL;
const POSITION_THRESHOLD_SQ: f64 = 2.0e-4 * 2.0e-4;
const POSITION_REMINDER: i32 = 20;
const HORIZONTAL_CUTOFF_SQ: f64 = 9.0e-6;
const RESTITUTION: bool = true;
const TELEPORT_CONFIRM_POSE: bool = true;
const LIQUID_SCAN_CLOSED: bool = true;
const BOUNCE_ABOVE_GRAVITY: bool = true;
const EYE_CAMERA_HEIGHT: bool = true;
const FLOW_BLOCKED_BY_SIGNS: bool = true;
const SEND_AFTER_ENTITIES: bool = true;
const GLIDE_START_NOT_IN_LAVA: bool = true;
const ENTITY_QUERY_UP_STEP: bool = true;
#[inline]
fn bounce_restitution(s: Self::State) -> f32 {
if s.phys().kind() == shared::BlockKind::SlimeBlock as u8 {
1.0
} else if s.block().data().flags & shared::block_flags::BED != 0
|| s.block() == ghast_data::v26_3::Block::SHELF_MUSHROOM
{
0.75
} else {
0.0
}
}
#[inline]
fn sturdy_down(s: Self::State) -> bool {
s.phys().flags() & shared::state_flags::STURDY_DOWN != 0
}
}