Skip to content

Commit

Permalink
add unload chunks too
Browse files Browse the repository at this point in the history
  • Loading branch information
kralverde committed Oct 19, 2024
1 parent 224242c commit 637104c
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion pumpkin/src/world/player_chunker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pumpkin_config::BASIC_CONFIG;
use pumpkin_core::math::{
get_section_cord, position::WorldPosition, vector2::Vector2, vector3::Vector3,
};
use pumpkin_protocol::client::play::CCenterChunk;
use pumpkin_protocol::client::play::{CCenterChunk, CUnloadChunk};
use pumpkin_world::cylindrical_chunk_iterator::Cylindrical;

use crate::entity::player::Player;
Expand Down Expand Up @@ -64,6 +64,18 @@ pub async fn player_join(world: &World, player: Arc<Player>) {

if !unloading_chunks.is_empty() {
world.mark_chunks_as_not_watched(&unloading_chunks).await;
for chunk in unloading_chunks {
if !player
.client
.closed
.load(std::sync::atomic::Ordering::Relaxed)
{
player
.client
.send_packet(&CUnloadChunk::new(chunk.x, chunk.z))
.await;
}
}
}
}

Expand Down Expand Up @@ -119,6 +131,18 @@ pub async fn update_position(player: &Player) {
.world
.mark_chunks_as_not_watched(&unloading_chunks)
.await;
for chunk in unloading_chunks {
if !player
.client
.closed
.load(std::sync::atomic::Ordering::Relaxed)
{
player
.client
.send_packet(&CUnloadChunk::new(chunk.x, chunk.z))
.await;
}
}
}
}
}
Expand Down

0 comments on commit 637104c

Please sign in to comment.