azalea_protocol/packets/game/
c_map_item_data.rs

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