Skip to main content

azalea_protocol/packets/game/
c_waypoint.rs

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