Skip to content

Commit

Permalink
Add Clientbound Block update
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Aug 17, 2024
1 parent 40fe403 commit 4562570
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/login/c_login_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Property>(self.properties, |p, v| {
p.put_string(&v.name);
p.put_string(&v.value);
Expand Down
11 changes: 11 additions & 0 deletions pumpkin-protocol/src/client/play/c_block_update.rs
Original file line number Diff line number Diff line change
@@ -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,
}
2 changes: 2 additions & 0 deletions pumpkin-protocol/src/client/play/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod c_actionbar;
mod c_block_update;
mod c_center_chunk;
mod c_change_difficulty;
mod c_chunk_data;
Expand Down Expand Up @@ -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::*;
Expand Down
14 changes: 13 additions & 1 deletion pumpkin-protocol/src/position.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use serde::Deserialize;
use serde::{Deserialize, Serialize};

pub struct WorldPosition {
x: i32,
y: i32,
z: i32,
}

impl Serialize for WorldPosition {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down
14 changes: 5 additions & 9 deletions pumpkin/src/util/vec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64> 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,
}
}
}

Expand Down

0 comments on commit 4562570

Please sign in to comment.