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
|
use std::io::{self, Cursor, Write};
use azalea_buf::AzBuf;
use azalea_protocol_macros::ServerboundGamePacket;
use azalea_registry::identifier::Identifier;
use crate::packets::BufReadError;
#[derive(Clone, Debug, PartialEq, ServerboundGamePacket)]
pub struct ServerboundSeenAdvancements {
pub action: Action,
pub tab: Option<Identifier>,
}
#[derive(AzBuf, Clone, Copy, Debug, Eq, PartialEq)]
pub enum Action {
OpenedTab = 0,
ClosedScreen = 1,
}
impl AzBuf for ServerboundSeenAdvancements {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let action = Action::azalea_read(buf)?;
let tab = if action == Action::OpenedTab {
Some(Identifier::azalea_read(buf)?)
} else {
None
};
Ok(Self { action, tab })
}
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
self.action.azalea_write(buf)?;
if let Some(tab) = &self.tab {
tab.azalea_write(buf)?;
}
Ok(())
}
}
|