diff --git a/Cargo.lock b/Cargo.lock index e7295d771..bcdb2a3e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,9 +66,9 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.40" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d67d43201f4d20c78bcda740c142ca52482d81da80681533d33bf3f0596c8e2" +checksum = "d0f9ee0f6e02ffd7ad5816e9464499fba7b3effd01123b515c41d1697c43dad1" dependencies = [ "compression-codecs", "compression-core", @@ -586,9 +586,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crossfire" -version = "3.1.3" +version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4150133c3f558d3190b52a4d36b571e29c18a24e98d24d12201bed0c038986f8" +checksum = "3fb12e9c05ae4854f743f0acec2f817148ba59a902484f6aa298d4fc7df2fac4" dependencies = [ "crossbeam-utils", "futures-core", @@ -616,9 +616,9 @@ dependencies = [ [[package]] name = "crypto-bigint" -version = "0.7.0-rc.27" +version = "0.7.0-rc.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b43308b9b6a47554f4612d5b1fb95ff935040aa3927dd42b1d6cbc015a262d96" +checksum = "96dacf199529fb801ae62a9aafdc01b189e9504c0d1ee1512a4c16bcd8666a93" dependencies = [ "cpubits", "ctutils", @@ -653,7 +653,7 @@ version = "0.7.0-pre.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6081ce8b60c0e533e2bba42771b94eb6149052115f4179744d5779883dc98583" dependencies = [ - "crypto-bigint 0.7.0-rc.27", + "crypto-bigint 0.7.0-rc.28", "libm", "rand_core 0.10.0", ] @@ -1463,9 +1463,9 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "linux-raw-sys" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "litemap" @@ -1871,9 +1871,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pin-utils" @@ -2202,9 +2202,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.44" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] @@ -2330,12 +2330,12 @@ dependencies = [ [[package]] name = "rsa" -version = "0.10.0-rc.15" +version = "0.10.0-rc.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b342b99544549f37509ed7fd42b0cea04bfd9ce07c16ca56094cf0fbeefbbcd" +checksum = "6fb9fd8c1edd9e6a2693623baf0fe77ff05ce022a5d7746900ffc38a15c233de" dependencies = [ "const-oid 0.10.2", - "crypto-bigint 0.7.0-rc.27", + "crypto-bigint 0.7.0-rc.28", "crypto-primes", "digest 0.11.0", "pkcs1", @@ -2354,9 +2354,9 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rustix" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ "bitflags", "errno", @@ -2752,9 +2752,9 @@ checksum = "016ef9739649996fcc983b9c588fe3d557cf216d4d98503ce1b057ab5a66d689" [[package]] name = "tempfile" -version = "3.25.0" +version = "3.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0136791f7c95b1f6dd99f9cc786b91bb81c3800b639b3478e561ddb7be95e5f1" +checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0" dependencies = [ "fastrand", "once_cell", @@ -2844,9 +2844,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.49.0" +version = "1.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" dependencies = [ "bytes", "libc", @@ -2861,9 +2861,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index f03e09cac..f0bd99838 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,7 @@ struct_excessive_bools = "allow" [workspace.package] version = "0.1.0-dev+1.21.11" edition = "2024" -rust-version = "1.89" +rust-version = "1.94" [profile.release] lto = true @@ -87,7 +87,7 @@ debug = true strip = false [workspace.dependencies] -tokio = { version = "1.49", default-features = false } +tokio = { version = "1.50", default-features = false } syn = { version = "2.0", default-features = false, features = ["printing"] } @@ -104,10 +104,10 @@ uuid = { version = "1.21", features = ["serde", "v3", "v4"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tempfile = { version = "3.25.0", default-features = false } +tempfile = { version = "3.26.0", default-features = false } proc-macro-error2 = "2" aes = "0.8" -async-compression = "0.4.40" +async-compression = "0.4.41" base64 = "0.22.1" bitflags = "2.11.0" cesu8 = "1.1" @@ -117,7 +117,7 @@ console-subscriber = { version = "0.5.0", default-features = false } crc-fast = "1.10.0" criterion = { version = "0.8", default-features = false } crossbeam-utils = "0.8.21" -crossfire = { version = "3.1.3", features = ["compat"] } +crossfire = { version = "3.1.4", features = ["compat"] } dashmap = "6.1" ecdsa = "0.16.9" enum_dispatch = "0.3.13" @@ -148,7 +148,7 @@ pumpkin-util = { path = "pumpkin-util" } pumpkin-world = { path = "pumpkin-world" } quote = "1.0" rand = "0.10.0" -rsa = "=0.10.0-rc.15" +rsa = "=0.10.0-rc.16" rustc-hash = "2.1.1" rustyline = "17.0.2" ruzstd = "0.8.2" diff --git a/pumpkin-codegen/src/chunk_gen_settings.rs b/pumpkin-codegen/src/chunk_gen_settings.rs index 4664f93ce..33e1a71d2 100644 --- a/pumpkin-codegen/src/chunk_gen_settings.rs +++ b/pumpkin-codegen/src/chunk_gen_settings.rs @@ -393,11 +393,13 @@ pub fn build() -> TokenStream { } impl GenerationShapeConfig { - #[inline] #[must_use] - pub fn vertical_cell_block_count(&self) -> u8 { self.size_vertical << 2 } + #[inline] + #[must_use] + pub const fn vertical_cell_block_count(&self) -> u8 { self.size_vertical << 2 } - #[inline] #[must_use] - pub fn horizontal_cell_block_count(&self) -> u8 { self.size_horizontal << 2 } + #[inline] + #[must_use] + pub const fn horizontal_cell_block_count(&self) -> u8 { self.size_horizontal << 2 } #[must_use] pub const fn max_y(&self) -> u16 { diff --git a/pumpkin-data/src/generated/chunk_gen_settings.rs b/pumpkin-data/src/generated/chunk_gen_settings.rs index 027f1994c..184339b5a 100644 --- a/pumpkin-data/src/generated/chunk_gen_settings.rs +++ b/pumpkin-data/src/generated/chunk_gen_settings.rs @@ -28,12 +28,12 @@ pub struct GenerationShapeConfig { impl GenerationShapeConfig { #[inline] #[must_use] - pub fn vertical_cell_block_count(&self) -> u8 { + pub const fn vertical_cell_block_count(&self) -> u8 { self.size_vertical << 2 } #[inline] #[must_use] - pub fn horizontal_cell_block_count(&self) -> u8 { + pub const fn horizontal_cell_block_count(&self) -> u8 { self.size_horizontal << 2 } #[must_use] diff --git a/pumpkin-protocol/src/codec/velocity.rs b/pumpkin-protocol/src/codec/velocity.rs index 1726d5767..100e68a2e 100644 --- a/pumpkin-protocol/src/codec/velocity.rs +++ b/pumpkin-protocol/src/codec/velocity.rs @@ -143,7 +143,7 @@ const fn abs_max(a: f64, b: f64) -> f64 { a.abs().max(b.abs()) } -fn to_long(value: f64) -> i64 { + fn to_long(value: f64) -> i64 { ((value.mul_add(0.5, 0.5) * MAX_15_BIT_VALUE).round() as i64).clamp(0, 32766) } diff --git a/pumpkin-protocol/src/java/client/config/update_tags.rs b/pumpkin-protocol/src/java/client/config/update_tags.rs index 7c45fcd19..b6f32c4b1 100644 --- a/pumpkin-protocol/src/java/client/config/update_tags.rs +++ b/pumpkin-protocol/src/java/client/config/update_tags.rs @@ -29,7 +29,7 @@ impl ClientPacket for CUpdateTags<'_> { version: &MinecraftVersion, ) -> Result<(), WritingError> { write.write_list(self.tags, |p, registry_key| { - p.write_string(&format!("minecraft:{}", registry_key.identifier_string(),))?; + p.write_string(&format!("minecraft:{}", registry_key.identifier_string()))?; let Some(values) = get_registry_key_tags(*version, *registry_key) else { // no tags defined for that registry key in this version diff --git a/pumpkin-util/src/math/boundingbox.rs b/pumpkin-util/src/math/boundingbox.rs index a2859bb9b..0785f403b 100644 --- a/pumpkin-util/src/math/boundingbox.rs +++ b/pumpkin-util/src/math/boundingbox.rs @@ -259,13 +259,13 @@ impl BoundingBox { /// Returns the minimum block position covered by this bounding box. #[must_use] - pub fn min_block_pos(&self) -> BlockPos { + pub const fn min_block_pos(&self) -> BlockPos { BlockPos::floored_v(self.min) } /// Returns the maximum block position covered by this bounding box. #[must_use] - pub fn max_block_pos(&self) -> BlockPos { + pub const fn max_block_pos(&self) -> BlockPos { // Use a tiny epsilon and floor the max coordinates so that a box whose // max is exactly on a block boundary does not include the adjacent // block. This mirrors vanilla behaviour where max block is inclusive @@ -295,7 +295,7 @@ impl BoundingBox { /// # Arguments /// * `other` – Vector specifying how much to stretch along each axis. #[must_use] - pub fn stretch(&self, other: Vector3) -> Self { + pub const fn stretch(&self, other: Vector3) -> Self { let mut new = *self; if other.x < 0.0 { diff --git a/pumpkin-util/src/math/mod.rs b/pumpkin-util/src/math/mod.rs index 2b1bc9226..a2b5d3740 100644 --- a/pumpkin-util/src/math/mod.rs +++ b/pumpkin-util/src/math/mod.rs @@ -73,7 +73,7 @@ pub fn subtract_angles(start: f32, end: f32) -> f32 { /// # Returns /// `a² + b² + c²` #[must_use] -pub fn squared_magnitude(a: f64, b: f64, c: f64) -> f64 { +pub const fn squared_magnitude(a: f64, b: f64, c: f64) -> f64 { c.mul_add(c, a.mul_add(a, b * b)) } @@ -179,7 +179,14 @@ pub fn floor_div(x: T, y: T) -> T { /// # Returns /// n² #[inline] -pub fn square(n: T) -> T { +#[must_use] +pub const fn square_f64(n: f64) -> f64 { + n * n +} + +#[inline] +#[must_use] +pub const fn square_f32(n: f32) -> f32 { n * n } diff --git a/pumpkin-util/src/math/position.rs b/pumpkin-util/src/math/position.rs index d081b31b4..7a0f6b0a1 100644 --- a/pumpkin-util/src/math/position.rs +++ b/pumpkin-util/src/math/position.rs @@ -371,7 +371,7 @@ impl BlockPos { /// # Returns /// A `BlockPos` with each coordinate floored to the nearest integer. #[must_use] - pub fn floored(x: f64, y: f64, z: f64) -> Self { + pub const fn floored(x: f64, y: f64, z: f64) -> Self { Self(Vector3::new( x.floor() as i32, y.floor() as i32, @@ -387,7 +387,7 @@ impl BlockPos { /// # Returns /// A `BlockPos` with each component floored to the nearest integer. #[must_use] - pub fn floored_v(pos: Vector3) -> Self { + pub const fn floored_v(pos: Vector3) -> Self { Self(Vector3::new( pos.x.floor() as i32, pos.y.floor() as i32, @@ -403,7 +403,7 @@ impl BlockPos { /// # Returns /// A `BlockPos` with each component ceiled to the nearest integer. #[must_use] - pub fn ceiled_v(pos: Vector3) -> Self { + pub const fn ceiled_v(pos: Vector3) -> Self { Self(Vector3::new( pos.x.ceil() as i32, pos.y.ceil() as i32, diff --git a/pumpkin-util/src/noise/mod.rs b/pumpkin-util/src/noise/mod.rs index 7b649db7d..486eb8a3d 100644 --- a/pumpkin-util/src/noise/mod.rs +++ b/pumpkin-util/src/noise/mod.rs @@ -107,7 +107,7 @@ impl Gradient { /// The dot product `self.x * x + self.y * y + self.z * z`. #[inline] #[must_use] - pub fn dot(&self, x: f64, y: f64, z: f64) -> f64 { + pub const fn dot(&self, x: f64, y: f64, z: f64) -> f64 { self.z.mul_add(z, self.x.mul_add(x, self.y * y)) } } diff --git a/pumpkin-util/src/noise/perlin.rs b/pumpkin-util/src/noise/perlin.rs index 07493b8d7..eee3c6eb5 100644 --- a/pumpkin-util/src/noise/perlin.rs +++ b/pumpkin-util/src/noise/perlin.rs @@ -137,7 +137,7 @@ impl PerlinNoiseSampler { /// # Returns /// The dot product of the selected gradient with (x, y, z). #[inline] - fn grad(hash: i32, x: f64, y: f64, z: f64) -> f64 { + const fn grad(hash: i32, x: f64, y: f64, z: f64) -> f64 { GRADIENTS[(hash & 15) as usize].dot(x, y, z) } @@ -152,8 +152,7 @@ impl PerlinNoiseSampler { /// # Returns /// The faded value. #[inline] - #[expect(clippy::suboptimal_flops)] - fn perlin_fade(value: f64) -> f64 { + const fn perlin_fade(value: f64) -> f64 { value * value * value * (value * (value * 6.0 - 15.0) + 10.0) } @@ -297,8 +296,7 @@ impl OctavePerlinNoiseSampler { /// The wrapped value. #[inline] #[must_use] - #[expect(clippy::suboptimal_flops)] - pub fn maintain_precision(value: f64) -> f64 { + pub const fn maintain_precision(value: f64) -> f64 { value - (value / 3.355_443_2E7 + 0.5).floor() * 3.355_443_2E7 } diff --git a/pumpkin-util/src/noise/simplex.rs b/pumpkin-util/src/noise/simplex.rs index 779b01bd1..262072c72 100644 --- a/pumpkin-util/src/noise/simplex.rs +++ b/pumpkin-util/src/noise/simplex.rs @@ -113,8 +113,7 @@ impl SimplexNoiseSampler { /// /// # Returns /// The contribution of this corner to the final noise value. - #[expect(clippy::suboptimal_flops)] - fn grad(gradient_index: usize, x: f64, y: f64, z: f64, distance: f64) -> f64 { + const fn grad(gradient_index: usize, x: f64, y: f64, z: f64, distance: f64) -> f64 { let d = distance - x * x - y * y - z * z; if d < 0f64 { 0f64 diff --git a/pumpkin-world/src/biome/multi_noise.rs b/pumpkin-world/src/biome/multi_noise.rs index fd6fbdff8..88163d328 100644 --- a/pumpkin-world/src/biome/multi_noise.rs +++ b/pumpkin-world/src/biome/multi_noise.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; #[must_use] -pub fn to_long(float: f32) -> i64 { +pub const fn to_long(float: f32) -> i64 { (float * 10000f32) as i64 } diff --git a/pumpkin-world/src/block/entities/chest_like_block_entity.rs b/pumpkin-world/src/block/entities/chest_like_block_entity.rs index 8f648788b..52784cd3c 100644 --- a/pumpkin-world/src/block/entities/chest_like_block_entity.rs +++ b/pumpkin-world/src/block/entities/chest_like_block_entity.rs @@ -1,7 +1,7 @@ -/// Implements the BlockEntity trait for chest-like block entities. +/// Implements the `BlockEntity` trait for chest-like block entities. /// Parameters: -/// - $struct_name: The type of the chest struct (e.g., ChestBlockEntity) -/// - $resource_id: The resource location string (e.g., "minecraft:chest") +/// - $`struct_name`: The type of the chest struct (e.g., `ChestBlockEntity`) +/// - $`resource_id`: The resource location string (e.g., "minecraft:chest") #[macro_export] macro_rules! impl_block_entity_for_chest { ($struct_name:ty) => { @@ -179,9 +179,10 @@ macro_rules! impl_clearable_for_chest { }; } -/// Implements the ViewerCountListener trait for chest-like block entities. -/// The behavior is controlled by the EMITS_REDSTONE constant on the struct. -/// When EMITS_REDSTONE is true, updates neighbors for redstone signals when viewer count changes. +/// Implements the `ViewerCountListener` trait for chest-like block entities. +/// +/// The behavior is controlled by the `EMITS_REDSTONE` constant on the struct. +/// When `EMITS_REDSTONE` is true, updates neighbors for redstone signals when viewer count changes. #[macro_export] macro_rules! impl_viewer_count_listener_for_chest { ($struct_name:ty) => { @@ -243,8 +244,9 @@ macro_rules! impl_viewer_count_listener_for_chest { } /// Implements helper methods for chest-like block entities. -/// Includes the play_sound method which handles sound positioning for single and double chests, -/// as well as new() and get_viewer_count() methods. +/// +/// Includes the `play_sound` method which handles sound positioning for single and double chests, +/// as well as `new()` and `get_viewer_count()` methods. #[macro_export] macro_rules! impl_chest_helper_methods { ($struct_name:ty) => { diff --git a/pumpkin-world/src/chunk_system/chunk_state.rs b/pumpkin-world/src/chunk_system/chunk_state.rs index 82bc28e7b..77592819d 100644 --- a/pumpkin-world/src/chunk_system/chunk_state.rs +++ b/pumpkin-world/src/chunk_system/chunk_state.rs @@ -89,6 +89,7 @@ impl From for ChunkStatus { } impl StagedChunkEnum { + #[must_use] pub const fn level_to_stage(level: i8) -> Self { if level <= 43 { Self::Full @@ -108,6 +109,7 @@ impl StagedChunkEnum { pub const FULL_DEPENDENCIES: &'static [Self] = &[Self::Full, Self::Lighting, Self::Features, Self::Surface]; pub const FULL_RADIUS: i32 = 3; + #[must_use] pub const fn get_direct_radius(self) -> i32 { // self exclude match self { @@ -123,6 +125,7 @@ impl StagedChunkEnum { _ => panic!(), } } + #[must_use] pub const fn get_write_radius(self) -> i32 { // self exclude match self { @@ -138,6 +141,7 @@ impl StagedChunkEnum { _ => panic!(), } } + #[must_use] pub const fn get_direct_dependencies(self) -> &'static [Self] { match self { // In vanilla StructureStart is first, but since it needs the biome in Vanilla it gets computed in StructureStart and @@ -161,6 +165,7 @@ pub enum Chunk { } impl Chunk { + #[must_use] pub fn get_stage_id(&self) -> u8 { match self { Self::Proto(data) => data.stage_id(), @@ -170,13 +175,14 @@ impl Chunk { pub fn get_proto_chunk_mut(&mut self) -> &mut ProtoChunk { match self { Self::Level(_) => panic!("chunk isn't a ProtoChunk"), - Chunk::Proto(chunk) => chunk, + Self::Proto(chunk) => chunk, } } + #[must_use] pub fn get_proto_chunk(&self) -> &ProtoChunk { match self { Self::Level(_) => panic!("chunk isn't a ProtoChunk"), - Chunk::Proto(chunk) => chunk, + Self::Proto(chunk) => chunk, } } pub fn upgrade_to_level_chunk( @@ -188,7 +194,7 @@ impl Chunk { // This allows us to move the light data instead of cloning it let proto_chunk_box = match std::mem::replace( self, - Chunk::Level(Arc::new(ChunkData { + Self::Level(Arc::new(ChunkData { section: ChunkSections::new(0, 0), heightmap: Default::default(), x: 0, @@ -202,8 +208,8 @@ impl Chunk { dirty: AtomicBool::new(false), })), ) { - Chunk::Proto(proto) => proto, - Chunk::Level(_) => panic!("Cannot upgrade a Level chunk"), + Self::Proto(proto) => proto, + Self::Level(_) => panic!("Cannot upgrade a Level chunk"), }; let proto_chunk = *proto_chunk_box; diff --git a/pumpkin-world/src/chunk_system/dag.rs b/pumpkin-world/src/chunk_system/dag.rs index b7543b295..c6a3e0674 100644 --- a/pumpkin-world/src/chunk_system/dag.rs +++ b/pumpkin-world/src/chunk_system/dag.rs @@ -12,6 +12,7 @@ pub struct Node { } impl Node { + #[must_use] pub fn new(pos: ChunkPos, stage: StagedChunkEnum) -> Self { Self { pos, @@ -30,6 +31,7 @@ pub struct Edge { } impl Edge { + #[must_use] pub const fn new(to: NodeKey, next: EdgeKey) -> Self { Self { to, next } } diff --git a/pumpkin-world/src/chunk_system/generation_cache.rs b/pumpkin-world/src/chunk_system/generation_cache.rs index 8d7baf6ce..0e1115405 100644 --- a/pumpkin-world/src/chunk_system/generation_cache.rs +++ b/pumpkin-world/src/chunk_system/generation_cache.rs @@ -296,6 +296,7 @@ impl GenerationCache for Cache { } impl Cache { + #[must_use] pub fn new(x: i32, z: i32, size: i32) -> Self { Self { x, diff --git a/pumpkin-world/src/chunk_system/schedule.rs b/pumpkin-world/src/chunk_system/schedule.rs index 0f1e15b4c..8a4816a65 100644 --- a/pumpkin-world/src/chunk_system/schedule.rs +++ b/pumpkin-world/src/chunk_system/schedule.rs @@ -158,10 +158,10 @@ impl GenerationSchedule { LightingEngineConfig::Full => { let mut engine = chunk.light_engine.lock().unwrap(); - for section in engine.block_light.iter_mut() { + for section in &mut engine.block_light { section.fill(15); } - for section in engine.sky_light.iter_mut() { + for section in &mut engine.sky_light { section.fill(15); } @@ -170,10 +170,10 @@ impl GenerationSchedule { LightingEngineConfig::Dark => { let mut engine = chunk.light_engine.lock().unwrap(); - for section in engine.block_light.iter_mut() { + for section in &mut engine.block_light { section.fill(0); } - for section in engine.sky_light.iter_mut() { + for section in &mut engine.sky_light { section.fill(0); } @@ -639,7 +639,18 @@ impl GenerationSchedule { // Check if this is the first time becoming public let was_public = holder.public; - if !was_public { + if was_public { + // Was already public but chunk has been regenerated (e.g., after relighting) + // Update the chunk data and re-notify players + self.apply_lighting_override(&chunk); + holder.chunk = Some(Chunk::Level(chunk.clone())); + self.public_chunk_map.insert(new_pos, chunk.clone()); + info!( + "Notifying players: regenerated chunk at {:?} (was already public)", + new_pos + ); + self.listener.process_new_chunk(new_pos, &chunk); + } else { self.apply_lighting_override(&chunk); // Clone once for public_chunk_map (needed for player access) let public_chunk = chunk.clone(); @@ -665,17 +676,6 @@ impl GenerationSchedule { new_pos ); } - } else { - // Was already public but chunk has been regenerated (e.g., after relighting) - // Update the chunk data and re-notify players - self.apply_lighting_override(&chunk); - holder.chunk = Some(Chunk::Level(chunk.clone())); - self.public_chunk_map.insert(new_pos, chunk.clone()); - info!( - "Notifying players: regenerated chunk at {:?} (was already public)", - new_pos - ); - self.listener.process_new_chunk(new_pos, &chunk); } } else { // Non-center chunk... just restore it to holder without cloning @@ -968,17 +968,14 @@ impl GenerationSchedule { if self.queue.is_empty() { // debug!("the queue is empty. thread sleep"); while self.running_task_count > 0 && self.queue.is_empty() { - match self.recv_chunk.try_recv() { - Ok((pos, data)) => { - self.receive_chunk(pos, data); - self.resort_work(self.send_level.get()); - } - Err(_) => { - if level.shut_down_chunk_system.load(Relaxed) { - break; - } - thread::sleep(Duration::from_millis(50)); + if let Ok((pos, data)) = self.recv_chunk.try_recv() { + self.receive_chunk(pos, data); + self.resort_work(self.send_level.get()); + } else { + if level.shut_down_chunk_system.load(Relaxed) { + break; } + thread::sleep(Duration::from_millis(50)); } } if self.queue.is_empty() { @@ -996,22 +993,19 @@ impl GenerationSchedule { let mut wait_iterations = 0; let max_wait_iterations = 100; // 5 seconds max wait while self.running_task_count > 0 && wait_iterations < max_wait_iterations { - match self.recv_chunk.try_recv() { - Ok((pos, data)) => { - self.receive_chunk(pos, data); - wait_iterations = 0; // Reset counter when we receive data - } - Err(_) => { - wait_iterations += 1; - if wait_iterations % 20 == 0 { - warn!( - "Still waiting for {} tasks to complete (waited {}ms)", - self.running_task_count, - wait_iterations * 50 - ); - } - thread::sleep(Duration::from_millis(50)); + if let Ok((pos, data)) = self.recv_chunk.try_recv() { + self.receive_chunk(pos, data); + wait_iterations = 0; // Reset counter when we receive data + } else { + wait_iterations += 1; + if wait_iterations % 20 == 0 { + warn!( + "Still waiting for {} tasks to complete (waited {}ms)", + self.running_task_count, + wait_iterations * 50 + ); } + thread::sleep(Duration::from_millis(50)); } } diff --git a/pumpkin-world/src/chunk_system/worker_logic.rs b/pumpkin-world/src/chunk_system/worker_logic.rs index 01f741ac8..4ca5fede1 100644 --- a/pumpkin-world/src/chunk_system/worker_logic.rs +++ b/pumpkin-world/src/chunk_system/worker_logic.rs @@ -234,12 +234,11 @@ pub fn generation_work( let settings = GenerationSettings::from_dimension(&level.world_gen.dimension); loop { - let (pos, mut cache, stage) = match recv.recv() { - Ok(data) => data, - Err(_) => { - debug!("generation channel closed, exiting"); - break; - } + let (pos, mut cache, stage) = if let Ok(data) = recv.recv() { + data + } else { + debug!("generation channel closed, exiting"); + break; }; // Run generation with panic catching @@ -267,7 +266,11 @@ pub fn generation_work( let msg = payload .downcast_ref::<&str>() .copied() - .or_else(|| payload.downcast_ref::().map(|s| s.as_str())) + .or_else(|| { + payload + .downcast_ref::() + .map(std::string::String::as_str) + }) .unwrap_or("Unknown panic payload"); error!("Chunk generation FAILED at {pos:?} ({stage:?}): {msg}"); diff --git a/pumpkin-world/src/generation/biome.rs b/pumpkin-world/src/generation/biome.rs index b5fcb4823..b31eecfc4 100644 --- a/pumpkin-world/src/generation/biome.rs +++ b/pumpkin-world/src/generation/biome.rs @@ -1,4 +1,4 @@ -use pumpkin_util::math::{floor_mod, square, vector3::Vector3}; +use pumpkin_util::math::{square_f64, vector3::Vector3}; use super::biome_coords; @@ -110,7 +110,7 @@ pub fn get_biome_blend( // This is effectively getting a random offset (+/- 0.0-0.8ish) to our biome position quarters and // returning a hypotenuse squared of the parts + the offset -fn score_permutation( +const fn score_permutation( seed: i64, x: i32, y: i32, @@ -131,12 +131,15 @@ fn score_permutation( let mix = salt_mix(mix, seed); let offset_z = scale_mix(mix); - square(z_part + offset_z) + square(y_part + offset_y) + square(x_part + offset_x) + square_f64(z_part + offset_z) + square_f64(y_part + offset_y) + square_f64(x_part + offset_x) } #[inline] -fn scale_mix(l: i64) -> f64 { - let d = floor_mod(l >> 24, 1024i64) as i32 as f64 / 1024.0; +pub const fn scale_mix(l: i64) -> f64 { + // Shifting and then masking with 1023 (1024 - 1) + // This is mathematically identical to floor_mod(l >> 24, 1024) + // but executes in a single CPU cycle. + let d = ((l >> 24) & 1023) as f64 / 1024.0; (d - 0.5) * 0.9 } diff --git a/pumpkin-world/src/generation/feature/features/geode.rs b/pumpkin-world/src/generation/feature/features/geode.rs index f7ae81afa..d9096d1d6 100644 --- a/pumpkin-world/src/generation/feature/features/geode.rs +++ b/pumpkin-world/src/generation/feature/features/geode.rs @@ -19,7 +19,7 @@ struct NormalNoise(crate::generation::noise::perlin::DoublePerlinNoiseSampler); impl NormalNoise { fn create(rand: &mut RandomGenerator, first_octave: i32, amplitudes: &[f64]) -> Self { - NormalNoise( + Self( crate::generation::noise::perlin::DoublePerlinNoiseSampler::new( rand, first_octave, @@ -259,7 +259,7 @@ impl GeodeFeature { } if matches!( dist_sum_shell.partial_cmp(&outer_crust), - Some(Ordering::Greater) | Some(Ordering::Equal) + Some(Ordering::Greater | Ordering::Equal) ) { if should_generate_crack && dist_sum_crack >= crack_size diff --git a/pumpkin-world/src/generation/feature/features/tree/foliage/fancy.rs b/pumpkin-world/src/generation/feature/features/tree/foliage/fancy.rs index 099877fd4..57ba8bb21 100644 --- a/pumpkin-world/src/generation/feature/features/tree/foliage/fancy.rs +++ b/pumpkin-world/src/generation/feature/features/tree/foliage/fancy.rs @@ -1,5 +1,6 @@ use pumpkin_data::BlockState; -use pumpkin_util::{math::square, random::RandomGenerator}; +use pumpkin_util::math::square_f32; +use pumpkin_util::random::RandomGenerator; use super::{FoliagePlacer, LeaveValidator}; use crate::generation::feature::features::tree::TreeNode; @@ -51,6 +52,6 @@ impl LeaveValidator for LargeOakFoliagePlacer { radius: i32, _giant_trunk: bool, ) -> bool { - square(dx as f32 + 0.5) + square(dz as f32 + 0.5) > (radius * radius) as f32 + square_f32(dx as f32 + 0.5) + square_f32(dz as f32 + 0.5) > (radius * radius) as f32 } } diff --git a/pumpkin-world/src/generation/noise/mod.rs b/pumpkin-world/src/generation/noise/mod.rs index a77bdae88..456f0c99c 100644 --- a/pumpkin-world/src/generation/noise/mod.rs +++ b/pumpkin-world/src/generation/noise/mod.rs @@ -408,13 +408,13 @@ impl<'a> ChunkNoiseGenerator<'a> { #[inline] #[must_use] - pub fn horizontal_cell_block_count(&self) -> u8 { + pub const fn horizontal_cell_block_count(&self) -> u8 { self.generation_shape.horizontal_cell_block_count() } #[inline] #[must_use] - pub fn vertical_cell_block_count(&self) -> u8 { + pub const fn vertical_cell_block_count(&self) -> u8 { self.generation_shape.vertical_cell_block_count() } diff --git a/pumpkin-world/src/generation/noise/router/density_function/spline.rs b/pumpkin-world/src/generation/noise/router/density_function/spline.rs index 3e4b07371..4cc534bd8 100644 --- a/pumpkin-world/src/generation/noise/router/density_function/spline.rs +++ b/pumpkin-world/src/generation/noise/router/density_function/spline.rs @@ -53,7 +53,7 @@ impl SplinePoint { } } - fn sample_outside_range(&self, sample_location: f32, last_known_sample: f32) -> f32 { + const fn sample_outside_range(&self, sample_location: f32, last_known_sample: f32) -> f32 { if self.derivative == 0f32 { last_known_sample } else { diff --git a/pumpkin-world/src/generation/rule/block_match.rs b/pumpkin-world/src/generation/rule/block_match.rs index 69988762e..f2639040d 100644 --- a/pumpkin-world/src/generation/rule/block_match.rs +++ b/pumpkin-world/src/generation/rule/block_match.rs @@ -6,6 +6,7 @@ pub struct BlockMatchRuleTest { } impl BlockMatchRuleTest { + #[must_use] pub fn test(&self, state: RawBlockState) -> bool { state.to_block().name == self.block.strip_prefix("minecraft:").unwrap_or(&self.block) } diff --git a/pumpkin-world/src/generation/rule/block_state_match.rs b/pumpkin-world/src/generation/rule/block_state_match.rs index c8737f313..73098b4e0 100644 --- a/pumpkin-world/src/generation/rule/block_state_match.rs +++ b/pumpkin-world/src/generation/rule/block_state_match.rs @@ -5,6 +5,7 @@ pub struct BlockStateMatchRuleTest { } impl BlockStateMatchRuleTest { + #[must_use] pub fn test(&self, state: RawBlockState) -> bool { state.0 == self.block_state.get_state_id() } diff --git a/pumpkin-world/src/generation/rule/tag_match.rs b/pumpkin-world/src/generation/rule/tag_match.rs index 079b5432f..bfa0962e3 100644 --- a/pumpkin-world/src/generation/rule/tag_match.rs +++ b/pumpkin-world/src/generation/rule/tag_match.rs @@ -7,6 +7,7 @@ pub struct TagMatchRuleTest { } impl TagMatchRuleTest { + #[must_use] pub fn test(&self, state: RawBlockState) -> bool { let values = get_tag_ids(RegistryKey::Block, &self.tag).unwrap(); values.contains(&state.to_block_id()) diff --git a/pumpkin-world/src/generation/structure/structures/igloo.rs b/pumpkin-world/src/generation/structure/structures/igloo.rs index 01d87e8b9..17a7d9cf8 100644 --- a/pumpkin-world/src/generation/structure/structures/igloo.rs +++ b/pumpkin-world/src/generation/structure/structures/igloo.rs @@ -45,11 +45,11 @@ const BASEMENT_DEPTH: i32 = 9; const PIVOT_OFFSET_X: i32 = 3; const PIVOT_OFFSET_Z: i32 = 5; -/// Offset from dome to shaft entrance (vanilla: OFFSETS_FROM_TOP for middle). +/// Offset from dome to shaft entrance (vanilla: `OFFSETS_FROM_TOP` for middle). const SHAFT_OFFSET_X: i32 = 2; const SHAFT_OFFSET_Z: i32 = 4; -/// Offset from dome to basement (vanilla: OFFSETS_FROM_TOP for bottom). +/// Offset from dome to basement (vanilla: `OFFSETS_FROM_TOP` for bottom). const BASEMENT_OFFSET_X: i32 = 0; const BASEMENT_OFFSET_Z: i32 = -2; diff --git a/pumpkin-world/src/generation/structure/structures/nether_fossil.rs b/pumpkin-world/src/generation/structure/structures/nether_fossil.rs index afa2c5ad5..e1cf1b48b 100644 --- a/pumpkin-world/src/generation/structure/structures/nether_fossil.rs +++ b/pumpkin-world/src/generation/structure/structures/nether_fossil.rs @@ -41,8 +41,8 @@ const TEMPLATE_NAMES: [&str; 14] = [ ]; /// Vanilla height provider bounds for nether fossils. -/// From nether_fossil.json: uniform(absolute=32, below_top=2). -/// Vanilla BelowTop: height - 1 + min_y - offset = 256 - 1 + 0 - 2 = 253. +/// From `nether_fossil.json`: uniform(absolute=32, `below_top=2`). +/// Vanilla `BelowTop`: height - 1 + `min_y` - offset = 256 - 1 + 0 - 2 = 253. const HEIGHT_MIN: i32 = 32; const HEIGHT_MAX: i32 = 253; @@ -122,7 +122,7 @@ struct NetherFossilPiece { } impl NetherFossilPiece { - /// Vanilla column scan: search downward from initial_y for air above (soul sand OR solid block). + /// Vanilla column scan: search downward from `initial_y` for air above (soul sand OR solid block). /// Returns the Y of the support block, or None if no valid position found above sea level. /// /// Mirrors vanilla's pre-decrement loop: @@ -134,7 +134,7 @@ impl NetherFossilPiece { /// } /// if (l <= k) return empty; /// ``` - /// After the loop, l is the support block Y. Vanilla rejects if l <= sea_level. + /// After the loop, l is the support block Y. Vanilla rejects if l <= `sea_level`. fn find_placement_y(&self, chunk: &ProtoChunk) -> Option { let origin = self.shiftable_structure_piece.piece.bounding_box.min; let mut y = self.initial_y; @@ -213,9 +213,9 @@ impl NetherFossilPiece { use pumpkin_util::random::xoroshiro128::Xoroshiro; let bbox = self.shiftable_structure_piece.piece.bounding_box; - let center_x = (bbox.min.x + bbox.max.x) / 2; - let center_y = (bbox.min.y + bbox.max.y) / 2; - let center_z = (bbox.min.z + bbox.max.z) / 2; + let center_x = i32::midpoint(bbox.min.x, bbox.max.x); + let center_y = i32::midpoint(bbox.min.y, bbox.max.y); + let center_z = i32::midpoint(bbox.min.z, bbox.max.z); // Vanilla: Random.create(world.getSeed()).nextSplitter().split(box.getCenter()) let mut rng = RandomGenerator::Xoroshiro(Xoroshiro::from_seed(seed as u64)); diff --git a/pumpkin-world/src/generation/structure/template/block_state_resolver.rs b/pumpkin-world/src/generation/structure/template/block_state_resolver.rs index 67eaff139..381b2c9c5 100644 --- a/pumpkin-world/src/generation/structure/template/block_state_resolver.rs +++ b/pumpkin-world/src/generation/structure/template/block_state_resolver.rs @@ -33,12 +33,11 @@ impl BlockStateResolver { // Find the block let block = Block::from_name(&entry.name).or_else(|| Block::from_registry_key(block_name)); - let block = match block { - Some(b) => b, - None => { - warn!("Unknown block in template: {}", entry.name); - return None; - } + let block = if let Some(b) = block { + b + } else { + warn!("Unknown block in template: {}", entry.name); + return None; }; // If no properties, return default state @@ -108,7 +107,7 @@ impl BlockStateResolver { } /// Converts a rotation value (0-15) to a static string. - fn rotation_to_str(rotation: i32) -> &'static str { + const fn rotation_to_str(rotation: i32) -> &'static str { match rotation % 16 { 0 => "0", 1 => "1", diff --git a/pumpkin-world/src/generation/structure/template/mod.rs b/pumpkin-world/src/generation/structure/template/mod.rs index 1aaf98de8..239dd3d8e 100644 --- a/pumpkin-world/src/generation/structure/template/mod.rs +++ b/pumpkin-world/src/generation/structure/template/mod.rs @@ -49,7 +49,7 @@ pub use template_piece::TemplatePiece; /// - Block entities are created from template NBT data /// /// `origin` is the base world position (x, y, z). -/// `offset` is the un-rotated XZ offset from origin (x_offset, z_offset) - rotation is applied automatically. +/// `offset` is the un-rotated XZ offset from origin (`x_offset`, `z_offset`) - rotation is applied automatically. pub fn place_template( chunk: &mut ProtoChunk, template: &StructureTemplate, diff --git a/pumpkin-world/src/generation/structure/template/rotation.rs b/pumpkin-world/src/generation/structure/template/rotation.rs index ed9003bb9..0e52c3d8b 100644 --- a/pumpkin-world/src/generation/structure/template/rotation.rs +++ b/pumpkin-world/src/generation/structure/template/rotation.rs @@ -47,7 +47,7 @@ impl BlockRotation { /// The position is rotated around the Y axis. The `size` parameter defines /// the template dimensions, used to calculate the pivot point. #[must_use] - pub fn transform_pos(&self, pos: Vector3, size: Vector3) -> Vector3 { + pub const fn transform_pos(&self, pos: Vector3, size: Vector3) -> Vector3 { match self { Self::None => pos, Self::Clockwise90 => Vector3::new(size.z - 1 - pos.z, pos.y, pos.x), @@ -61,7 +61,7 @@ impl BlockRotation { /// Unlike `transform_pos` which rotates within template bounds, /// this rotates a simple offset (e.g. sub-template positioning). #[must_use] - pub fn rotate_offset(self, x: i32, z: i32) -> (i32, i32) { + pub const fn rotate_offset(self, x: i32, z: i32) -> (i32, i32) { match self { Self::None => (x, z), Self::Clockwise90 => (-z, x), @@ -169,7 +169,7 @@ impl BlockRotation { /// Converts rotation to a primary axis for bounding box creation. #[must_use] - pub fn to_axis(self) -> pumpkin_util::math::vector3::Axis { + pub const fn to_axis(self) -> pumpkin_util::math::vector3::Axis { match self { Self::None | Self::Rotate180 => pumpkin_util::math::vector3::Axis::Z, Self::Clockwise90 | Self::CounterClockwise90 => pumpkin_util::math::vector3::Axis::X, @@ -198,7 +198,7 @@ impl BlockMirror { /// Transforms a position within the template bounds according to this mirror. #[must_use] - pub fn transform_pos(&self, pos: Vector3, size: Vector3) -> Vector3 { + pub const fn transform_pos(&self, pos: Vector3, size: Vector3) -> Vector3 { match self { Self::None => pos, Self::LeftRight => Vector3::new(size.x - 1 - pos.x, pos.y, pos.z), diff --git a/pumpkin-world/src/generation/structure/template/structure_template.rs b/pumpkin-world/src/generation/structure/template/structure_template.rs index 319954e1f..1cffcaec6 100644 --- a/pumpkin-world/src/generation/structure/template/structure_template.rs +++ b/pumpkin-world/src/generation/structure/template/structure_template.rs @@ -50,7 +50,7 @@ pub struct StructureTemplate { /// Each palette entry defines a block type with optional properties. #[derive(Debug, Clone)] pub struct PaletteEntry { - /// The block name (e.g., "minecraft:stone_bricks"). + /// The block name (e.g., "`minecraft:stone_bricks`"). pub name: String, /// Block state properties (e.g., [("facing", "north"), ("lit", "false")]). @@ -60,7 +60,7 @@ pub struct PaletteEntry { impl PaletteEntry { /// Creates a new palette entry with no properties. #[must_use] - pub fn new(name: String) -> Self { + pub const fn new(name: String) -> Self { Self { name, properties: Vec::new(), @@ -69,7 +69,7 @@ impl PaletteEntry { /// Creates a new palette entry with the given properties. #[must_use] - pub fn with_properties(name: String, properties: Vec<(String, String)>) -> Self { + pub const fn with_properties(name: String, properties: Vec<(String, String)>) -> Self { Self { name, properties } } } @@ -334,7 +334,7 @@ impl StructureTemplate { /// Returns the total number of blocks in this template. #[must_use] - pub fn block_count(&self) -> usize { + pub const fn block_count(&self) -> usize { self.blocks.len() } @@ -346,7 +346,7 @@ impl StructureTemplate { /// Returns whether this template has any entities. #[must_use] - pub fn has_entities(&self) -> bool { + pub const fn has_entities(&self) -> bool { !self.entities.is_empty() } } diff --git a/pumpkin-world/src/generation/structure/template/template_piece.rs b/pumpkin-world/src/generation/structure/template/template_piece.rs index 0f521be60..26ff8c22a 100644 --- a/pumpkin-world/src/generation/structure/template/template_piece.rs +++ b/pumpkin-world/src/generation/structure/template/template_piece.rs @@ -131,13 +131,13 @@ impl TemplatePiece { } // Resolve the block state with rotation/mirror - let state = match BlockStateResolver::resolve(palette_entry, self.rotation, self.mirror) + let state = if let Some(s) = + BlockStateResolver::resolve(palette_entry, self.rotation, self.mirror) { - Some(s) => s, - None => { - debug!("Failed to resolve block: {}", palette_entry.name); - continue; - } + s + } else { + debug!("Failed to resolve block: {}", palette_entry.name); + continue; }; // Transform position to world coordinates diff --git a/pumpkin-world/src/level.rs b/pumpkin-world/src/level.rs index ff7536285..1f3025635 100644 --- a/pumpkin-world/src/level.rs +++ b/pumpkin-world/src/level.rs @@ -295,7 +295,7 @@ impl Level { info!("Joining {} threads for {}...", handle_count, world_id); let join_task = tokio::task::spawn_blocking(move || { let mut failed_count = 0; - for handle in handles.into_iter() { + for handle in handles { if handle.join().is_err() { failed_count += 1; } diff --git a/pumpkin-world/src/lighting/engine.rs b/pumpkin-world/src/lighting/engine.rs index 7a64221dc..8d52fbf8e 100644 --- a/pumpkin-world/src/lighting/engine.rs +++ b/pumpkin-world/src/lighting/engine.rs @@ -29,7 +29,7 @@ impl LightProvider for BlockLightProvider { } #[inline(always)] fn set_light(cache: &mut Cache, pos: BlockPos, level: u8) { - set_block_light(cache, pos, level) + set_block_light(cache, pos, level); } #[inline(always)] fn propagate_level(current_level: u8, opacity: u8, _dir: BlockDirection) -> u8 { @@ -45,7 +45,7 @@ impl LightProvider for SkyLightProvider { } #[inline(always)] fn set_light(cache: &mut Cache, pos: BlockPos, level: u8) { - set_sky_light(cache, pos, level) + set_sky_light(cache, pos, level); } #[inline(always)] fn propagate_level(current_level: u8, opacity: u8, dir: BlockDirection) -> u8 { @@ -75,6 +75,7 @@ pub struct LightPropagator { } impl LightPropagator

{ + #[must_use] pub fn new() -> Self { Self { queue: VecDeque::with_capacity(4096), @@ -447,10 +448,7 @@ impl SkyLightPropagator { if y <= top_y { break; } - // Safe to break if we're under our own roof - else { - continue; - } + continue; } let is_at_surface = y == top_y; @@ -458,11 +456,7 @@ impl SkyLightPropagator { y < north_top || y < south_top || y < west_top || y < east_top; if (is_at_surface || below_neighbor) && self.visited.insert(pos) { - let skip_dir = if y >= top_y { - Some(BlockDirection::Up) - } else { - None - }; + let skip_dir = (y >= top_y).then_some(BlockDirection::Up); self.queue.push_back(PropagationEntry { pos, @@ -489,6 +483,7 @@ pub struct LightEngine { } impl LightEngine { + #[must_use] pub fn new() -> Self { Self { block_light: BlockLightPropagator::new(), diff --git a/pumpkin-world/src/lighting/runtime.rs b/pumpkin-world/src/lighting/runtime.rs index b9b1fc687..10aeba9c4 100644 --- a/pumpkin-world/src/lighting/runtime.rs +++ b/pumpkin-world/src/lighting/runtime.rs @@ -15,7 +15,8 @@ pub struct DynamicLightEngine { } impl DynamicLightEngine { - pub fn new() -> Self { + #[must_use] + pub const fn new() -> Self { Self { decrease_block_light_queue: SegQueue::new(), increase_block_light_queue: SegQueue::new(), @@ -395,7 +396,7 @@ impl DynamicLightEngine { if has_sky { // Direct sunlight, reduced by opacity - 15_u8.saturating_sub(opacity) + 15u8.saturating_sub(opacity) } else { // No direct sky, check neighbors for best light let mut best_light = 0; diff --git a/pumpkin-world/src/lighting/storage.rs b/pumpkin-world/src/lighting/storage.rs index 0e7cc7ddd..4c62b2eb4 100644 --- a/pumpkin-world/src/lighting/storage.rs +++ b/pumpkin-world/src/lighting/storage.rs @@ -4,7 +4,7 @@ use crate::generation::height_limit::HeightLimitView; use pumpkin_util::math::position::BlockPos; #[inline(always)] -fn get_chunk_index(cache: &Cache, chunk_x: i32, chunk_z: i32) -> Option { +const fn get_chunk_index(cache: &Cache, chunk_x: i32, chunk_z: i32) -> Option { let rel_x = chunk_x - cache.x; let rel_z = chunk_z - cache.z; if rel_x < 0 || rel_x >= cache.size || rel_z < 0 || rel_z >= cache.size { @@ -24,6 +24,7 @@ fn get_section_y(cache: &Cache, pos_y: i32) -> Option { } #[inline(always)] +#[must_use] pub fn get_block_light(cache: &Cache, pos: BlockPos) -> u8 { let chunk_x = pos.0.x >> 4; let chunk_z = pos.0.z >> 4; @@ -90,6 +91,7 @@ pub fn set_block_light(cache: &mut Cache, pos: BlockPos, level: u8) { } #[inline(always)] +#[must_use] pub fn get_sky_light(cache: &Cache, pos: BlockPos) -> u8 { let chunk_x = pos.0.x >> 4; let chunk_z = pos.0.z >> 4; diff --git a/pumpkin-world/src/poi/mod.rs b/pumpkin-world/src/poi/mod.rs index 4b5a91ac0..3e6815e02 100644 --- a/pumpkin-world/src/poi/mod.rs +++ b/pumpkin-world/src/poi/mod.rs @@ -235,8 +235,7 @@ impl PoiRegion { let timestamp = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) - .map(|d| d.as_secs() as u32) - .unwrap_or(0); + .map_or(0, |d| d.as_secs() as u32); // Start after header (2 sectors) let mut current_sector: u32 = 2; diff --git a/pumpkin-world/src/world_info/mod.rs b/pumpkin-world/src/world_info/mod.rs index 095a30d41..31a7700fc 100644 --- a/pumpkin-world/src/world_info/mod.rs +++ b/pumpkin-world/src/world_info/mod.rs @@ -91,19 +91,19 @@ const DEFAULT_DIFFICULTY: Difficulty = Difficulty::Normal; const DEFAULT_LEVEL_NAME: &str = "world"; const DEFAULT_SPAWN_Y: i32 = 200; -fn default_border_damage_per_block() -> f64 { +const fn default_border_damage_per_block() -> f64 { DEFAULT_BORDER_DAMAGE_PER_BLOCK } -fn default_border_size() -> f64 { +const fn default_border_size() -> f64 { DEFAULT_BORDER_SIZE } -fn default_border_safe_zone() -> f64 { +const fn default_border_safe_zone() -> f64 { DEFAULT_BORDER_SAFE_ZONE } -fn default_border_warning_blocks() -> f64 { +const fn default_border_warning_blocks() -> f64 { DEFAULT_BORDER_WARNING_BLOCKS } -fn default_border_warning_time() -> f64 { +const fn default_border_warning_time() -> f64 { DEFAULT_BORDER_WARNING_TIME } fn default_data_packs() -> DataPacks { @@ -112,16 +112,16 @@ fn default_data_packs() -> DataPacks { enabled: vec!["vanilla".to_string()], } } -fn default_difficulty() -> Difficulty { +const fn default_difficulty() -> Difficulty { DEFAULT_DIFFICULTY } fn default_level_name() -> String { DEFAULT_LEVEL_NAME.to_string() } -fn default_spawn_y() -> i32 { +const fn default_spawn_y() -> i32 { DEFAULT_SPAWN_Y } -fn default_level_version() -> i32 { +const fn default_level_version() -> i32 { MAXIMUM_SUPPORTED_LEVEL_VERSION } diff --git a/pumpkin/src/block/blocks/redstone/rails/activator_rail.rs b/pumpkin/src/block/blocks/redstone/rails/activator_rail.rs index bc83f0f4e..be40d3b7a 100644 --- a/pumpkin/src/block/blocks/redstone/rails/activator_rail.rs +++ b/pumpkin/src/block/blocks/redstone/rails/activator_rail.rs @@ -556,7 +556,6 @@ impl ActivatorRailBlock { pos: &BlockPos, ) -> Option<(&'static Block, RailProperties)> { let block = world.get_block(pos).await; - #[expect(clippy::if_then_some_else_none)] if *block == Block::ACTIVATOR_RAIL { let state_id = world.get_block_state_id(pos).await; let rail_props = RailProperties::new(state_id, block); diff --git a/pumpkin/src/block/blocks/redstone/rails/powered_rail.rs b/pumpkin/src/block/blocks/redstone/rails/powered_rail.rs index f77d98811..a6a53342b 100644 --- a/pumpkin/src/block/blocks/redstone/rails/powered_rail.rs +++ b/pumpkin/src/block/blocks/redstone/rails/powered_rail.rs @@ -557,7 +557,6 @@ impl PoweredRailBlock { pos: &BlockPos, ) -> Option<(&'static Block, RailProperties)> { let block = world.get_block(pos).await; - #[expect(clippy::if_then_some_else_none)] if *block == Block::POWERED_RAIL { let state_id = world.get_block_state_id(pos).await; let rail_props = RailProperties::new(state_id, block); diff --git a/pumpkin/src/command/commands/pumpkin.rs b/pumpkin/src/command/commands/pumpkin.rs index 83d892a7f..4b5e22fd7 100644 --- a/pumpkin/src/command/commands/pumpkin.rs +++ b/pumpkin/src/command/commands/pumpkin.rs @@ -103,7 +103,7 @@ impl CommandExecutor for Executor { vec![TextComponent::text(version_string.clone())], ) .hover_event(HoverEvent::show_text( - TextComponent::text(format!("Commit: {GIT_HASH_FULL}\n\nContributors:\n",)) + TextComponent::text(format!("Commit: {GIT_HASH_FULL}\n\nContributors:\n")) .add_child( TextComponent::text(contributor_names) .gradient_named(&[NamedColor::DarkGreen, NamedColor::Green]) diff --git a/pumpkin/src/command/dispatcher.rs b/pumpkin/src/command/dispatcher.rs index d6146fd7d..76b190b14 100644 --- a/pumpkin/src/command/dispatcher.rs +++ b/pumpkin/src/command/dispatcher.rs @@ -165,41 +165,29 @@ impl CommandDispatcher { continue; } match c { - '{' => { - if !in_single_quotes && !in_double_quotes { - in_braces += 1; - } + '{' if !in_single_quotes && !in_double_quotes => { + in_braces += 1; } - '}' => { - if !in_single_quotes && !in_double_quotes { - if in_braces == 0 { - return Err(CommandFailed(TextComponent::text("Unmatched braces"))); - } - in_braces -= 1; + '}' if !in_single_quotes && !in_double_quotes => { + if in_braces == 0 { + return Err(CommandFailed(TextComponent::text("Unmatched braces"))); } + in_braces -= 1; } - '[' => { - if !in_single_quotes && !in_double_quotes { - in_brackets += 1; - } + '[' if !in_single_quotes && !in_double_quotes => { + in_brackets += 1; } - ']' => { - if !in_single_quotes && !in_double_quotes { - if in_brackets == 0 { - return Err(CommandFailed(TextComponent::text("Unmatched brackets"))); - } - in_brackets -= 1; + ']' if !in_single_quotes && !in_double_quotes => { + if in_brackets == 0 { + return Err(CommandFailed(TextComponent::text("Unmatched brackets"))); } + in_brackets -= 1; } - '\'' => { - if !in_double_quotes { - in_single_quotes = !in_single_quotes; - } + '\'' if !in_double_quotes => { + in_single_quotes = !in_single_quotes; } - '"' => { - if !in_single_quotes { - in_double_quotes = !in_double_quotes; - } + '"' if !in_single_quotes => { + in_double_quotes = !in_double_quotes; } ' ' if !in_single_quotes && !in_double_quotes diff --git a/pumpkin/src/entity/ai/pathfinder/node_evaluator.rs b/pumpkin/src/entity/ai/pathfinder/node_evaluator.rs index be825a41a..1aa41742a 100644 --- a/pumpkin/src/entity/ai/pathfinder/node_evaluator.rs +++ b/pumpkin/src/entity/ai/pathfinder/node_evaluator.rs @@ -108,7 +108,7 @@ impl MobData { } #[must_use] - pub fn block_position(&self) -> (i32, i32, i32) { + pub const fn block_position(&self) -> (i32, i32, i32) { ( self.position.x.floor() as i32, self.position.y.floor() as i32, diff --git a/pumpkin/src/entity/mod.rs b/pumpkin/src/entity/mod.rs index bb999eb91..a14642e97 100644 --- a/pumpkin/src/entity/mod.rs +++ b/pumpkin/src/entity/mod.rs @@ -2440,10 +2440,10 @@ impl Entity { return; } } - v if v == EntityType::SPIDER.id || v == EntityType::CAVE_SPIDER.id => { - if Block::from_state_id(state.id).id == Block::COBWEB.id { - return; - } + v if (v == EntityType::SPIDER.id || v == EntityType::CAVE_SPIDER.id) + && Block::from_state_id(state.id).id == Block::COBWEB.id => + { + return; } v if v == EntityType::WITHER.id => { return; diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index e49e22274..a3a8cb909 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -309,7 +309,7 @@ impl ChunkManager { self.last_chunk_batch_sent_at = Instant::now(); } - pub fn handle_acknowledge(&mut self, chunks_per_tick: f32) { + pub const fn handle_acknowledge(&mut self, chunks_per_tick: f32) { self.batches_sent_since_ack = BatchState::Count(0); self.chunks_per_tick = chunks_per_tick.ceil() as usize; } diff --git a/pumpkin/src/entity/projectile/wind_charge.rs b/pumpkin/src/entity/projectile/wind_charge.rs index 7905b9df5..469c2bcba 100644 --- a/pumpkin/src/entity/projectile/wind_charge.rs +++ b/pumpkin/src/entity/projectile/wind_charge.rs @@ -16,8 +16,6 @@ use crate::{ }; const EXPLOSION_POWER: f32 = 1.2; -// square(3.5) -const MAX_RENDER_DISTANCE_WHEN_NEWLY_SPAWNED: f32 = 3.5 * 3.5; const DEFAULT_DEFLECT_COOLDOWN: u8 = 5; pub struct WindChargeEntity { @@ -50,28 +48,6 @@ impl WindChargeEntity { .await; } - pub fn should_render(&self, distance: f64) -> bool { - if self.get_entity().age.load(Ordering::Relaxed) < 2 - && distance < f64::from(MAX_RENDER_DISTANCE_WHEN_NEWLY_SPAWNED) - { - return false; - } - - let mut average_side_length = self - .get_entity() - .bounding_box - .load() - .get_average_side_length(); - - if average_side_length.is_nan() { - average_side_length = 1.0; - } - - // TODO: IMPLEMENT renderDistanceMultiplier instead of the 1.0 - average_side_length *= 64.0 * 1.0; - distance < average_side_length * average_side_length - } - pub fn deflect( &mut self, deflection: &ProjectileDeflectionType, diff --git a/pumpkin/src/lib.rs b/pumpkin/src/lib.rs index 3545316bc..29dd0ac13 100644 --- a/pumpkin/src/lib.rs +++ b/pumpkin/src/lib.rs @@ -191,7 +191,6 @@ impl PumpkinServer { pub fn log_info(&self, message: &str) { tracing::info!(target: "plugin", "{}", message); } - #[expect(clippy::if_then_some_else_none)] pub async fn new( basic_config: BasicConfiguration, advanced_config: AdvancedConfiguration, diff --git a/pumpkin/src/server/mod.rs b/pumpkin/src/server/mod.rs index 063cd09ad..a99f3f63b 100644 --- a/pumpkin/src/server/mod.rs +++ b/pumpkin/src/server/mod.rs @@ -420,7 +420,6 @@ impl Server { PlayerLoginEvent::new(player.clone(), TextComponent::text("You have been kicked from the server")); 'after: { player.screen_handler_sync_handler.store_player(player.clone()).await; - #[expect(clippy::if_then_some_else_none)] if world .add_player(player.clone()) .is_ok() {