From 264bf6084e20cd9a753aba2973cdcee80993eed7 Mon Sep 17 00:00:00 2001 From: iceiix <43691553+iceiix@users.noreply.github.com> Date: Thu, 10 Jan 2019 17:21:19 -0800 Subject: [PATCH] Add 18w50a (451) multiprotocol support (#79) Adds 18w50a (451) multiprotocol support, last snapshot of 2018 Reference: https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14491 * Use v18w50a module for protocol * Add blasting, smoking, and suspicious stew recipe types * Add entity tags to tags packet * Add chunk data packet variant with height map * Add update light packet * Add chunk format parsing with block_count, without skylights, conditionalize on protocol_version >= 451 * Add villager data entity metadata type parsing https://wiki.vg/Pre-release_protocol#Entity_Metadata * Add open book and entity sound effect packets --- protocol/src/types/metadata.rs | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/protocol/src/types/metadata.rs b/protocol/src/types/metadata.rs index a5e8a3e..cb390ff 100644 --- a/protocol/src/types/metadata.rs +++ b/protocol/src/types/metadata.rs @@ -321,6 +321,7 @@ impl Metadata { } } 15 => panic!("TODO: particle"), + 16 => m.put_raw(index, VillagerData::read_from(buf)?), _ => return Err(protocol::Error::Err("unknown metadata type".to_owned())), } } @@ -400,6 +401,10 @@ impl Metadata { u8::write_to(&15, buf)?; val.write_to(buf)?; } + Value::Villager(ref val) => { + u8::write_to(&16, buf)?; + val.write_to(buf)?; + } _ => panic!("unexpected metadata"), } } @@ -472,6 +477,7 @@ pub enum Value { Block(u16), // TODO: Proper type NBTTag(nbt::NamedTag), Particle(ParticleData), + Villager(VillagerData), } #[derive(Debug)] @@ -613,6 +619,27 @@ impl Serializable for ParticleData { } } +#[derive(Debug)] +pub struct VillagerData { + villager_type: protocol::VarInt, + profession: protocol::VarInt, + level: protocol::VarInt, +} + +impl Serializable for VillagerData { + fn read_from(buf: &mut R) -> Result { + let villager_type = protocol::VarInt::read_from(buf)?; + let profession = protocol::VarInt::read_from(buf)?; + let level = protocol::VarInt::read_from(buf)?; + Ok(VillagerData { villager_type, profession, level }) + } + + fn write_to(&self, _buf: &mut W) -> Result<(), protocol::Error> { + unimplemented!() + } +} + + pub trait MetaValue { fn unwrap(_: &Value) -> &Self; fn wrap(self) -> Value; @@ -823,6 +850,18 @@ impl MetaValue for nbt::NamedTag { } } +impl MetaValue for VillagerData { + fn unwrap(value: &Value) -> &Self { + match *value { + Value::Villager(ref val) => val, + _ => panic!("incorrect key"), + } + } + fn wrap(self) -> Value { + Value::Villager(self) + } +} + #[cfg(test)] mod test { use super::*;