Smaller fixes

This commit is contained in:
Alexander Medvedev committed 2025-07-31 10:29:41 +02:00
1 parent fab33370b5
commit 7468f2cf76
4 files changed
+4 -34

No files matched your search

+1 -5
View File
@@ -23,13 +23,9 @@ pub fn wrap_degrees(degrees: f32) -> f32 {
var1 var1
} }
pub fn clamp(value: f32, min: f32, max: f32) -> f32 {
if value < min { min } else { value.min(max) }
}
pub fn clamp_angle(value: f32, mean: f32, delta: f32) -> f32 { pub fn clamp_angle(value: f32, mean: f32, delta: f32) -> f32 {
let i = subtract_angles(value, mean); let i = subtract_angles(value, mean);
let j = clamp(i, -delta, delta); let j = i.clamp(-delta, delta);
mean - j mean - j
} }
-25
View File
@@ -55,9 +55,6 @@ pub struct Level {
block_registry: Arc<dyn BlockRegistryExt>, block_registry: Arc<dyn BlockRegistryExt>,
level_folder: LevelFolder, level_folder: LevelFolder,
// Holds this level's spawn chunks, which are always loaded
spawn_chunks: Arc<DashMap<Vector2<i32>, SyncChunk>>,
/// Counts the number of ticks that have been scheduled for this world /// Counts the number of ticks that have been scheduled for this world
schedule_tick_counts: AtomicU64, schedule_tick_counts: AtomicU64,
@@ -151,7 +148,6 @@ impl Level {
chunk_saver, chunk_saver,
entity_saver, entity_saver,
schedule_tick_counts: AtomicU64::new(0), schedule_tick_counts: AtomicU64::new(0),
spawn_chunks: Arc::new(DashMap::new()),
loaded_chunks: Arc::new(DashMap::new()), loaded_chunks: Arc::new(DashMap::new()),
loaded_entity_chunks: Arc::new(DashMap::new()), loaded_entity_chunks: Arc::new(DashMap::new()),
chunk_watchers: Arc::new(DashMap::new()), chunk_watchers: Arc::new(DashMap::new()),
@@ -667,22 +663,6 @@ impl Level {
} }
} }
/// Initializes the spawn chunks to these chunks
pub async fn read_spawn_chunks(self: &Arc<Self>, chunks: &[Vector2<i32>]) {
let (send, mut recv) = mpsc::unbounded_channel();
let fetcher = self.fetch_chunks(chunks, send);
let handler = async {
while let Some((chunk, _)) = recv.recv().await {
let pos = chunk.read().await.position;
self.spawn_chunks.insert(pos, chunk);
}
};
let _ = tokio::join!(fetcher, handler);
log::debug!("Read {} chunks as spawn chunks", chunks.len());
}
/// Reads/Generates many chunks in a world /// Reads/Generates many chunks in a world
/// Note: The order of the output chunks will almost never be in the same order as the order of input chunks /// Note: The order of the output chunks will almost never be in the same order as the order of input chunks
pub async fn fetch_chunks( pub async fn fetch_chunks(
@@ -708,11 +688,6 @@ impl Level {
for chunk in chunks { for chunk in chunks {
let is_ok = if let Some(chunk) = self.loaded_chunks.get(chunk) { let is_ok = if let Some(chunk) = self.loaded_chunks.get(chunk) {
send_chunk(false, chunk.value().clone(), &channel) send_chunk(false, chunk.value().clone(), &channel)
} else if let Some(spawn_chunk) = self.spawn_chunks.get(chunk) {
// Also clone the arc into the loaded chunks
self.loaded_chunks
.insert(*chunk, spawn_chunk.value().clone());
send_chunk(false, spawn_chunk.value().clone(), &channel)
} else { } else {
remaining_chunks.push(*chunk); remaining_chunks.push(*chunk);
true true
+2 -2
View File
@@ -1,11 +1,11 @@
use pumpkin_util::math::{clamp, subtract_angles}; use pumpkin_util::math::subtract_angles;
pub mod look_control; pub mod look_control;
pub trait Control: Send + Sync { pub trait Control: Send + Sync {
fn change_angle(&self, start: f32, end: f32, max_change: f32) -> f32 { fn change_angle(&self, start: f32, end: f32, max_change: f32) -> f32 {
let i = subtract_angles(start, end); let i = subtract_angles(start, end);
let j = clamp(i, -max_change, max_change); let j = i.clamp(-max_change, max_change);
start + j start + j
} }
} }
+1 -2
View File
@@ -1446,7 +1446,6 @@ impl JavaClient {
server, server,
) )
.await; .await;
self.update_sequence(player, use_item_on.sequence.0);
// Check if the item is a block, because not every item can be placed :D // Check if the item is a block, because not every item can be placed :D
if let Some(block) = Block::from_item_id(item.lock().await.item.id) { if let Some(block) = Block::from_item_id(item.lock().await.item.id) {
@@ -1556,6 +1555,7 @@ impl JavaClient {
self.kick(TextComponent::text("InvalidHand")).await; self.kick(TextComponent::text("InvalidHand")).await;
return; return;
}; };
self.update_sequence(player, use_item.sequence.0);
let item_in_hand = if hand == Hand::Left { let item_in_hand = if hand == Hand::Left {
inventory.held_item() inventory.held_item()
} else { } else {
@@ -1603,7 +1603,6 @@ impl JavaClient {
let item = held.item; let item = held.item;
drop(held); drop(held);
server.item_registry.on_use(item, player).await; server.item_registry.on_use(item, player).await;
self.update_sequence(player, use_item.sequence.0);
} }
}} }}
} }