#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Keys {
pub forward: bool,
pub back: bool,
pub left: bool,
pub right: bool,
pub jump: bool,
pub sneak: bool,
pub sprint: bool,
}
impl Keys {
pub const NONE: Keys = Keys {
forward: false,
back: false,
left: false,
right: false,
jump: false,
sneak: false,
sprint: false,
};
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct TickInput {
pub keys: Keys,
pub yaw: f32,
pub pitch: f32,
pub using_item: bool,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Abilities {
pub invulnerable: bool,
pub flying: bool,
pub allow_flying: bool,
pub creative: bool,
pub fly_speed: f32,
pub walk_speed: f32,
}
impl Default for Abilities {
fn default() -> Self {
Abilities {
invulnerable: false,
flying: false,
allow_flying: false,
creative: false,
fly_speed: 0.05,
walk_speed: 0.1,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub enum Packet {
StartSneaking,
StopSneaking,
StartSprinting,
StopSprinting,
Abilities(Abilities),
StartRidingJump {
strength: i32,
},
StopRidingJump,
Flying {
on_ground: bool,
},
Position {
x: f64,
y: f64,
z: f64,
on_ground: bool,
},
Look {
yaw: f32,
pitch: f32,
on_ground: bool,
},
Move {
pos: Option<[f64; 3]>,
look: Option<(f32, f32)>,
on_ground: bool,
horizontal_collision: bool,
},
PlayerInput(Keys),
PlayerLoaded,
StartFallFlying,
MoveVehicle {
pos: [f64; 3],
yaw: f32,
pitch: f32,
on_ground: bool,
},
SteerVehicle {
sideways: f32,
forward: f32,
jump: bool,
sneak: bool,
},
PaddleBoat {
left: bool,
right: bool,
},
PositionLook {
x: f64,
y: f64,
z: f64,
yaw: f32,
pitch: f32,
on_ground: bool,
},
}
const MAX_PACKETS: usize = 8;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Packets {
buf: [Packet; MAX_PACKETS],
len: usize,
}
impl Default for Packets {
fn default() -> Self {
Packets {
buf: [Packet::Flying { on_ground: false }; MAX_PACKETS],
len: 0,
}
}
}
impl Packets {
#[must_use]
pub fn new() -> Self {
Packets::default()
}
pub fn clear(&mut self) {
self.len = 0;
}
pub fn push(&mut self, p: Packet) {
assert!(self.len < MAX_PACKETS, "packet list overflow");
self.buf[self.len] = p;
self.len += 1;
}
#[must_use]
pub fn as_slice(&self) -> &[Packet] {
&self.buf[..self.len]
}
#[cfg(any(feature = "v26_1", feature = "v26_2", feature = "v26_3"))]
pub(crate) fn as_mut_slice(&mut self) -> &mut [Packet] {
&mut self.buf[..self.len]
}
#[must_use]
pub fn len(&self) -> usize {
self.len
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.len == 0
}
}
impl<'a> IntoIterator for &'a Packets {
type Item = &'a Packet;
type IntoIter = std::slice::Iter<'a, Packet>;
fn into_iter(self) -> Self::IntoIter {
self.as_slice().iter()
}
}