nurtex_protocol/types/
player_command.rs1use nurtex_codec::Buffer;
2use nurtex_codec::types::variable::VarI32;
3
4#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
6pub enum PlayerCommand {
7 LeaveBed,
8 StartSprinting,
9 StopSprinting,
10 StartJumpWithHorse,
11 StopJumpWithHorse,
12 OpenVehicleInventory,
13 StartElytraFlying,
14}
15
16impl Buffer for PlayerCommand {
17 fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
18 let id = i32::read_var(buffer)?;
19
20 Some(match id {
21 0 => Self::LeaveBed,
22 1 => Self::StartSprinting,
23 2 => Self::StopSprinting,
24 3 => Self::StartJumpWithHorse,
25 4 => Self::StopJumpWithHorse,
26 5 => Self::OpenVehicleInventory,
27 6 => Self::StartElytraFlying,
28 _ => return None,
29 })
30 }
31
32 fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
33 let id = match self {
34 Self::LeaveBed => 0,
35 Self::StartSprinting => 1,
36 Self::StopSprinting => 2,
37 Self::StartJumpWithHorse => 3,
38 Self::StopJumpWithHorse => 4,
39 Self::OpenVehicleInventory => 5,
40 Self::StartElytraFlying => 6,
41 };
42
43 id.write_var(buffer)?;
44
45 Ok(())
46 }
47}