Skip to main content

nurtex_protocol/types/
player_hand.rs

1use std::io::{self, Cursor, Write};
2
3use nurtex_codec::{Buffer, VarInt};
4
5/// Точная рука игрока (левая / правая)
6#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
7pub enum AccurateHand {
8  Left,
9  Right,
10}
11
12impl Buffer for AccurateHand {
13  fn read_buf(buffer: &mut Cursor<&[u8]>) -> Option<Self> {
14    let id = i32::read_varint(buffer)?;
15
16    match id {
17      0 => Some(Self::Left),
18      1 => Some(Self::Right),
19      _ => None,
20    }
21  }
22
23  fn write_buf(&self, buffer: &mut impl Write) -> io::Result<()> {
24    let id = match self {
25      Self::Left => 0,
26      Self::Right => 1,
27    };
28
29    id.write_varint(buffer)?;
30
31    Ok(())
32  }
33}
34
35/// Относительная рука игрока
36#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
37pub enum RelativeHand {
38  MainHand,
39  OffHand,
40}
41
42impl Buffer for RelativeHand {
43  fn read_buf(buffer: &mut Cursor<&[u8]>) -> Option<Self> {
44    let id = i32::read_varint(buffer)?;
45
46    match id {
47      0 => Some(Self::MainHand),
48      1 => Some(Self::OffHand),
49      _ => None,
50    }
51  }
52
53  fn write_buf(&self, buffer: &mut impl Write) -> io::Result<()> {
54    let id = match self {
55      Self::MainHand => 0,
56      Self::OffHand => 1,
57    };
58
59    id.write_varint(buffer)?;
60
61    Ok(())
62  }
63}