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
This commit is contained in:
parent
264bf6084e
commit
4f4533411e
|
@ -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::<protocol::VarInt>::read_from(buf)?);
|
||||
} else {
|
||||
m.put_raw::<Option<protocol::VarInt>>(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<protocol::VarInt>),
|
||||
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<R: io::Read>(buf: &mut R) -> Result<Self, protocol::Error> {
|
||||
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<W: io::Write>(&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<protocol::VarInt> {
|
||||
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::*;
|
||||
|
|
Loading…
Reference in New Issue