azalea_protocol/packets/game/
c_waypoint.rs1use std::io::{self, Cursor, Write};
2
3use azalea_buf::{AzBuf, BufReadError};
4use azalea_core::{color::RgbColor, position::Vec3i};
5use azalea_protocol_macros::ClientboundGamePacket;
6use azalea_registry::identifier::Identifier;
7use uuid::Uuid;
8
9#[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)]
10pub struct ClientboundWaypoint {
11 pub operation: WaypointOperation,
12 pub waypoint: TrackedWaypoint,
13}
14
15#[derive(AzBuf, Clone, Copy, 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 AzBuf 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 fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
52 let style = Identifier::azalea_read(buf)?;
53 let color = Option::<CompactRgbColor>::azalea_read(buf)?;
54 let color = color.map(|c| RgbColor::new(c.r, c.g, c.b));
55
56 Ok(Self { style, color })
57 }
58}
59
60#[derive(AzBuf)]
62struct CompactRgbColor {
63 r: u8,
64 g: u8,
65 b: u8,
66}
67
68#[derive(AzBuf, Clone, Debug, PartialEq)]
69pub enum WaypointData {
70 Empty,
71 Vec3i(Vec3i),
72 Chunk {
73 #[var]
74 x: i32,
75 #[var]
76 z: i32,
77 },
78 Azimuth {
79 angle: f32,
80 },
81}