azalea_protocol/packets/game/
c_waypoint.rs

1use std::io::{self, Cursor, Write};
2
3use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
4use azalea_core::{color::RgbColor, position::Vec3i};
5use azalea_protocol_macros::ClientboundGamePacket;
6use azalea_registry::identifier::Identifier;
7use uuid::Uuid;
8
9#[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)]
10pub struct ClientboundWaypoint {
11    pub operation: WaypointOperation,
12    pub waypoint: TrackedWaypoint,
13}
14
15#[derive(AzBuf, Copy, Clone, Debug, PartialEq)]
16pub enum WaypointOperation {
17    Track,
18    Untrack,
19    Update,
20}
21
22#[derive(AzBuf, Clone, Debug, PartialEq)]
23pub struct TrackedWaypoint {
24    pub identifier: WaypointIdentifier,
25    pub icon: WaypointIcon,
26    pub data: WaypointData,
27}
28
29#[derive(AzBuf, Clone, Debug, PartialEq)]
30pub enum WaypointIdentifier {
31    String(String),
32    Uuid(Uuid),
33}
34
35#[derive(Clone, Debug, PartialEq)]
36pub struct WaypointIcon {
37    pub style: Identifier,
38    pub color: Option<RgbColor>,
39}
40impl AzaleaWrite for WaypointIcon {
41    fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
42        self.style.azalea_write(buf)?;
43        let color = self.color.map(|c| CompactRgbColor {
44            r: c.red(),
45            g: c.green(),
46            b: c.blue(),
47        });
48        color.azalea_write(buf)?;
49        Ok(())
50    }
51}
52impl AzaleaRead for WaypointIcon {
53    fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
54        let style = Identifier::azalea_read(buf)?;
55        let color = Option::<CompactRgbColor>::azalea_read(buf)?;
56        let color = color.map(|c| RgbColor::new(c.r, c.g, c.b));
57
58        Ok(Self { style, color })
59    }
60}
61
62// usually RgbColor is encoded as 4 bytes, except here where it's 3
63#[derive(AzBuf)]
64struct CompactRgbColor {
65    r: u8,
66    g: u8,
67    b: u8,
68}
69
70#[derive(AzBuf, Clone, Debug, PartialEq)]
71pub enum WaypointData {
72    Empty,
73    Vec3i(Vec3i),
74    Chunk {
75        #[var]
76        x: i32,
77        #[var]
78        z: i32,
79    },
80    Azimuth {
81        angle: f32,
82    },
83}