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