From 8b418813f8e016b7adf13badf396bc0d91a5b3f6 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Mon, 6 Apr 2026 23:22:38 +0200 Subject: [PATCH] chore: remove some dump unwraps we need to remove more --- pumpkin-world/src/chunk/format/linear.rs | 4 ++-- .../src/generation/feature/features/tree/mod.rs | 2 +- pumpkin/src/block/fluid/pathfinder.rs | 7 ++----- pumpkin/src/command/args/textcomponent.rs | 10 +++------- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/pumpkin-world/src/chunk/format/linear.rs b/pumpkin-world/src/chunk/format/linear.rs index 914fb5533..f1bf9e9d1 100644 --- a/pumpkin-world/src/chunk/format/linear.rs +++ b/pumpkin-world/src/chunk/format/linear.rs @@ -327,8 +327,8 @@ impl ChunkSerializer for LinearFile { header.size = chunk_raw.len() as u32; header.timestamp = SystemTime::now() .duration_since(UNIX_EPOCH) - .unwrap() - .as_secs() as u32; + .map(|d| d.as_secs() as u32) + .unwrap_or(0); // We update the data buffer self.chunks_data[index] = Some(chunk_raw); diff --git a/pumpkin-world/src/generation/feature/features/tree/mod.rs b/pumpkin-world/src/generation/feature/features/tree/mod.rs index 7e59e6788..bf96ff48b 100644 --- a/pumpkin-world/src/generation/feature/features/tree/mod.rs +++ b/pumpkin-world/src/generation/feature/features/tree/mod.rs @@ -90,7 +90,7 @@ impl TreeFeature { let clipped_height = self.minimum_size.min_clipped_height; let top = self.get_top(height, chunk, pos); // TODO: roots - if top < height && (clipped_height.is_none() || top < clipped_height.unwrap() as u32) { + if top < height && top < clipped_height.map_or(u32::MAX, |h| h as u32) { return vec![]; } let trunk_state = self.trunk_provider.get(random, pos); diff --git a/pumpkin/src/block/fluid/pathfinder.rs b/pumpkin/src/block/fluid/pathfinder.rs index e095529ea..4d205b615 100644 --- a/pumpkin/src/block/fluid/pathfinder.rs +++ b/pumpkin/src/block/fluid/pathfinder.rs @@ -62,14 +62,11 @@ pub async fn get_spread( continue; } - let new_fluid_state = fluid_impl.get_new_liquid(world, fluid, &side_pos).await; - // Skip if no valid fluid state for this position - if new_fluid_state.is_none() { + let Some(new_fluid_props) = fluid_impl.get_new_liquid(world, fluid, &side_pos).await else { continue; - } + }; - let new_fluid_props = new_fluid_state.unwrap(); let new_state_id = new_fluid_props.to_state_id(fluid); // Holes get distance 0 diff --git a/pumpkin/src/command/args/textcomponent.rs b/pumpkin/src/command/args/textcomponent.rs index eef4fae9a..e0642290d 100644 --- a/pumpkin/src/command/args/textcomponent.rs +++ b/pumpkin/src/command/args/textcomponent.rs @@ -61,11 +61,7 @@ impl FindArg<'_> for TextComponentArgConsumer { } fn parse_text_component(input: &str) -> Option { - let result = serde_json::from_str(input); - if let Err(e) = result { - debug!("Failed to parse text component: {e}"); - None - } else { - result.unwrap() - } + serde_json::from_str(input) + .map_err(|e| debug!("Failed to parse text component: {e}")) + .ok() }