Add WorldPosition struct for packets
Add WorldPosition struct that deserialises according to: https://wiki.vg/Data_types#Type:Position
This commit is contained in:
parent
03f9b377d5
commit
cce0161e3d
@ -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;
|
||||
|
||||
|
||||
31
pumpkin-protocol/src/position.rs
Normal file
31
pumpkin-protocol/src/position.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
pub struct WorldPosition {
|
||||
x: i32,
|
||||
y: i32,
|
||||
z: i32
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for WorldPosition {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
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<E>(self, v: i64) -> Result<Self::Value, E>
|
||||
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)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user