azalea_protocol/packets/game/
s_seen_advancements.rs1use std::io::Cursor;
2
3use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite};
4use azalea_core::resource_location::ResourceLocation;
5use azalea_protocol_macros::ServerboundGamePacket;
6
7use crate::packets::BufReadError;
8
9#[derive(Clone, Debug, ServerboundGamePacket)]
10pub struct ServerboundSeenAdvancements {
11 pub action: Action,
12 pub tab: Option<ResourceLocation>,
13}
14
15#[derive(AzBuf, Clone, Copy, Debug, Eq, PartialEq)]
16pub enum Action {
17 OpenedTab = 0,
18 ClosedScreen = 1,
19}
20
21impl AzaleaRead for ServerboundSeenAdvancements {
22 fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
23 let action = Action::azalea_read(buf)?;
24 let tab = if action == Action::OpenedTab {
25 Some(ResourceLocation::azalea_read(buf)?)
26 } else {
27 None
28 };
29 Ok(Self { action, tab })
30 }
31}
32
33impl AzaleaWrite for ServerboundSeenAdvancements {
34 fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
35 self.action.azalea_write(buf)?;
36 if let Some(tab) = &self.tab {
37 tab.azalea_write(buf)?;
38 }
39 Ok(())
40 }
41}