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