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