#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct PlayerExt {
pub ultrawarm: bool,
pub spin_attack: bool,
pub riptide_ticks: i32,
pub fall_flying: bool,
pub elytra: bool,
pub glide_pose: bool,
pub sleeping: bool,
pub mount_jump_ticks: i32,
mount_jump_bar: u32,
mount_jump: Option<i32>,
}
impl PlayerExt {
#[must_use]
pub fn new() -> PlayerExt {
PlayerExt::default()
}
pub fn apply_living_flags(&mut self, flags: u8) {
self.spin_attack = flags & 4 != 0;
}
pub fn apply_shared_flags(&mut self, p: &mut super::PlayerState, flags: u8) {
p.sprinting = flags & 0x08 != 0;
p.swimming = flags & 0x10 != 0;
self.fall_flying = flags & 0x80 != 0;
}
#[must_use]
pub fn shared_flags(&self, p: &super::PlayerState) -> u8 {
(u8::from(p.sprinting) << 3)
| (u8::from(p.swimming) << 4)
| (u8::from(self.fall_flying) << 7)
}
#[must_use]
pub fn mount_jump_bar(&self) -> f32 {
f32::from_bits(self.mount_jump_bar)
}
pub(super) fn mount_jump_bar_tick(
&mut self,
jumping_mount: bool,
prev: bool,
now: bool,
) -> Option<i32> {
if !jumping_mount {
self.mount_jump_bar = 0;
return None;
}
let mut bar = f32::from_bits(self.mount_jump_bar);
let mut released = None;
if self.mount_jump_ticks < 0 {
self.mount_jump_ticks += 1;
if self.mount_jump_ticks == 0 {
bar = 0.0;
}
}
if prev && !now {
self.mount_jump_ticks = -10;
let s = (bar * 100.0).floor() as i32;
self.mount_jump = Some(s);
released = Some(s);
} else if !prev && now {
self.mount_jump_ticks = 0;
bar = 0.0;
} else if prev {
self.mount_jump_ticks += 1;
bar = if self.mount_jump_ticks < 10 {
self.mount_jump_ticks as f32 * 0.1
} else {
0.8 + 2.0 / (self.mount_jump_ticks - 9) as f32 * 0.1
};
}
self.mount_jump_bar = bar.to_bits();
released
}
pub fn take_mount_jump(&mut self) -> Option<i32> {
self.mount_jump.take()
}
#[must_use]
pub fn is_inert(&self) -> bool {
*self == PlayerExt::default()
}
}