From b13fe32f767ea906f0601a940804a88da45e7353 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 19 Sep 2022 21:03:39 -0700 Subject: [PATCH] Only set center chunk when crossing chunk borders, not sections --- src/chunk_pos.rs | 2 +- src/client.rs | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/chunk_pos.rs b/src/chunk_pos.rs index 8926d9e..38f8db0 100644 --- a/src/chunk_pos.rs +++ b/src/chunk_pos.rs @@ -15,7 +15,7 @@ impl ChunkPos { Self { x, z } } - /// Takes an absolute position and returns the chunk position + /// Takes an X and Z position in world space and returns the chunk position /// containing the point. pub fn at(x: f64, z: f64) -> Self { Self::new((x / 16.0).floor() as i32, (z / 16.0).floor() as i32) diff --git a/src/client.rs b/src/client.rs index 6062905..b81b55f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1224,18 +1224,13 @@ impl Client { let center = ChunkPos::at(self.position.x, self.position.z); - // Send the update view position packet if the client changes the chunk section - // they're in. - { - let old_section = self.old_position.map(|n| (n / 16.0).floor() as i32); - let new_section = self.position.map(|n| (n / 16.0).floor() as i32); - - if old_section != new_section { - self.send_packet(SetCenterChunk { - chunk_x: VarInt(new_section.x), - chunk_z: VarInt(new_section.z), - }) - } + // Send the update view position packet if the client changes the chunk they're + // in. + if ChunkPos::at(self.old_position.x, self.old_position.z) != center { + self.send_packet(SetCenterChunk { + chunk_x: VarInt(center.x), + chunk_z: VarInt(center.z), + }); } let dimension = shared.dimension(world.meta.dimension());