52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
#[allow(clippy::wildcard_imports)]
|
|
use super::*;
|
|
|
|
impl BedrockClient {
|
|
pub async fn handle_request_chunk_radius(
|
|
&self,
|
|
player: &Arc<Player>,
|
|
packet: SRequestChunkRadius,
|
|
) {
|
|
let chunk_radius = packet.chunk_radius;
|
|
if chunk_radius.0 < 1 {
|
|
self.kick(
|
|
DisconnectReason::Kicked,
|
|
"Cannot have zero or negative view distance!".to_string(),
|
|
)
|
|
.await;
|
|
return;
|
|
}
|
|
let Some(server) = player.world().server.upgrade() else {
|
|
return;
|
|
};
|
|
|
|
let view_distance = chunk_radius.clamp(
|
|
2,
|
|
NonZeroI32::from(server.advanced_config.networking.bedrock.view_distance).get(),
|
|
);
|
|
|
|
self.enqueue_packet(&CChunkRadiusUpdate {
|
|
chunk_radius: VarInt(view_distance),
|
|
})
|
|
.await;
|
|
|
|
let old_view_distance = {
|
|
let current_config = player.config.load();
|
|
let old_vd = current_config.view_distance;
|
|
let mut new_config = (**current_config).clone();
|
|
|
|
new_config.view_distance =
|
|
NonZero::new(view_distance as u8).unwrap_or(NonZero::<u8>::MIN);
|
|
player.config.store(std::sync::Arc::new(new_config));
|
|
|
|
old_vd
|
|
};
|
|
|
|
debug!(
|
|
"Player {} updated their render distance: {} -> {}.",
|
|
player.gameprofile.name, old_view_distance, view_distance
|
|
);
|
|
chunker::update_position(player).await;
|
|
}
|
|
}
|