diff --git a/protocol/src/types/metadata.rs b/protocol/src/types/metadata.rs index cb390ff..e27e043 100644 --- a/protocol/src/types/metadata.rs +++ b/protocol/src/types/metadata.rs @@ -322,6 +322,14 @@ impl Metadata { } 15 => panic!("TODO: particle"), 16 => m.put_raw(index, VillagerData::read_from(buf)?), + 17 => { + if bool::read_from(buf)? { + m.put_raw(index, Option::::read_from(buf)?); + } else { + m.put_raw::>(index, None); + } + }, + 18 => m.put_raw(index, PoseData::read_from(buf)?), _ => return Err(protocol::Error::Err("unknown metadata type".to_owned())), } } @@ -405,6 +413,14 @@ impl Metadata { u8::write_to(&16, buf)?; val.write_to(buf)?; } + Value::OptionalVarInt(ref val) => { + u8::write_to(&17, buf)?; + val.write_to(buf)?; + } + Value::Pose(ref val) => { + u8::write_to(&18, buf)?; + val.write_to(buf)?; + } _ => panic!("unexpected metadata"), } } @@ -478,6 +494,8 @@ pub enum Value { NBTTag(nbt::NamedTag), Particle(ParticleData), Villager(VillagerData), + OptionalVarInt(Option), + Pose(PoseData), } #[derive(Debug)] @@ -639,6 +657,38 @@ impl Serializable for VillagerData { } } +#[derive(Debug)] +pub enum PoseData { + Standing, + FallFlying, + Sleeping, + Swimming, + SpinAttack, + Sneaking, + Dying, +} + +impl Serializable for PoseData { + fn read_from(buf: &mut R) -> Result { + let n = protocol::VarInt::read_from(buf)?; + Ok(match n.0 { + 0 => PoseData::Standing, + 1 => PoseData::FallFlying, + 2 => PoseData::Sleeping, + 3 => PoseData::Swimming, + 4 => PoseData::SpinAttack, + 5 => PoseData::Sneaking, + 6 => PoseData::Dying, + _ => panic!("unknown pose data: {}", n.0), + }) + } + + fn write_to(&self, _buf: &mut W) -> Result<(), protocol::Error> { + unimplemented!() + } +} + + pub trait MetaValue { fn unwrap(_: &Value) -> &Self; @@ -862,6 +912,31 @@ impl MetaValue for VillagerData { } } +impl MetaValue for Option { + fn unwrap(value: &Value) -> &Self { + match *value { + Value::OptionalVarInt(ref val) => val, + _ => panic!("incorrect key"), + } + } + fn wrap(self) -> Value { + Value::OptionalVarInt(self) + } +} + +impl MetaValue for PoseData { + fn unwrap(value: &Value) -> &Self { + match *value { + Value::Pose(ref val) => val, + _ => panic!("incorrect key"), + } + } + fn wrap(self) -> Value { + Value::Pose(self) + } +} + + #[cfg(test)] mod test { use super::*;