aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Sacchini <joey@sacchini.net>2020-10-09 23:47:00 -0400
committerJoey Sacchini <joey@sacchini.net>2020-10-09 23:47:00 -0400
commit811ab9dc56eda1535f326630fb04e1fb0e055574 (patch)
tree60083cca5ad1c9d82346a96d7cfda06c5e06a7ad /src
parent3070c8b2c86138e408b9b29eb6d26f35c19a9a59 (diff)
downloadmcproto-rs-811ab9dc56eda1535f326630fb04e1fb0e055574.tar.gz
mcproto-rs-811ab9dc56eda1535f326630fb04e1fb0e055574.tar.bz2
mcproto-rs-811ab9dc56eda1535f326630fb04e1fb0e055574.zip
Implement server-bound advancement tab packet
Diffstat (limited to 'src')
-rw-r--r--src/v1_15_2.rs61
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,