azalea_protocol/packets/game/
c_map_item_data.rs1use std::io::{self, Cursor, Write};
2
3use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite};
4use azalea_chat::FormattedText;
5use azalea_protocol_macros::ClientboundGamePacket;
6
7#[derive(Clone, Debug, ClientboundGamePacket, AzBuf)]
8pub struct ClientboundMapItemData {
9 #[var]
10 pub map_id: u32,
11 pub scale: u8,
12 pub locked: bool,
13 pub decorations: Option<Vec<MapDecoration>>,
14 pub color_patch: OptionalMapPatch,
15}
16
17#[derive(Clone, Debug, AzBuf)]
18pub struct MapDecoration {
19 pub decoration_type: DecorationType,
20 pub x: i8,
21 pub y: i8,
22 pub rot: i8,
25 pub name: Option<FormattedText>,
26}
27
28#[derive(Debug, Clone)]
29pub struct OptionalMapPatch(pub Option<MapPatch>);
30
31impl AzaleaRead for OptionalMapPatch {
32 fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
33 let pos = buf.position();
34 Ok(Self(if u8::azalea_read(buf)? == 0 {
35 None
36 } else {
37 buf.set_position(pos);
38 Some(MapPatch::azalea_read(buf)?)
39 }))
40 }
41}
42
43impl AzaleaWrite for OptionalMapPatch {
44 fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
45 match &self.0 {
46 None => 0u8.azalea_write(buf),
47 Some(m) => m.azalea_write(buf),
48 }
49 }
50}
51
52#[derive(Debug, Clone, AzBuf)]
53pub struct MapPatch {
54 pub width: u8,
55 pub height: u8,
56 pub start_x: u8,
57 pub start_y: u8,
58 pub map_colors: Vec<u8>,
59}
60
61#[derive(Clone, Copy, Debug, AzBuf)]
62pub enum DecorationType {
63 Player,
64 Frame,
65 RedMarker,
66 BlueMarker,
67 TargetX,
68 TargetPoint,
69 PlayerOffMap,
70 PlayerOffLimits,
71 Mansion,
72 Monument,
73 BannerWhite,
74 BannerOrange,
75 BannerMagenta,
76 BannerLightBlue,
77 BannerYellow,
78 BannerLime,
79 BannerPink,
80 BannerGray,
81 BannerLightGray,
82 BannerCyan,
83 BannerPurple,
84 BannerBlue,
85 BannerBrown,
86 BannerGreen,
87 BannerRed,
88 BannerBlack,
89 RedX,
90}