From 4562570f92ed593e65e6628d6386161b322c30af Mon Sep 17 00:00:00 2001 From: Snowiiii Date: Sat, 17 Aug 2024 11:26:12 +0200 Subject: [PATCH] Add Clientbound Block update --- .../src/client/login/c_login_success.rs | 2 +- pumpkin-protocol/src/client/play/c_block_update.rs | 11 +++++++++++ pumpkin-protocol/src/client/play/mod.rs | 2 ++ pumpkin-protocol/src/position.rs | 14 +++++++++++++- pumpkin/src/util/vec3.rs | 14 +++++--------- 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 pumpkin-protocol/src/client/play/c_block_update.rs diff --git a/pumpkin-protocol/src/client/login/c_login_success.rs b/pumpkin-protocol/src/client/login/c_login_success.rs index 2493f1ced..4177d1c5a 100644 --- a/pumpkin-protocol/src/client/login/c_login_success.rs +++ b/pumpkin-protocol/src/client/login/c_login_success.rs @@ -29,7 +29,7 @@ impl<'a> CLoginSuccess<'a> { impl<'a> ClientPacket for CLoginSuccess<'a> { fn write(&self, bytebuf: &mut ByteBuffer) { bytebuf.put_uuid(self.uuid); - bytebuf.put_string(&self.username); + bytebuf.put_string(self.username); bytebuf.put_list::(self.properties, |p, v| { p.put_string(&v.name); p.put_string(&v.value); diff --git a/pumpkin-protocol/src/client/play/c_block_update.rs b/pumpkin-protocol/src/client/play/c_block_update.rs new file mode 100644 index 000000000..53548585d --- /dev/null +++ b/pumpkin-protocol/src/client/play/c_block_update.rs @@ -0,0 +1,11 @@ +use pumpkin_macros::packet; +use serde::Serialize; + +use crate::{position::WorldPosition, VarInt}; + +#[derive(Serialize)] +#[packet(0x09)] +pub struct CBlockUpdate { + location: WorldPosition, + block_id: VarInt, +} diff --git a/pumpkin-protocol/src/client/play/mod.rs b/pumpkin-protocol/src/client/play/mod.rs index 1b352d21f..376d329e1 100644 --- a/pumpkin-protocol/src/client/play/mod.rs +++ b/pumpkin-protocol/src/client/play/mod.rs @@ -1,4 +1,5 @@ mod c_actionbar; +mod c_block_update; mod c_center_chunk; mod c_change_difficulty; mod c_chunk_data; @@ -30,6 +31,7 @@ mod c_update_entity_rot; mod player_action; pub use c_actionbar::*; +pub use c_block_update::*; pub use c_center_chunk::*; pub use c_change_difficulty::*; pub use c_chunk_data::*; diff --git a/pumpkin-protocol/src/position.rs b/pumpkin-protocol/src/position.rs index 4ae10833c..976c1267d 100644 --- a/pumpkin-protocol/src/position.rs +++ b/pumpkin-protocol/src/position.rs @@ -1,4 +1,4 @@ -use serde::Deserialize; +use serde::{Deserialize, Serialize}; pub struct WorldPosition { x: i32, @@ -6,6 +6,18 @@ pub struct WorldPosition { z: i32, } +impl Serialize for WorldPosition { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let long = ((self.x as i64 & 0x3FFFFFF) << 38) + | ((self.z as i64 & 0x3FFFFFF) << 12) + | (self.y as i64 & 0xFFF); + serializer.serialize_i64(long) + } +} + impl<'de> Deserialize<'de> for WorldPosition { fn deserialize(deserializer: D) -> Result where diff --git a/pumpkin/src/util/vec3.rs b/pumpkin/src/util/vec3.rs index 0227302c7..96fd970c0 100644 --- a/pumpkin/src/util/vec3.rs +++ b/pumpkin/src/util/vec3.rs @@ -48,21 +48,17 @@ impl Vec3 { z: self.z * z, } } - - pub fn mul(self, scalar: f64) -> Self { - Vec3 { - x: self.x * scalar, - y: self.y * scalar, - z: self.z * scalar, - } - } } impl Mul for Vec3 { type Output = Self; fn mul(self, scalar: f64) -> Self { - self.mul(scalar) + Self { + x: self.x * scalar, + y: self.y * scalar, + z: self.z * scalar, + } } }