Skip to main content

nurtex_protocol/types/
interact_type.rs

1use std::io::{self, Cursor, Write};
2
3use nurtex_codec::{Buffer, VarInt};
4
5/// Тип взаимодействия
6#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
7pub enum InteractType {
8  Interact,
9  Attack,
10  InteractAt,
11}
12
13impl Buffer for InteractType {
14  fn read_buf(buffer: &mut Cursor<&[u8]>) -> Option<Self> {
15    let id = i32::read_varint(buffer)?;
16
17    Some(match id {
18      0 => Self::Interact,
19      1 => Self::Attack,
20      2 => Self::InteractAt,
21      _ => return None,
22    })
23  }
24
25  fn write_buf(&self, buffer: &mut impl Write) -> io::Result<()> {
26    let id = match self {
27      Self::Interact => 0,
28      Self::Attack => 1,
29      Self::InteractAt => 2,
30    };
31
32    id.write_varint(buffer)?;
33
34    Ok(())
35  }
36}