diff options
Diffstat (limited to 'src/v1_15_2.rs')
-rw-r--r-- | src/v1_15_2.rs | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/v1_15_2.rs b/src/v1_15_2.rs index 0f5689f..1eb5f8a 100644 --- a/src/v1_15_2.rs +++ b/src/v1_15_2.rs @@ -731,7 +731,9 @@ define_protocol!(Packet578, PacketDirection, State, i32, Id => { PlayResourcePackStatus, 0x1F, Play, ServerBound => PlayResourcePackStatusSpec { status: ResourcePackStatus }, - // todo advancement tab + PlayAdvancementTab, 0x20, Play, ServerBound => PlayAdvancementTabSpec { + action: AdvancementTabAction + }, PlaySelectTrade, 0x21, Play, ServerBound => PlaySelectTradeSpec { selected_slot: VarInt }, @@ -2735,6 +2737,54 @@ proto_varint_enum!(ResourcePackStatus, 0x03 :: Accepted ); +#[derive(Clone, PartialEq, Debug)] +pub enum AdvancementTabAction { + Opened(String), + Closed +} + +impl Serialize for AdvancementTabAction { + fn mc_serialize<S: Serializer>(&self, to: &mut S) -> SerializeResult { + use AdvancementTabAction::*; + + to.serialize_other(&VarInt(match self { + Opened(_) => 0x00, + Closed => 0x01 + }))?; + + match self { + Opened(identifier) => to.serialize_other(identifier), + _ => Ok(()) + } + } +} + +impl Deserialize for AdvancementTabAction { + fn mc_deserialize(data: &[u8]) -> DeserializeResult<'_, Self> { + use AdvancementTabAction::*; + + let Deserialized { value: action_id, data } = VarInt::mc_deserialize(data)?; + match action_id.0 { + 0x00 => Ok(String::mc_deserialize(data)?.map(move |id| Opened(id))), + 0x01 => Deserialized::ok(Closed, data), + other => Err(DeserializeErr::CannotUnderstandValue(format!("bad advancement tab action id {}", other))) + } + } +} + +#[cfg(test)] +impl TestRandom for AdvancementTabAction { + fn test_gen_random() -> Self { + use AdvancementTabAction::*; + + if rand::random::<bool>() { + Opened(String::test_gen_random()) + } else { + Closed + } + } +} + proto_varint_enum!(CommandBlockMode, 0x00 :: Sequence, 0x01 :: Auto, @@ -4616,6 +4666,15 @@ pub mod tests { packet_test_cases!( Packet578, + PlayAdvancementTab, + PlayAdvancementTabSpec, + test_play_advancement_tab, + bench_write_play_advancement_tab, + bench_read_play_advancement_tab + ); + + packet_test_cases!( + Packet578, PlaySelectTrade, PlaySelectTradeSpec, test_play_select_trade, |