azalea_physics/
local_player.rs

1use azalea_core::position::Vec2;
2use bevy_ecs::component::Component;
3
4/// Component for entities that can move and sprint. Usually only in
5/// [`LocalEntity`]s.
6///
7/// [`LocalEntity`]: azalea_entity::LocalEntity
8#[derive(Default, Component, Clone)]
9pub struct PhysicsState {
10    /// Minecraft only sends a movement packet either after 20 ticks or if the
11    /// player moved enough. This is that tick counter.
12    pub position_remainder: u32,
13    pub was_sprinting: bool,
14    // Whether we're going to try to start sprinting this tick. Equivalent to
15    // holding down ctrl for a tick.
16    pub trying_to_sprint: bool,
17
18    /// Whether our player is currently trying to sneak.
19    ///
20    /// This is distinct from
21    /// [`AbstractEntityShiftKeyDown`](azalea_entity::metadata::AbstractEntityShiftKeyDown),
22    /// which is a metadata value that is controlled by the server and affects
23    /// how the nametags of other entities are displayed.
24    ///
25    /// To check whether we're actually sneaking, you can check the
26    /// [`Crouching`](azalea_entity::Crouching) or [`Pose`](azalea_entity::Pose)
27    /// components.
28    pub trying_to_crouch: bool,
29
30    pub move_direction: WalkDirection,
31    pub move_vector: Vec2,
32}
33
34/// A direction that a player can walk in, including none.
35///
36/// Superset of [`SprintDirection`].
37#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
38pub enum WalkDirection {
39    #[default]
40    None,
41    Forward,
42    Backward,
43    Left,
44    Right,
45    ForwardRight,
46    ForwardLeft,
47    BackwardRight,
48    BackwardLeft,
49}
50
51/// The directions that a player can sprint in. It's a subset of
52/// [`WalkDirection`].
53#[derive(Clone, Copy, Debug)]
54pub enum SprintDirection {
55    Forward,
56    ForwardRight,
57    ForwardLeft,
58}
59
60impl From<SprintDirection> for WalkDirection {
61    fn from(d: SprintDirection) -> Self {
62        match d {
63            SprintDirection::Forward => WalkDirection::Forward,
64            SprintDirection::ForwardRight => WalkDirection::ForwardRight,
65            SprintDirection::ForwardLeft => WalkDirection::ForwardLeft,
66        }
67    }
68}