Skip to content

Commit 264bf60

Browse files
authored
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
1 parent 6844132 commit 264bf60

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

protocol/src/types/metadata.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ impl Metadata {
321321
}
322322
}
323323
15 => panic!("TODO: particle"),
324+
16 => m.put_raw(index, VillagerData::read_from(buf)?),
324325
_ => return Err(protocol::Error::Err("unknown metadata type".to_owned())),
325326
}
326327
}
@@ -400,6 +401,10 @@ impl Metadata {
400401
u8::write_to(&15, buf)?;
401402
val.write_to(buf)?;
402403
}
404+
Value::Villager(ref val) => {
405+
u8::write_to(&16, buf)?;
406+
val.write_to(buf)?;
407+
}
403408
_ => panic!("unexpected metadata"),
404409
}
405410
}
@@ -472,6 +477,7 @@ pub enum Value {
472477
Block(u16), // TODO: Proper type
473478
NBTTag(nbt::NamedTag),
474479
Particle(ParticleData),
480+
Villager(VillagerData),
475481
}
476482

477483
#[derive(Debug)]
@@ -613,6 +619,27 @@ impl Serializable for ParticleData {
613619
}
614620
}
615621

622+
#[derive(Debug)]
623+
pub struct VillagerData {
624+
villager_type: protocol::VarInt,
625+
profession: protocol::VarInt,
626+
level: protocol::VarInt,
627+
}
628+
629+
impl Serializable for VillagerData {
630+
fn read_from<R: io::Read>(buf: &mut R) -> Result<Self, protocol::Error> {
631+
let villager_type = protocol::VarInt::read_from(buf)?;
632+
let profession = protocol::VarInt::read_from(buf)?;
633+
let level = protocol::VarInt::read_from(buf)?;
634+
Ok(VillagerData { villager_type, profession, level })
635+
}
636+
637+
fn write_to<W: io::Write>(&self, _buf: &mut W) -> Result<(), protocol::Error> {
638+
unimplemented!()
639+
}
640+
}
641+
642+
616643
pub trait MetaValue {
617644
fn unwrap(_: &Value) -> &Self;
618645
fn wrap(self) -> Value;
@@ -823,6 +850,18 @@ impl MetaValue for nbt::NamedTag {
823850
}
824851
}
825852

853+
impl MetaValue for VillagerData {
854+
fn unwrap(value: &Value) -> &Self {
855+
match *value {
856+
Value::Villager(ref val) => val,
857+
_ => panic!("incorrect key"),
858+
}
859+
}
860+
fn wrap(self) -> Value {
861+
Value::Villager(self)
862+
}
863+
}
864+
826865
#[cfg(test)]
827866
mod test {
828867
use super::*;

0 commit comments

Comments
 (0)