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