use super::super::player::PlayerState;
use super::{Mount, MountKind, camel};
pub(super) fn follow(e: &mut PlayerState, pos: [f64; 3], yaw: f32, pitch: f32) {
e.set_pos(pos[0], pos[1], pos[2]);
if yaw.is_finite() {
e.yaw = yaw;
}
if pitch.is_finite() {
e.pitch = pitch.clamp(-90.0, 90.0);
}
}
impl Mount {
pub fn set_passenger_count(&mut self, count: usize) {
self.s.passengers = count.min(usize::from(u8::MAX)) as u8;
}
#[must_use]
pub fn passenger_count(&self) -> usize {
usize::from(self.s.passengers)
}
pub fn follow_tracker(&mut self, pos: [f64; 3], yaw: f32, pitch: f32, was: bool, still: bool) {
self.s.follow = Some((pos, yaw, pitch));
self.s.follow_interp = (was, still);
}
pub fn set_interpolation_target(&mut self, target: ([f64; 3], f32, f32)) {
self.s.send_target = Some(target);
}
pub fn server_teleport(&mut self, delta: [f64; 3], on_ground: bool) {
self.e.vel = delta;
self.e.on_ground = on_ground;
self.s.ground = Some(on_ground);
}
pub fn set_watched_state(&mut self, vel: [f64; 3], on_ground: bool) {
self.e.vel = vel;
self.e.on_ground = on_ground;
self.s.ground = Some(on_ground);
}
pub fn server_motion(&mut self, vel: [f64; 3]) {
self.e.vel = vel;
}
pub fn server_on_ground(&mut self, on_ground: bool) {
self.e.on_ground = on_ground;
self.s.ground = Some(on_ground);
}
pub fn server_snap(&mut self, pos: [f64; 3], yaw: f32, pitch: f32) {
follow(&mut self.e, pos, yaw, pitch);
self.s.follow = None;
}
pub fn position_passenger(&self, p: &mut PlayerState) {
super::position_rider(self, p);
}
pub fn mark_ticked(&mut self) {
self.e.first_tick = false;
}
pub fn set_dash_state(&mut self, cooldown: i32, dashing: bool) {
if matches!(self.kind, MountKind::Camel | MountKind::CamelHusk) {
self.cm.dash_cooldown = cooldown;
self.cm.dashing = dashing;
} else if super::swim::is_nautilus(self.kind) {
self.sw.set_state(cooldown, dashing);
}
}
#[must_use]
pub fn dash_clock(
kind: MountKind,
state: (i32, bool),
ticks: u32,
grounded: bool,
) -> (i32, bool) {
let (mut cd, mut on) = state;
let camel = matches!(kind, MountKind::Camel | MountKind::CamelHusk);
if !camel && !super::swim::is_nautilus(kind) {
return state;
}
for _ in 0..ticks {
if on && cd == 0 && !(camel && !grounded) {
on = false;
cd = if camel {
camel::DASH_COOLDOWN
} else {
super::swim::DASH_COOLDOWN
};
} else if on && cd < if camel { 50 } else { 35 } && (!camel || grounded) {
on = false;
}
if cd > 0 {
cd -= 1;
}
if cd == 0 && (!on || camel && !grounded) {
break;
}
}
(cd, on)
}
#[must_use]
pub fn dash_synced(
kind: MountKind,
state: (i32, bool),
dashing: bool,
ticked: bool,
) -> (i32, bool) {
let cd = match kind {
MountKind::Camel | MountKind::CamelHusk if ticked && state.0 == 0 => {
camel::DASH_COOLDOWN
}
MountKind::Nautilus | MountKind::ZombieNautilus if ticked && state.0 == 0 => {
super::swim::DASH_COOLDOWN
}
_ => state.0,
};
(cd, dashing)
}
}