aboutsummaryrefslogtreecommitdiff
path: root/azalea-physics/src/local_player.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-08-14 20:40:13 -0500
committerGitHub <noreply@github.com>2025-08-14 20:40:13 -0500
commite74ed047dbaf3877db4a89a2d589e992abd0bb11 (patch)
tree0a728c8be167a1d59a5492ed9df666f41cf12e57 /azalea-physics/src/local_player.rs
parent6695132ddb31780786c67b8b9ff5df8ab3891438 (diff)
downloadazalea-drasl-e74ed047dbaf3877db4a89a2d589e992abd0bb11.tar.xz
Sneaking (#237)
* start implementing sneaking * fix horizontal_collision being inverted and cleanup * clippy * change dimensions and eye height based on pose * proper support for automatically crouching in certain cases * fix anticheat issues * add line to changelog and update a comment
Diffstat (limited to 'azalea-physics/src/local_player.rs')
-rw-r--r--azalea-physics/src/local_player.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/azalea-physics/src/local_player.rs b/azalea-physics/src/local_player.rs
new file mode 100644
index 00000000..6ce196b6
--- /dev/null
+++ b/azalea-physics/src/local_player.rs
@@ -0,0 +1,67 @@
+use azalea_core::position::Vec2;
+use bevy_ecs::component::Component;
+
+/// Component for entities that can move and sprint. Usually only in
+/// [`LocalEntity`]s.
+///
+/// [`LocalEntity`]: azalea_entity::LocalEntity
+#[derive(Default, Component, Clone)]
+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`] or [`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, PartialEq, Eq)]
+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,
+ }
+ }
+}