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