azalea_protocol/packets/game/
s_player_input.rs1use std::io::Cursor;
2
3use azalea_buf::BufReadError;
4use azalea_buf::{AzaleaRead, AzaleaWrite};
5use azalea_core::bitset::FixedBitSet;
6use azalea_protocol_macros::ServerboundGamePacket;
7
8#[derive(Clone, Debug, Default, PartialEq, Eq, ServerboundGamePacket)]
9pub struct ServerboundPlayerInput {
10 pub forward: bool,
11 pub backward: bool,
12 pub left: bool,
13 pub right: bool,
14 pub jump: bool,
15 pub shift: bool,
16 pub sprint: bool,
17}
18
19impl AzaleaRead for ServerboundPlayerInput {
20 fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
21 let set = FixedBitSet::<{ 7_usize.div_ceil(8) }>::azalea_read(buf)?;
22 Ok(Self {
23 forward: set.index(0),
24 backward: set.index(1),
25 left: set.index(2),
26 right: set.index(3),
27 jump: set.index(4),
28 shift: set.index(5),
29 sprint: set.index(6),
30 })
31 }
32}
33
34impl AzaleaWrite for ServerboundPlayerInput {
35 fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
36 let mut set = FixedBitSet::<{ 7_usize.div_ceil(8) }>::new();
37 if self.forward {
38 set.set(0);
39 }
40 if self.backward {
41 set.set(1);
42 }
43 if self.left {
44 set.set(2);
45 }
46 if self.right {
47 set.set(3);
48 }
49 if self.jump {
50 set.set(4);
51 }
52 if self.shift {
53 set.set(5);
54 }
55 if self.sprint {
56 set.set(6);
57 }
58 set.azalea_write(buf)
59 }
60}