use ghast_protocol::{BlockPos, DecodeError, RawPacket};
use ghast_world::{WorldConfig, WorldError};
use crate::common::{
Abilities, Controls, EntityAction, MovePacket, Outbound, Pose, Teleport, Vec3,
};
use crate::hands::{BlockQuery, HeldItem};
use crate::version::DataSet;
#[macro_use]
mod shared;
#[cfg(test)]
mod boxed;
mod items;
#[cfg(feature = "v1_12_2")]
mod place112;
#[cfg(feature = "v1_16_5")]
mod place116;
#[cfg(feature = "v1_8")]
mod place18;
pub(crate) mod predict;
#[cfg(any(ghast_modern, feature = "v1_12_2", feature = "v1_16_5"))]
mod teams;
#[cfg(test)]
#[allow(unused_imports, dead_code)] pub(crate) mod test_chunks;
#[cfg(all(test, feature = "v1_8"))]
mod tests;
#[cfg(feature = "v1_12_2")]
mod use112;
#[cfg(feature = "v1_16_5")]
mod use116;
#[cfg(feature = "v1_8")]
mod use18;
#[cfg(feature = "v1_12_2")]
mod v1_12;
#[cfg(feature = "v1_16_5")]
mod v1_16_5;
#[cfg(feature = "v1_8")]
mod v1_8;
#[cfg(feature = "v26_1")]
pub(crate) mod v26_1;
#[cfg(feature = "v26_2")]
pub(crate) mod v26_2;
#[cfg(feature = "v26_3")]
pub(crate) mod v26_3;
#[cfg(feature = "v1_8")]
pub(crate) use v1_8::Sim18;
#[cfg(feature = "v1_12_2")]
pub(crate) use v1_12::Sim12;
#[cfg(feature = "v1_16_5")]
pub(crate) use v1_16_5::Sim16;
#[cfg(feature = "v26_1")]
pub(crate) use v26_1::Sim26;
#[cfg(feature = "v26_2")]
pub(crate) use v26_2::Sim262;
#[cfg(feature = "v26_3")]
pub(crate) use v26_3::Sim263;
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
use items::ACTIVATED_1_8;
pub(crate) use items::{food_points, held_item_facts};
#[cfg_attr(
not(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5")),
allow(dead_code)
)]
pub(crate) struct PickQuery<'a> {
pub eyes: Vec3,
pub rotation: (f32, f32),
pub look: Vec3,
pub held: Option<u16>,
pub now: bool,
pub creative: bool,
pub player_bb: ghast_physics::math::Aabb,
pub entities: &'a [ghast_physics::pick::PickEntity],
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) enum Crosshair {
Block(Option<crate::BlockHit>),
Entity {
index: usize,
hit: Vec3,
},
}
#[derive(Debug)]
pub(crate) enum SimError {
Decode(DecodeError),
World(WorldError),
}
impl From<DecodeError> for SimError {
fn from(e: DecodeError) -> Self {
SimError::Decode(e)
}
}
impl From<WorldError> for SimError {
fn from(e: WorldError) -> Self {
SimError::World(e)
}
}
pub trait WorldView {
fn is_column_loaded(&self, chunk_x: i32, chunk_z: i32) -> bool;
fn raw_block(&self, x: i32, y: i32, z: i32) -> Option<u32>;
fn loaded_columns(&self) -> usize;
fn build_height(&self) -> Option<(i32, i32)> {
None
}
fn entities(&self) -> Option<&ghast_entity::Entities>;
fn block_query(&self, x: i32, y: i32, z: i32) -> Option<BlockQuery>;
fn column(&self, chunk_x: i32, chunk_z: i32) -> Option<&ghast_world::Column> {
let _ = (chunk_x, chunk_z);
None
}
fn collisions(&self) -> (bool, bool) {
(false, false)
}
fn piston_uncertain(&self) -> bool {
false
}
fn crosshair(
&self,
eyes: Vec3,
rotation: (f32, f32),
look: Vec3,
reach: f64,
) -> Option<crate::BlockHit> {
let _ = rotation;
let blocks = |x: i32, y: i32, z: i32| self.block_query(x, y, z);
crate::hands::pick(&blocks, eyes, look, reach)
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
ghast_modern
))]
#[derive(Debug, Default)]
pub(super) struct SessionPackets {
login: Option<RawPacket>,
respawn: Option<RawPacket>,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
ghast_modern
))]
impl SessionPackets {
fn note(&mut self, raw: &RawPacket, login: i32, respawn: i32) {
let own = || RawPacket::new(raw.id, bytes::Bytes::copy_from_slice(&raw.body));
if raw.id == login {
self.login = Some(own());
self.respawn = None;
} else if raw.id == respawn {
self.respawn = Some(own());
}
}
fn replay(&self, mut apply: impl FnMut(&RawPacket)) {
for r in [&self.login, &self.respawn].into_iter().flatten() {
apply(r);
}
}
}
pub(super) const MAX_BLOCK_UPDATES: usize = 4096;
#[derive(Debug, Default)]
pub(super) struct BlockUpdates {
on: bool,
list: Vec<(BlockPos, u32)>,
dropped: usize,
}
impl BlockUpdates {
fn push(&mut self, pos: BlockPos, state: u32) {
if self.on {
if self.list.len() < MAX_BLOCK_UPDATES {
self.list.push((pos, state));
} else {
self.dropped += 1;
}
}
}
}
#[derive(Debug, Clone, Copy)]
#[cfg_attr(not(ghast_modern), allow(dead_code))]
pub(crate) struct PreTick {
pub(crate) using: Option<(bool, u16)>,
pub(crate) released: Option<(bool, u16, u32)>,
pub(crate) controls: Controls,
pub(crate) look: (f32, f32),
}
pub(crate) trait Sim: WorldView + std::fmt::Debug {
fn world_packet(&mut self, raw: &RawPacket) -> Result<(), SimError>;
fn reset_player(&mut self);
#[inline(always)]
fn item_use_facts(
&self,
stack: &ghast_inventory::Stack,
off_hand: bool,
held: HeldItem,
) -> HeldItem {
let _ = (stack, off_hand);
held
}
#[inline(always)]
fn modern_inputs(&self) -> bool {
false
}
#[inline(always)]
fn held_use_inputs(&mut self, inv: &mut ghast_inventory::Inventory) {
let _ = inv;
}
#[inline(always)]
fn pre_tick_wanted(&self) -> bool {
false
}
#[inline(always)]
fn pre_tick(&mut self, inv: &ghast_inventory::Inventory, t: &PreTick) -> bool {
let _ = (inv, t);
true
}
#[cfg(all(test, ghast_modern, feature = "v1_8", feature = "v1_16_5"))]
fn test_set_modern(
&mut self,
p: ghast_physics::modern::PlayerState,
x: ghast_physics::modern::PlayerExt,
) {
let _ = (p, x);
}
#[cfg(all(test, ghast_modern, feature = "v1_8", feature = "v1_16_5"))]
fn test_shared_flags(&self) -> u8 {
0
}
#[cfg(all(test, ghast_modern, feature = "v1_8", feature = "v1_16_5"))]
fn test_set_own_id(&mut self, id: i32) {
let _ = id;
}
#[inline(always)]
fn gliding(&self) -> bool {
false
}
fn weather(&mut self, reason: u8, value: f32) {
let _ = (reason, value);
}
fn mount_info(&self, entity_id: i32) -> Option<(i32, bool, bool)> {
let _ = entity_id;
None
}
fn mount_rules(&self, entity_id: i32) -> Option<ghast_inventory::MountRules> {
let _ = entity_id;
None
}
#[inline(always)]
fn take_reply(&mut self) -> Option<Outbound> {
None
}
#[inline(always)]
fn take_filter_dirty(&mut self) -> bool {
false
}
#[inline(always)]
fn vehicle(&self) -> Option<crate::common::Vehicle> {
None
}
#[inline(always)]
fn set_main_arm_left(&mut self, left: bool) {
let _ = left;
}
fn drop_level(&mut self) {
self.reset_player();
}
fn respawn_player(&mut self, keep: u8) {
let _ = keep;
self.reset_player();
}
fn teleport(&mut self, pose: &mut Pose, t: &Teleport);
fn abilities(&mut self, a: Abilities);
fn food(&mut self, food: i32);
fn velocity(&mut self, v: Vec3, add: bool);
fn movement_speed(&mut self, base: f64, modifiers: &[(u128, f64, u8)]);
fn status_effects(&mut self, effects: &std::collections::BTreeMap<i8, i8>);
fn boots(&mut self, depth_strider: u8, soul_speed: u8);
fn feet_item(&mut self, id: Option<i32>) {
let _ = id;
}
#[inline(always)]
fn hand_items(&mut self, inv: &mut ghast_inventory::Inventory) {
let _ = inv;
}
#[inline(always)]
fn hands_at_packet(&mut self, inv: &ghast_inventory::Inventory) {
let _ = inv;
}
fn spectator(&mut self, on: bool);
#[cfg(ghast_modern)]
fn modern_player(&self) -> Option<&ghast_physics::modern::PlayerState> {
None
}
fn step(
&mut self,
pose: &mut Pose,
controls: Controls,
using_item: bool,
entity_id: i32,
out: &mut Vec<Outbound>,
);
fn entity_packet_ids(&self) -> Vec<i32>;
fn world_packet_ids(&self) -> Vec<i32>;
#[cfg_attr(
not(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5")),
allow(dead_code)
)]
fn entity_config(&self) -> Option<ghast_entity::Config>;
fn set_entities(&mut self, config: Option<ghast_entity::Config>);
fn set_flying(&mut self, flying: bool, out: &mut Vec<Outbound>);
fn collect_block_updates(&mut self, on: bool);
fn drain_block_updates(&mut self, out: &mut Vec<(BlockPos, u32)>) -> usize;
fn predict_air(&mut self, x: i32, y: i32, z: i32);
#[inline]
fn dig_sent(
&mut self,
pos: BlockPos,
status: crate::common::DigStatus,
broken: bool,
sequence: i32,
player: Vec3,
) {
let _ = (status, sequence, player);
if broken {
self.predict_air(pos.x, pos.y, pos.z);
}
}
#[inline]
fn place_sent(&mut self, p: &predict::PlaceSent<'_>) -> bool {
let _ = p;
false
}
#[inline]
fn place_suppressed(&self, pos: BlockPos, face: crate::common::Face, held: u16) -> bool {
let _ = (pos, face, held);
false
}
#[inline]
fn place_rules(&self, q: &predict::PlaceQuery<'_>) -> predict::PlaceRules {
let _ = q;
predict::PlaceRules::default()
}
#[inline]
fn air_use(&self, q: &predict::AirQuery<'_>) -> predict::AirAnswer {
let _ = q;
predict::AirAnswer::Flags
}
#[inline]
fn air_use_sent(&mut self, blocks: &[(BlockPos, u32)]) {
let _ = blocks;
}
#[cfg(test)]
#[allow(dead_code)] fn test_air_case(&mut self, case: &serde_json::Value) {
let _ = case;
}
#[cfg(test)]
#[allow(dead_code)] fn test_tracker_from_join(&mut self) {}
#[cfg(test)]
#[allow(dead_code)] fn set_player_pos(&mut self, p: Vec3) {
let _ = p;
}
#[inline(always)]
fn records_digs(&self) -> bool {
false
}
#[inline(always)]
fn teleport_sequence(&mut self, sequence: Option<i32>) {
let _ = sequence;
}
#[inline(always)]
fn take_snap(&mut self) -> Option<Vec3> {
None
}
fn held_item(&self, id: u16, count: u8, efficiency: u8) -> HeldItem;
fn crosshair_now(
&self,
eyes: Vec3,
rotation: (f32, f32),
look: Vec3,
held: Option<u16>,
) -> Option<crate::BlockHit> {
let _ = held;
self.crosshair(eyes, rotation, look, crate::hands::REACH)
}
fn pick_margin(&self, e: &ghast_entity::Entity) -> Option<f32> {
crate::engine::legacy_pick_margin(self.entities()?, e)
}
fn search_order(&self, e: &ghast_entity::Entity) -> Option<(i32, i32, i32, u32)> {
e.search_order()
}
fn tick_entities(&mut self, pose: &mut Pose) {
let _ = pose;
}
#[inline(always)]
fn send_changes(&mut self, entity_id: i32, out: &mut Vec<Outbound>) {
let _ = (entity_id, out);
}
#[inline(always)]
fn entity_event(&mut self, entity_id: i32, status: i8) {
let _ = (entity_id, status);
}
fn entities_mut(&mut self) -> Option<&mut ghast_entity::Entities> {
None
}
fn set_entity_push(&mut self, on: bool) {
let _ = on;
}
fn set_entity_physics(&mut self, on: bool) {
let _ = on;
}
fn sign_at(&self, pos: ghast_protocol::BlockPos) -> Option<bool> {
let _ = pos;
None
}
fn sleep_at(&mut self, pose: &mut Pose, bed: ghast_protocol::BlockPos) {
let _ = (pose, bed);
}
fn wake_up(&mut self) {}
fn take_sleep(&mut self, pose: &mut Pose) -> Option<Option<ghast_protocol::BlockPos>> {
let _ = pose;
None
}
#[inline(always)]
fn fishing(&self) -> Option<&crate::fishing::Bobber> {
None
}
#[inline(always)]
fn fishing_news(&self) -> bool {
false
}
fn drain_fishing(&mut self, out: &mut Vec<crate::fishing::FishingEvent>) {
let _ = out;
}
fn block_interaction_range(&self) -> f64 {
4.5
}
fn level_load_start(&mut self) {}
fn player_alive(&mut self, alive: bool) {
let _ = alive;
}
fn load_gate_tick(&mut self, section_compiled: bool, timed_out: bool) -> bool {
let _ = (section_compiled, timed_out);
false
}
fn tick_unloaded(&mut self) {}
fn crosshair_target(&self, q: &PickQuery<'_>) -> Crosshair {
Crosshair::Block(if q.now {
self.crosshair_now(q.eyes, q.rotation, q.look, q.held)
} else {
self.crosshair(q.eyes, q.rotation, q.look, crate::hands::REACH)
})
}
fn attributes(&mut self, attributes: &[crate::common::AttributeUpdate]) {
let _ = attributes;
}
fn entity_attributes(&mut self, entity_id: i32, attributes: &[crate::common::AttributeUpdate]) {
let _ = (entity_id, attributes);
}
fn chunk_batch_start(&mut self, now_nanos: i64) {
let _ = now_nanos;
}
fn chunk_batch_finished(&mut self, batch_size: i32, now_nanos: i64) -> f32 {
let _ = (batch_size, now_nanos);
3.5
}
fn registry_data(&mut self, raw: &RawPacket) {
let _ = raw;
}
fn day_clock(&self) -> Option<i32> {
Some(crate::common::ClockUpdate::LEGACY_DAY)
}
fn attack_hurts(&self, e: &ghast_entity::Entity) -> bool {
e.is_player()
}
fn eye_height(&self) -> Option<f64> {
None
}
fn awake_eye_height(&self) -> Option<f64> {
self.eye_height()
}
fn attack_slow(&mut self, target: i32, yaw: f32, knockback: i32, sprint_bonus: bool) {
let _ = (target, yaw, knockback, sprint_bonus);
}
fn sprinting(&self) -> bool {
false
}
fn server_flags(&self) -> Option<u8> {
None
}
fn take_absorption(&mut self) -> Option<f32> {
None
}
fn take_living_flags(&mut self) -> Option<u8> {
None
}
fn velocity_now(&self) -> Vec3 {
Vec3::default()
}
}
#[inline]
pub(super) fn attack_knockback_applies(
knockback: i32,
sprinting: bool,
sprint_bonus: bool,
) -> bool {
knockback + i32::from(sprinting && sprint_bonus) > 0
}
#[derive(Debug, Clone, Default)]
pub(crate) struct SimOptions {
pub record: Option<std::path::PathBuf>,
pub force_step_position: ForceStepPosition,
pub entities: Option<ghast_entity::Config>,
pub world: Option<WorldConfig>,
pub shared_chunks: Option<ghast_world::SharedChunks>,
#[cfg_attr(
not(any(ghast_modern, feature = "v1_12_2", feature = "v1_16_5")),
allow(dead_code)
)]
pub profile_name: Option<String>,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ForceStepPosition {
#[default]
Off,
Always,
StepUpOnly,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
pub(super) fn force_position(
packets: &mut ghast_physics::Packets,
cur: [f64; 3],
sent_pos: &mut [f64; 3],
ticks_since_pos: &mut i32,
mode: ForceStepPosition,
) {
use ghast_physics::Packet as P;
if mode == ForceStepPosition::Off || cur[1] == sent_pos[1] {
return;
}
let Some(last) = packets.as_slice().last().copied() else {
return;
};
if mode == ForceStepPosition::StepUpOnly {
let on_ground = matches!(
last,
P::Flying { on_ground: true }
| P::Look {
on_ground: true,
..
}
);
if !on_ground || cur[1] <= sent_pos[1] {
return;
}
}
let new = match last {
P::Flying { on_ground } => P::Position {
x: cur[0],
y: cur[1],
z: cur[2],
on_ground,
},
P::Look {
yaw,
pitch,
on_ground,
} => P::PositionLook {
x: cur[0],
y: cur[1],
z: cur[2],
yaw,
pitch,
on_ground,
},
_ => return,
};
let mut out = ghast_physics::Packets::new();
let n = packets.len();
for p in &packets.as_slice()[..n - 1] {
out.push(*p);
}
out.push(new);
*packets = out;
*sent_pos = cur;
*ticks_since_pos = 0;
}
#[cfg(any(feature = "v1_16_5", ghast_modern))]
pub(super) fn activates_1_16(name: &str) -> bool {
const EXACT: &[&str] = &[
"chest",
"trapped_chest",
"ender_chest",
"crafting_table",
"furnace",
"blast_furnace",
"smoker",
"barrel",
"anvil",
"chipped_anvil",
"damaged_anvil",
"enchanting_table",
"brewing_stand",
"hopper",
"dispenser",
"dropper",
"repeater",
"comparator",
"note_block",
"jukebox",
"cake",
"loom",
"stonecutter",
"grindstone",
"cartography_table",
"smithing_table",
"lectern",
"bell",
"beacon",
"daylight_detector",
"respawn_anchor",
"composter",
"lever",
"command_block",
"chain_command_block",
"repeating_command_block",
"structure_block",
"jigsaw",
"dragon_egg",
"flower_pot",
"sweet_berry_bush",
];
EXACT.contains(&name)
|| name.ends_with("_shulker_box")
|| name == "shulker_box"
|| name.ends_with("_bed")
|| name.ends_with("_button")
|| name.ends_with("_fence_gate")
|| (name.ends_with("_door") && name != "iron_door")
|| (name.ends_with("_trapdoor") && name != "iron_trapdoor")
|| name.starts_with("potted_")
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
pub(super) fn legacy_bed_position(
bed: ghast_protocol::BlockPos,
meta: Option<u8>,
computed: bool,
) -> [f64; 3] {
let (dx, dz) = match meta.map(|m| m & 3) {
Some(0) => (0, 1),
Some(1) => (-1, 0),
Some(2) => (0, -1),
Some(3) => (1, 0),
_ => (0, 0),
};
let off = |d: i32| -> f32 {
if computed {
0.5f32 + d as f32 * 0.4f32
} else {
match d {
1 => 0.9f32,
-1 => 0.1f32,
_ => 0.5f32,
}
}
};
[
f64::from(bed.x as f32 + off(dx)),
f64::from(bed.y as f32 + 0.6875f32),
f64::from(bed.z as f32 + off(dz)),
]
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
pub(super) fn legacy_crosshair(t: ghast_physics::pick::legacy::Target, eye: [f64; 3]) -> Crosshair {
use ghast_physics::pick::legacy::Target;
match t {
Target::Block(h) => Crosshair::Block(block_hit(&h, eye)),
Target::Entity(e) => Crosshair::Entity {
index: e.index,
hit: Vec3::new(e.location[0], e.location[1], e.location[2]),
},
Target::None | Target::TooFar { .. } => Crosshair::Block(None),
}
}
#[cfg(any(feature = "v1_16_5", ghast_modern))]
pub(super) fn modern_crosshair(t: ghast_physics::pick::Target, eye: [f64; 3]) -> Crosshair {
use ghast_physics::pick::Target;
match t {
Target::Block(h) => Crosshair::Block(block_hit(&h, eye)),
Target::Entity(e) => Crosshair::Entity {
index: e.index,
hit: Vec3::new(e.location[0], e.location[1], e.location[2]),
},
}
}
pub(super) fn block_hit(
hit: &ghast_physics::pick::BlockHit,
eye: [f64; 3],
) -> Option<crate::BlockHit> {
use ghast_physics::pick::Direction;
if !hit.is_block() {
return None;
}
let face = match hit.face {
Direction::Down => crate::Face::Down,
Direction::Up => crate::Face::Up,
Direction::North => crate::Face::North,
Direction::South => crate::Face::South,
Direction::West => crate::Face::West,
Direction::East => crate::Face::East,
};
let [lx, ly, lz] = hit.location;
let distance = ((lx - eye[0]).powi(2) + (ly - eye[1]).powi(2) + (lz - eye[2]).powi(2)).sqrt();
Some(crate::BlockHit {
pos: BlockPos::new(hit.pos[0], hit.pos[1], hit.pos[2]),
face,
hit: Vec3::new(lx, ly, lz),
distance,
})
}
#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", ghast_modern))]
pub(super) fn union(boxes: &[ghast_data::Aabb]) -> Option<[f64; 6]> {
let mut u = [1.0_f64, 1.0, 1.0, 0.0, 0.0, 0.0];
for b in boxes {
u[0] = u[0].min(b.min_x);
u[1] = u[1].min(b.min_y);
u[2] = u[2].min(b.min_z);
u[3] = u[3].max(b.max_x.min(1.0));
u[4] = u[4].max(b.max_y.min(1.0));
u[5] = u[5].max(b.max_z.min(1.0));
}
(!boxes.is_empty()).then_some(u)
}
pub(super) fn config() -> WorldConfig {
WorldConfig::default()
.with_biomes(false)
.with_light(false)
.with_block_entities(false)
}
pub(super) fn abilities_flags(a: &ghast_physics::Abilities) -> i8 {
let mut f = 0;
if a.invulnerable {
f |= 1;
}
if a.flying {
f |= 2;
}
if a.allow_flying {
f |= 4;
}
if a.creative {
f |= 8;
}
f
}
pub(super) fn push_packets(
packets: &ghast_physics::Packets,
entity_id: i32,
out: &mut Vec<Outbound>,
) {
for p in packets {
use ghast_physics::Packet as P;
let action = |action| Outbound::EntityAction { entity_id, action };
let wire = match *p {
P::StartSneaking => action(EntityAction::StartSneaking),
P::StopSneaking => action(EntityAction::StopSneaking),
P::StartSprinting => action(EntityAction::StartSprinting),
P::StopSprinting => action(EntityAction::StopSprinting),
P::StartFallFlying => action(EntityAction::StartFallFlying),
P::StartRidingJump { strength } => Outbound::RidingJump {
entity_id,
strength,
},
P::StopRidingJump => action(EntityAction::StopRidingJump),
P::Abilities(a) => Outbound::Abilities {
flags: abilities_flags(&a),
flying_speed: a.fly_speed,
walking_speed: a.walk_speed,
},
P::Flying { on_ground } => Outbound::Move(MovePacket::Flying {
horizontal_collision: false,
on_ground,
}),
P::Position { x, y, z, on_ground } => Outbound::Move(MovePacket::Position {
horizontal_collision: false,
pos: Vec3::new(x, y, z),
on_ground,
}),
P::Look {
yaw,
pitch,
on_ground,
} => Outbound::Move(MovePacket::Look {
horizontal_collision: false,
yaw,
pitch,
on_ground,
}),
P::PositionLook {
x,
y,
z,
yaw,
pitch,
on_ground,
} => Outbound::Move(MovePacket::PositionLook {
horizontal_collision: false,
pos: Vec3::new(x, y, z),
yaw,
pitch,
on_ground,
}),
P::Move {
pos,
look,
on_ground,
horizontal_collision,
} => Outbound::Move(match (pos, look) {
(Some([x, y, z]), Some((yaw, pitch))) => MovePacket::PositionLook {
pos: Vec3::new(x, y, z),
yaw,
pitch,
on_ground,
horizontal_collision,
},
(Some([x, y, z]), None) => MovePacket::Position {
pos: Vec3::new(x, y, z),
on_ground,
horizontal_collision,
},
(None, Some((yaw, pitch))) => MovePacket::Look {
yaw,
pitch,
on_ground,
horizontal_collision,
},
(None, None) => MovePacket::Flying {
on_ground,
horizontal_collision,
},
}),
P::MoveVehicle {
pos,
yaw,
pitch,
on_ground,
} => Outbound::VehicleMove {
pos: Vec3::new(pos[0], pos[1], pos[2]),
yaw,
pitch,
on_ground,
},
P::PaddleBoat { left, right } => Outbound::SteerBoat { left, right },
P::SteerVehicle {
sideways,
forward,
jump,
sneak,
} => Outbound::SteerVehicle {
sideways,
forward,
jump,
sneak,
},
P::PlayerInput(k) => Outbound::PlayerInput(Controls {
forward: k.forward,
back: k.back,
left: k.left,
right: k.right,
jump: k.jump,
sneak: k.sneak,
sprint: k.sprint,
}),
_ => {
debug_assert!(false, "physics packet without a wire form: {p:?}");
continue;
}
};
out.push(wire);
}
}
#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", ghast_modern))]
pub(super) fn physics_abilities(a: Abilities) -> ghast_physics::Abilities {
ghast_physics::Abilities {
invulnerable: a.flags & 1 != 0,
flying: a.flags & 2 != 0,
allow_flying: a.flags & 4 != 0,
creative: a.flags & 8 != 0,
fly_speed: a.flying_speed,
walk_speed: a.walking_speed,
}
}
pub(super) fn keys(c: Controls) -> ghast_physics::Keys {
ghast_physics::Keys {
forward: c.forward,
back: c.back,
left: c.left,
right: c.right,
jump: c.jump,
sneak: c.sneak,
sprint: c.sprint,
}
}
#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
pub(super) fn rel_flags(flags: i8) -> [bool; 5] {
use crate::common::teleport_flags as fl;
[
flags & fl::X != 0,
flags & fl::Y != 0,
flags & fl::Z != 0,
flags & fl::YAW != 0,
flags & fl::PITCH != 0,
]
}