From c85216242ec1cc714fb7d30a9107026a399aa8e5 Mon Sep 17 00:00:00 2001 From: Alvsch <94403567+Alvsch@users.noreply.github.com> Date: Sat, 19 Oct 2024 14:49:05 +0200 Subject: [PATCH] Fixed cylindrical --- .../src/cylindrical_chunk_iterator.rs | 38 +++++++++---------- pumpkin/src/entity/mod.rs | 7 ++-- pumpkin/src/world/player_chunker.rs | 4 +- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/pumpkin-world/src/cylindrical_chunk_iterator.rs b/pumpkin-world/src/cylindrical_chunk_iterator.rs index bb7ca9bf3..185505d28 100644 --- a/pumpkin-world/src/cylindrical_chunk_iterator.rs +++ b/pumpkin-world/src/cylindrical_chunk_iterator.rs @@ -19,7 +19,7 @@ impl Cylindrical { old_cylindrical: Cylindrical, new_cylindrical: Cylindrical, mut newly_included: impl FnMut(Vector2), - just_removed: impl FnMut(Vector2), + mut just_removed: impl FnMut(Vector2), ignore: bool, ) { let min_x = old_cylindrical.left().min(new_cylindrical.left()); @@ -29,26 +29,24 @@ impl Cylindrical { for x in min_x..=max_x { for z in min_z..=max_z { - // TODO - // let old_is_within = if ignore { - // false - // } else { - // old_cylindrical.is_within_distance(x, z) - // }; - // let new_is_within = if ignore { - // true - // } else { - // new_cylindrical.is_within_distance(x, z) - // }; + let old_is_within = if ignore { + false + } else { + old_cylindrical.is_within_distance(x, z) + }; + let new_is_within = if ignore { + true + } else { + new_cylindrical.is_within_distance(x, z) + }; - // if old_is_within != new_is_within { - // if new_is_within { - newly_included(Vector2::new(x, z)); - // } else { - // dbg!("aa"); - // just_removed(Vector2::new(x, z)); - // } - // } + if old_is_within != new_is_within { + if new_is_within { + newly_included(Vector2::new(x, z)); + } else { + just_removed(Vector2::new(x, z)); + } + } } } } diff --git a/pumpkin/src/entity/mod.rs b/pumpkin/src/entity/mod.rs index 1deb672cd..d2d0447af 100644 --- a/pumpkin/src/entity/mod.rs +++ b/pumpkin/src/entity/mod.rs @@ -101,13 +101,14 @@ impl Entity { let block_pos = self.block_pos.load(); let block_pos_vec = block_pos.0; if i != block_pos_vec.x || j != block_pos_vec.y || k != block_pos_vec.z { - self.block_pos.store(WorldPosition(Vector3::new(i, j, k))); + let new_block_pos = Vector3::new(i, j, k); + self.block_pos.store(WorldPosition(new_block_pos)); let chunk_pos = self.chunk_pos.load(); if get_section_cord(i) != chunk_pos.x || get_section_cord(k) != chunk_pos.z { self.chunk_pos.store(Vector2::new( - get_section_cord(block_pos_vec.x), - get_section_cord(block_pos_vec.z), + get_section_cord(new_block_pos.x), + get_section_cord(new_block_pos.z), )); } } diff --git a/pumpkin/src/world/player_chunker.rs b/pumpkin/src/world/player_chunker.rs index fc61a70c8..9f443f7aa 100644 --- a/pumpkin/src/world/player_chunker.rs +++ b/pumpkin/src/world/player_chunker.rs @@ -79,8 +79,10 @@ pub async fn update_position(entity: &Entity, player: &Player) { view_distance, ); let new_cylindrical = - Cylindrical::new(Vector2::new(chunk_pos.x, chunk_pos.z), view_distance); + Cylindrical::new(chunk_pos, view_distance); + player.watched_section.store(new_watched); + let mut loading_chunks = Vec::new(); Cylindrical::for_each_changed_chunk( old_cylindrical,