diff --git a/pumpkin-protocol/src/lib.rs b/pumpkin-protocol/src/lib.rs index b46e0f248..24a58c168 100644 --- a/pumpkin-protocol/src/lib.rs +++ b/pumpkin-protocol/src/lib.rs @@ -1,17 +1,19 @@ -use std::io::{self, Write}; +#![feature(test)] +extern crate test; use bytebuf::{packet_id::Packet, ByteBuffer, DeserializerError}; use bytes::Buf; use serde::{Deserialize, Serialize, Serializer}; +use std::io::{self, Write}; use thiserror::Error; pub mod bytebuf; pub mod client; -pub mod server; -pub mod uuid; - pub mod packet_decoder; pub mod packet_encoder; +pub mod server; +pub mod uuid; +pub mod position; pub const CURRENT_MC_PROTOCOL: u32 = 767; diff --git a/pumpkin-protocol/src/position.rs b/pumpkin-protocol/src/position.rs new file mode 100644 index 000000000..afaaf6adc --- /dev/null +++ b/pumpkin-protocol/src/position.rs @@ -0,0 +1,31 @@ +use serde::Deserialize; + +pub struct WorldPosition { + x: i32, + y: i32, + z: i32 +} + +impl<'de> Deserialize<'de> for WorldPosition { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de> { + struct Visitor; + impl<'a> serde::de::Visitor<'a> for Visitor { + type Value = WorldPosition; + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("An i64 int") + } + fn visit_i64(self, v: i64) -> Result + where + E: serde::de::Error, { + Ok(WorldPosition { + x: (v >> 38) as i32, + y: (v << 52 >> 52) as i32, + z: (v << 26 >> 38) as i32 + }) + } + } + deserializer.deserialize_i64(Visitor) + } +} \ No newline at end of file