Only set center chunk when crossing chunk borders, not sections

This commit is contained in:
Ryan 2022-09-19 21:03:39 -07:00
parent d9b7008827
commit b13fe32f76
2 changed files with 8 additions and 13 deletions

View file

@ -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)

View file

@ -1224,18 +1224,13 @@ impl<C: Config> Client<C> {
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());