steel_protocol/packets/game/s_player_input.rs
1use steel_macros::{ReadFrom, ServerPacket};
2
3/// Player input state sent each tick when input changes.
4///
5/// Bit flags from Java Input.java:
6/// - `FLAG_FORWARD` = 1 (0x01)
7/// - `FLAG_BACKWARD` = 2 (0x02)
8/// - `FLAG_LEFT` = 4 (0x04)
9/// - `FLAG_RIGHT` = 8 (0x08)
10/// - `FLAG_JUMP` = 16 (0x10)
11/// - `FLAG_SHIFT` = 32 (0x20)
12/// - `FLAG_SPRINT` = 64 (0x40)
13#[derive(ReadFrom, ServerPacket, Clone, Debug)]
14pub struct SPlayerInput {
15 pub flags: u8,
16}
17
18impl SPlayerInput {
19 /// Returns true if the forward key is pressed.
20 #[must_use]
21 pub const fn forward(&self) -> bool {
22 (self.flags & 0x01) != 0
23 }
24
25 /// Returns true if the backward key is pressed.
26 #[must_use]
27 pub const fn backward(&self) -> bool {
28 (self.flags & 0x02) != 0
29 }
30
31 /// Returns true if the left strafe key is pressed.
32 #[must_use]
33 pub const fn left(&self) -> bool {
34 (self.flags & 0x04) != 0
35 }
36
37 /// Returns true if the right strafe key is pressed.
38 #[must_use]
39 pub const fn right(&self) -> bool {
40 (self.flags & 0x08) != 0
41 }
42
43 /// Returns true if the jump key is pressed.
44 #[must_use]
45 pub const fn jump(&self) -> bool {
46 (self.flags & 0x10) != 0
47 }
48
49 /// Returns true if the shift (sneak) key is pressed.
50 #[must_use]
51 pub const fn shift(&self) -> bool {
52 (self.flags & 0x20) != 0
53 }
54
55 /// Returns true if the sprint key is pressed.
56 #[must_use]
57 pub const fn sprint(&self) -> bool {
58 (self.flags & 0x40) != 0
59 }
60}