Skip to content

Commit 4f45334

Browse files
committed
1.14 protocol support (477) (#132). Closes #72
Adds 1.14 (477) protocol support, based on: https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14723 * New packets: SetDifficulty, LockDifficulty, UpdateJigsawBlock, UpdateViewPosition, UpdateViewDistance * New metadata: Optional VarInt (17) and Pose (18) * Add new join game variant with view distance, without difficulty * Add new server difficulty variant, with locked boolean * Implement recipe parsing changes, add stonecutting recipe type
1 parent 264bf60 commit 4f45334

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

protocol/src/types/metadata.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ impl Metadata {
322322
}
323323
15 => panic!("TODO: particle"),
324324
16 => m.put_raw(index, VillagerData::read_from(buf)?),
325+
17 => {
326+
if bool::read_from(buf)? {
327+
m.put_raw(index, Option::<protocol::VarInt>::read_from(buf)?);
328+
} else {
329+
m.put_raw::<Option<protocol::VarInt>>(index, None);
330+
}
331+
},
332+
18 => m.put_raw(index, PoseData::read_from(buf)?),
325333
_ => return Err(protocol::Error::Err("unknown metadata type".to_owned())),
326334
}
327335
}
@@ -405,6 +413,14 @@ impl Metadata {
405413
u8::write_to(&16, buf)?;
406414
val.write_to(buf)?;
407415
}
416+
Value::OptionalVarInt(ref val) => {
417+
u8::write_to(&17, buf)?;
418+
val.write_to(buf)?;
419+
}
420+
Value::Pose(ref val) => {
421+
u8::write_to(&18, buf)?;
422+
val.write_to(buf)?;
423+
}
408424
_ => panic!("unexpected metadata"),
409425
}
410426
}
@@ -478,6 +494,8 @@ pub enum Value {
478494
NBTTag(nbt::NamedTag),
479495
Particle(ParticleData),
480496
Villager(VillagerData),
497+
OptionalVarInt(Option<protocol::VarInt>),
498+
Pose(PoseData),
481499
}
482500

483501
#[derive(Debug)]
@@ -639,6 +657,38 @@ impl Serializable for VillagerData {
639657
}
640658
}
641659

660+
#[derive(Debug)]
661+
pub enum PoseData {
662+
Standing,
663+
FallFlying,
664+
Sleeping,
665+
Swimming,
666+
SpinAttack,
667+
Sneaking,
668+
Dying,
669+
}
670+
671+
impl Serializable for PoseData {
672+
fn read_from<R: io::Read>(buf: &mut R) -> Result<Self, protocol::Error> {
673+
let n = protocol::VarInt::read_from(buf)?;
674+
Ok(match n.0 {
675+
0 => PoseData::Standing,
676+
1 => PoseData::FallFlying,
677+
2 => PoseData::Sleeping,
678+
3 => PoseData::Swimming,
679+
4 => PoseData::SpinAttack,
680+
5 => PoseData::Sneaking,
681+
6 => PoseData::Dying,
682+
_ => panic!("unknown pose data: {}", n.0),
683+
})
684+
}
685+
686+
fn write_to<W: io::Write>(&self, _buf: &mut W) -> Result<(), protocol::Error> {
687+
unimplemented!()
688+
}
689+
}
690+
691+
642692

643693
pub trait MetaValue {
644694
fn unwrap(_: &Value) -> &Self;
@@ -862,6 +912,31 @@ impl MetaValue for VillagerData {
862912
}
863913
}
864914

915+
impl MetaValue for Option<protocol::VarInt> {
916+
fn unwrap(value: &Value) -> &Self {
917+
match *value {
918+
Value::OptionalVarInt(ref val) => val,
919+
_ => panic!("incorrect key"),
920+
}
921+
}
922+
fn wrap(self) -> Value {
923+
Value::OptionalVarInt(self)
924+
}
925+
}
926+
927+
impl MetaValue for PoseData {
928+
fn unwrap(value: &Value) -> &Self {
929+
match *value {
930+
Value::Pose(ref val) => val,
931+
_ => panic!("incorrect key"),
932+
}
933+
}
934+
fn wrap(self) -> Value {
935+
Value::Pose(self)
936+
}
937+
}
938+
939+
865940
#[cfg(test)]
866941
mod test {
867942
use super::*;

0 commit comments

Comments
 (0)