From d0d0f35a94f2d7e0d5cdefd9e222a95083712c9e Mon Sep 17 00:00:00 2001 From: Snowiiii Date: Sun, 8 Dec 2024 23:59:52 +0100 Subject: [PATCH] Some minor improvements --- Cargo.toml | 2 +- pumpkin-protocol/src/bytebuf/deserializer.rs | 4 - .../src/client/play/c_command_suggestions.rs | 6 +- pumpkin-registry/Cargo.toml | 2 +- pumpkin-world/Cargo.toml | 1 - .../src/world_gen/noise/density/mod.rs | 720 ++++++++++-------- pumpkin-world/src/world_gen/noise/router.rs | 18 +- pumpkin/Cargo.toml | 4 +- pumpkin/src/client/mod.rs | 2 - pumpkin/src/command/args/arg_bossbar_color.rs | 2 +- pumpkin/src/command/args/arg_bossbar_style.rs | 2 +- pumpkin/src/command/args/arg_command.rs | 2 +- .../src/command/args/arg_resource_location.rs | 19 +- pumpkin/src/command/commands/cmd_help.rs | 15 +- pumpkin/src/command/dispatcher.rs | 28 +- 15 files changed, 429 insertions(+), 398 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ae9ee6f2b..dd3e6ba0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ debug = true [workspace.dependencies] log = "0.4" -tokio = { version = "1.41", features = [ +tokio = { version = "1.42", features = [ "fs", "io-util", "macros", diff --git a/pumpkin-protocol/src/bytebuf/deserializer.rs b/pumpkin-protocol/src/bytebuf/deserializer.rs index 120fdaee5..829eb515e 100644 --- a/pumpkin-protocol/src/bytebuf/deserializer.rs +++ b/pumpkin-protocol/src/bytebuf/deserializer.rs @@ -11,12 +11,8 @@ pub struct Deserializer<'a> { #[derive(Debug, Error)] pub enum DeserializerError { - #[error("Unknown Packet")] - UnknownPacket, #[error("serializer error {0}")] Message(String), - #[error("Stdio error {0}")] - Stdio(std::io::Error), } impl de::Error for DeserializerError { diff --git a/pumpkin-protocol/src/client/play/c_command_suggestions.rs b/pumpkin-protocol/src/client/play/c_command_suggestions.rs index b3dd4c174..fae9b04f3 100644 --- a/pumpkin-protocol/src/client/play/c_command_suggestions.rs +++ b/pumpkin-protocol/src/client/play/c_command_suggestions.rs @@ -34,7 +34,7 @@ impl ClientPacket for CCommandSuggestions<'_> { bytebuf.put_var_int(&self.length); bytebuf.put_list(&self.matches, |bytebuf, suggestion| { - bytebuf.put_string(suggestion.suggestion.as_str()); + bytebuf.put_string(suggestion.suggestion); bytebuf.put_bool(suggestion.tooltip.is_some()); if let Some(tooltip) = &suggestion.tooltip { bytebuf.put_slice(&tooltip.encode()); @@ -45,12 +45,12 @@ impl ClientPacket for CCommandSuggestions<'_> { #[derive(PartialEq, Eq, Hash, Debug)] pub struct CommandSuggestion<'a> { - pub suggestion: String, + pub suggestion: &'a str, pub tooltip: Option>, } impl<'a> CommandSuggestion<'a> { - pub fn new(suggestion: String, tooltip: Option>) -> Self { + pub fn new(suggestion: &'a str, tooltip: Option>) -> Self { Self { suggestion, tooltip, diff --git a/pumpkin-registry/Cargo.toml b/pumpkin-registry/Cargo.toml index 929a7e8e6..3d55b6bb7 100644 --- a/pumpkin-registry/Cargo.toml +++ b/pumpkin-registry/Cargo.toml @@ -8,7 +8,7 @@ pumpkin-protocol = { path = "../pumpkin-protocol" } pumpkin-nbt = { path = "../pumpkin-nbt" } pumpkin-core = { path = "../pumpkin-core" } -indexmap = { version = "2.6.0", features = ["serde"] } +indexmap = { version = "2.7.0", features = ["serde"] } serde.workspace = true serde_json.workspace = true diff --git a/pumpkin-world/Cargo.toml b/pumpkin-world/Cargo.toml index 36f798e61..18745f731 100644 --- a/pumpkin-world/Cargo.toml +++ b/pumpkin-world/Cargo.toml @@ -22,7 +22,6 @@ num-traits.workspace = true num-derive.workspace = true futures = "0.3" dashmap = "6.1.0" -lazy_static = "1.5.0" # Compression flate2 = "1.0" diff --git a/pumpkin-world/src/world_gen/noise/density/mod.rs b/pumpkin-world/src/world_gen/noise/density/mod.rs index f78c980d8..ecec83509 100644 --- a/pumpkin-world/src/world_gen/noise/density/mod.rs +++ b/pumpkin-world/src/world_gen/noise/density/mod.rs @@ -74,9 +74,7 @@ pub trait NoisePosImpl { } pub mod built_in_density_function { - use std::sync::Arc; - - use lazy_static::lazy_static; + use std::sync::{Arc, LazyLock}; use crate::world_gen::noise::built_in_noise_params::{self}; use crate::world_gen::positions::{MAX_COLUMN_HEIGHT, MIN_HEIGHT}; @@ -106,136 +104,153 @@ pub mod built_in_density_function { use super::weird::{RarityMapper, WierdScaledFunction}; - lazy_static! { - pub static ref ZERO: SharedComponentReference = ConstantFunction::new(0f64).into(); - pub static ref TEN: SharedComponentReference = ConstantFunction::new(10f64).into(); - pub static ref BLEND_ALPHA: SharedComponentReference = BlendAlphaFunction::INSTANCE.into(); - pub static ref BLEND_OFFSET: SharedComponentReference = - BlendOffsetFunction::INSTANCE.into(); - pub static ref Y: SharedComponentReference = YClampedFunction::new( + pub static ZERO: LazyLock = + LazyLock::new(|| ConstantFunction::new(0f64).into()); + pub static TEN: LazyLock = + LazyLock::new(|| ConstantFunction::new(10f64).into()); + pub static BLEND_ALPHA: LazyLock = + LazyLock::new(|| BlendAlphaFunction::INSTANCE.into()); + pub static BLEND_OFFSET: LazyLock = + LazyLock::new(|| BlendOffsetFunction::INSTANCE.into()); + pub static Y: LazyLock = LazyLock::new(|| { + YClampedFunction::new( MIN_HEIGHT * 2, MAX_COLUMN_HEIGHT as i32 * 2, (MIN_HEIGHT * 2) as f64, - ((MAX_COLUMN_HEIGHT as i32) * 2) as f64 + ((MAX_COLUMN_HEIGHT as i32) * 2) as f64, ) - .into(); - pub static ref SHIFT_X: SharedComponentReference = + .into() + }); + pub static SHIFT_X: LazyLock = LazyLock::new(|| { + WrapperFunction::::new( WrapperFunction::::new( - WrapperFunction::::new( - ShiftAFunction::new(Arc::new(InternalNoise::new( - &built_in_noise_params::OFFSET, - None - ))) - .into(), - WrapperType::Cache2D - ) + ShiftAFunction::new(Arc::new(InternalNoise::new( + &built_in_noise_params::OFFSET, + None, + ))) .into(), - WrapperType::FlatCache + WrapperType::Cache2D, ) - .into(); - pub static ref SHIFT_Z: SharedComponentReference = + .into(), + WrapperType::FlatCache, + ) + .into() + }); + pub static SHIFT_Z: LazyLock = LazyLock::new(|| { + WrapperFunction::::new( WrapperFunction::::new( - WrapperFunction::::new( - ShiftBFunction::new(Arc::new(InternalNoise::new( - &built_in_noise_params::OFFSET, - None - ))) - .into(), - WrapperType::Cache2D - ) + ShiftBFunction::new(Arc::new(InternalNoise::new( + &built_in_noise_params::OFFSET, + None, + ))) .into(), - WrapperType::FlatCache + WrapperType::Cache2D, ) - .into(); - pub static ref BASE_3D_NOISE_OVERWORLD: SharedComponentReference = - InterpolatedNoiseFunction::create_base_3d_noise_function( - 0.25f64, 0.125f64, 80f64, 160f64, 8f64 + .into(), + WrapperType::FlatCache, + ) + .into() + }); + pub static BASE_3D_NOISE_OVERWORLD: LazyLock = LazyLock::new(|| { + InterpolatedNoiseFunction::create_base_3d_noise_function( + 0.25f64, 0.125f64, 80f64, 160f64, 8f64, + ) + .into() + }); + pub static BASE_3D_NOISE_NETHER: LazyLock = LazyLock::new(|| { + InterpolatedNoiseFunction::create_base_3d_noise_function( + 0.25f64, 0.375f64, 80f64, 60f64, 8f64, + ) + .into() + }); + pub static BASE_3D_NOISE_END: LazyLock = LazyLock::new(|| { + InterpolatedNoiseFunction::create_base_3d_noise_function( + 0.25f64, 0.25f64, 80f64, 160f64, 4f64, + ) + .into() + }); + pub static CONTINENTS_OVERWORLD: LazyLock = LazyLock::new(|| { + WrapperFunction::::new( + ShiftedNoiseFunction::< + NoEnvironment, + SharedComponentReference, + SharedComponentReference, + SharedComponentReference, + >::new( + SHIFT_X.clone(), + ZERO.clone(), + SHIFT_Z.clone(), + 0.25f64, + 0f64, + Arc::new(InternalNoise::new( + &built_in_noise_params::CONTINENTALNESS, + None, + )), ) - .into(); - pub static ref BASE_3D_NOISE_NETHER: SharedComponentReference = - InterpolatedNoiseFunction::create_base_3d_noise_function( - 0.25f64, 0.375f64, 80f64, 60f64, 8f64 + .into(), + WrapperType::FlatCache, + ) + .into() + }); + pub static EROSION_OVERWORLD: LazyLock = LazyLock::new(|| { + WrapperFunction::::new( + ShiftedNoiseFunction::< + NoEnvironment, + SharedComponentReference, + SharedComponentReference, + SharedComponentReference, + >::new( + SHIFT_X.clone(), + ZERO.clone(), + SHIFT_Z.clone(), + 0.25f64, + 0f64, + Arc::new(InternalNoise::new(&built_in_noise_params::EROSION, None)), ) - .into(); - pub static ref BASE_3D_NOISE_END: SharedComponentReference = - InterpolatedNoiseFunction::create_base_3d_noise_function( - 0.25f64, 0.25f64, 80f64, 160f64, 4f64 + .into(), + WrapperType::FlatCache, + ) + .into() + }); + pub static RIDGES_OVERWORLD: LazyLock = LazyLock::new(|| { + WrapperFunction::::new( + ShiftedNoiseFunction::< + NoEnvironment, + SharedComponentReference, + SharedComponentReference, + SharedComponentReference, + >::new( + SHIFT_X.clone(), + ZERO.clone(), + SHIFT_Z.clone(), + 0.25f64, + 0f64, + Arc::new(InternalNoise::new(&built_in_noise_params::RIDGE, None)), ) - .into(); - pub static ref CONTINENTS_OVERWORLD: SharedComponentReference = - WrapperFunction::::new( - ShiftedNoiseFunction::< - NoEnvironment, - SharedComponentReference, - SharedComponentReference, - SharedComponentReference, - >::new( - SHIFT_X.clone(), - ZERO.clone(), - SHIFT_Z.clone(), - 0.25f64, - 0f64, - Arc::new(InternalNoise::new( - &built_in_noise_params::CONTINENTALNESS, - None - )) - ) - .into(), - WrapperType::FlatCache - ) - .into(); - pub static ref EROSION_OVERWORLD: SharedComponentReference = - WrapperFunction::::new( - ShiftedNoiseFunction::< - NoEnvironment, - SharedComponentReference, - SharedComponentReference, - SharedComponentReference, - >::new( - SHIFT_X.clone(), - ZERO.clone(), - SHIFT_Z.clone(), - 0.25f64, - 0f64, - Arc::new(InternalNoise::new(&built_in_noise_params::EROSION, None)) - ) - .into(), - WrapperType::FlatCache - ) - .into(); - pub static ref RIDGES_OVERWORLD: SharedComponentReference = - WrapperFunction::::new( - ShiftedNoiseFunction::< - NoEnvironment, - SharedComponentReference, - SharedComponentReference, - SharedComponentReference, - >::new( - SHIFT_X.clone(), - ZERO.clone(), - SHIFT_Z.clone(), - 0.25f64, - 0f64, - Arc::new(InternalNoise::new(&built_in_noise_params::RIDGE, None)) - ) - .into(), - WrapperType::FlatCache - ) - .into(); - pub static ref RIDGES_FOLDED_OVERWORLD: SharedComponentReference = RIDGES_OVERWORLD + .into(), + WrapperType::FlatCache, + ) + .into() + }); + pub static RIDGES_FOLDED_OVERWORLD: LazyLock = LazyLock::new(|| { + RIDGES_OVERWORLD .clone() .abs() .add_const(-0.6666666666666666f64) .abs() .add_const(-0.3333333333333333f64) - .mul_const(-3f64); - static ref JAGGED_NOISE: SharedComponentReference = NoiseFunction::new( + .mul_const(-3f64) + }); + static JAGGED_NOISE: LazyLock = LazyLock::new(|| { + NoiseFunction::new( Arc::new(InternalNoise::new(&built_in_noise_params::JAGGED, None)), 1500f64, - 0f64 + 0f64, ) - .into(); - pub static ref OFFSET_OVERWORLD: SharedComponentReference = apply_blending( + .into() + }); + pub static OFFSET_OVERWORLD: LazyLock = LazyLock::new(|| { + apply_blending( ConstantFunction::new(-0.50375f32 as f64).add( SplineFunction::::new( create_offset_spline( @@ -244,13 +259,15 @@ pub mod built_in_density_function { RIDGES_FOLDED_OVERWORLD.clone(), false, ) - .into() + .into(), ) - .into() + .into(), ), BLEND_OFFSET.clone(), - ); - pub static ref FACTOR_OVERWORLD: SharedComponentReference = apply_blending( + ) + }); + pub static FACTOR_OVERWORLD: LazyLock = LazyLock::new(|| { + apply_blending( SplineFunction::::new( create_factor_spline( CONTINENTS_OVERWORLD.clone(), @@ -259,12 +276,14 @@ pub mod built_in_density_function { RIDGES_FOLDED_OVERWORLD.clone(), false, ) - .into() + .into(), ) .into(), TEN.clone(), - ); - pub static ref JAGGEDNESS_OVERWORLD: SharedComponentReference = apply_blending( + ) + }); + pub static JAGGEDNESS_OVERWORLD: LazyLock = LazyLock::new(|| { + apply_blending( SplineFunction::::new( create_jaggedness_spline( CONTINENTS_OVERWORLD.clone(), @@ -273,28 +292,31 @@ pub mod built_in_density_function { RIDGES_FOLDED_OVERWORLD.clone(), false, ) - .into() + .into(), ) .into(), ZERO.clone(), - ); - pub static ref DEPTH_OVERWORLD: SharedComponentReference = - YClampedFunction::new(-64, 320, 1.5f64, -1.5f64).add(OFFSET_OVERWORLD.clone()); - pub static ref SLOPED_CHEESE_OVERWORLD: SharedComponentReference = { - let density1 = JAGGEDNESS_OVERWORLD + ) + }); + pub static DEPTH_OVERWORLD: LazyLock = LazyLock::new(|| { + YClampedFunction::new(-64, 320, 1.5f64, -1.5f64).add(OFFSET_OVERWORLD.clone()) + }); + pub static SLOPED_CHEESE_OVERWORLD: LazyLock = LazyLock::new(|| { + let density1 = JAGGEDNESS_OVERWORLD + .clone() + .mul(JAGGED_NOISE.clone().half_negative()); + let density2 = ConstantFunction::new(4f64).mul( + DEPTH_OVERWORLD .clone() - .mul(JAGGED_NOISE.clone().half_negative()); - let density2 = ConstantFunction::new(4f64).mul( - DEPTH_OVERWORLD - .clone() - .add(density1) - .mul(FACTOR_OVERWORLD.clone()) - .quarter_negative(), - ); + .add(density1) + .mul(FACTOR_OVERWORLD.clone()) + .quarter_negative(), + ); - density2.add(BASE_3D_NOISE_OVERWORLD.clone()) - }; - pub static ref CONTINENTS_OVERWORLD_LARGE_BIOME: SharedComponentReference = + density2.add(BASE_3D_NOISE_OVERWORLD.clone()) + }); + pub static CONTINENTS_OVERWORLD_LARGE_BIOME: LazyLock = + LazyLock::new(|| { WrapperFunction::::new( ShiftedNoiseFunction::< NoEnvironment, @@ -309,14 +331,16 @@ pub mod built_in_density_function { 0f64, Arc::new(InternalNoise::new( &built_in_noise_params::CONTINENTALNESS_LARGE, - None - )) + None, + )), ) .into(), - WrapperType::FlatCache + WrapperType::FlatCache, ) - .into(); - pub static ref EROSION_OVERWORLD_LARGE_BIOME: SharedComponentReference = + .into() + }); + pub static EROSION_OVERWORLD_LARGE_BIOME: LazyLock = + LazyLock::new(|| { WrapperFunction::::new( ShiftedNoiseFunction::< NoEnvironment, @@ -331,60 +355,73 @@ pub mod built_in_density_function { 0f64, Arc::new(InternalNoise::new( &built_in_noise_params::EROSION_LARGE, - None - )) + None, + )), ) .into(), - WrapperType::FlatCache + WrapperType::FlatCache, ) - .into(); - pub static ref OFFSET_OVERWORLD_LARGE_BIOME: SharedComponentReference = apply_blending( - ConstantFunction::new(-0.50375f32 as f64).add( + .into() + }); + pub static OFFSET_OVERWORLD_LARGE_BIOME: LazyLock = + LazyLock::new(|| { + apply_blending( + ConstantFunction::new(-0.50375f32 as f64).add( + SplineFunction::::new( + create_offset_spline( + CONTINENTS_OVERWORLD_LARGE_BIOME.clone(), + EROSION_OVERWORLD_LARGE_BIOME.clone(), + RIDGES_FOLDED_OVERWORLD.clone(), + false, + ) + .into(), + ) + .into(), + ), + BLEND_OFFSET.clone(), + ) + }); + pub static FACTOR_OVERWORLD_LARGE_BIOME: LazyLock = + LazyLock::new(|| { + apply_blending( SplineFunction::::new( - create_offset_spline( + create_factor_spline( CONTINENTS_OVERWORLD_LARGE_BIOME.clone(), EROSION_OVERWORLD_LARGE_BIOME.clone(), + RIDGES_OVERWORLD.clone(), RIDGES_FOLDED_OVERWORLD.clone(), false, ) - .into() + .into(), ) - .into() - ), - BLEND_OFFSET.clone() - ); - pub static ref FACTOR_OVERWORLD_LARGE_BIOME: SharedComponentReference = apply_blending( - SplineFunction::::new( - create_factor_spline( - CONTINENTS_OVERWORLD_LARGE_BIOME.clone(), - EROSION_OVERWORLD_LARGE_BIOME.clone(), - RIDGES_OVERWORLD.clone(), - RIDGES_FOLDED_OVERWORLD.clone(), - false, - ) - .into() + .into(), + TEN.clone(), ) - .into(), - TEN.clone() - ); - pub static ref JAGGEDNESS_OVERWORLD_LARGE_BIOME: SharedComponentReference = apply_blending( - SplineFunction::::new( - create_jaggedness_spline( - CONTINENTS_OVERWORLD_LARGE_BIOME.clone(), - EROSION_OVERWORLD_LARGE_BIOME.clone(), - RIDGES_OVERWORLD.clone(), - RIDGES_FOLDED_OVERWORLD.clone(), - false, + }); + pub static JAGGEDNESS_OVERWORLD_LARGE_BIOME: LazyLock = + LazyLock::new(|| { + apply_blending( + SplineFunction::::new( + create_jaggedness_spline( + CONTINENTS_OVERWORLD_LARGE_BIOME.clone(), + EROSION_OVERWORLD_LARGE_BIOME.clone(), + RIDGES_OVERWORLD.clone(), + RIDGES_FOLDED_OVERWORLD.clone(), + false, + ) + .into(), ) - .into() + .into(), + ZERO.clone(), ) - .into(), - ZERO.clone() - ); - pub static ref DEPTH_OVERWORLD_LARGE_BIOME: SharedComponentReference = + }); + pub static DEPTH_OVERWORLD_LARGE_BIOME: LazyLock = + LazyLock::new(|| { YClampedFunction::new(-64, 320, 1.5f64, -1.5f64) - .add(OFFSET_OVERWORLD_LARGE_BIOME.clone()); - pub static ref SLOPED_CHEESE_OVERWORLD_LARGE_BIOME: SharedComponentReference = { + .add(OFFSET_OVERWORLD_LARGE_BIOME.clone()) + }); + pub static SLOPED_CHEESE_OVERWORLD_LARGE_BIOME: LazyLock = + LazyLock::new(|| { let density1 = JAGGEDNESS_OVERWORLD_LARGE_BIOME .clone() .mul(JAGGED_NOISE.clone().half_negative()); @@ -397,54 +434,65 @@ pub mod built_in_density_function { ); density2.add(BASE_3D_NOISE_OVERWORLD.clone()) - }; - pub static ref OFFSET_OVERWORLD_AMPLIFIED: SharedComponentReference = apply_blending( - ConstantFunction::new(-0.50375f32 as f64).add( + }); + pub static OFFSET_OVERWORLD_AMPLIFIED: LazyLock = + LazyLock::new(|| { + apply_blending( + ConstantFunction::new(-0.50375f32 as f64).add( + SplineFunction::::new( + create_offset_spline( + CONTINENTS_OVERWORLD.clone(), + EROSION_OVERWORLD.clone(), + RIDGES_FOLDED_OVERWORLD.clone(), + true, + ) + .into(), + ) + .into(), + ), + BLEND_OFFSET.clone(), + ) + }); + pub static FACTOR_OVERWORLD_AMPLIFIED: LazyLock = + LazyLock::new(|| { + apply_blending( SplineFunction::::new( - create_offset_spline( + create_factor_spline( CONTINENTS_OVERWORLD.clone(), EROSION_OVERWORLD.clone(), + RIDGES_OVERWORLD.clone(), RIDGES_FOLDED_OVERWORLD.clone(), - true + true, ) - .into() + .into(), ) - .into() - ), - BLEND_OFFSET.clone() - ); - pub static ref FACTOR_OVERWORLD_AMPLIFIED: SharedComponentReference = apply_blending( - SplineFunction::::new( - create_factor_spline( - CONTINENTS_OVERWORLD.clone(), - EROSION_OVERWORLD.clone(), - RIDGES_OVERWORLD.clone(), - RIDGES_FOLDED_OVERWORLD.clone(), - true - ) - .into() + .into(), + TEN.clone(), ) - .into(), - TEN.clone() - ); - pub static ref JAGGEDNESS_OVERWORLD_AMPLIFIED: SharedComponentReference = apply_blending( - SplineFunction::::new( - create_jaggedness_spline( - CONTINENTS_OVERWORLD.clone(), - EROSION_OVERWORLD.clone(), - RIDGES_OVERWORLD.clone(), - RIDGES_FOLDED_OVERWORLD.clone(), - true + }); + pub static JAGGEDNESS_OVERWORLD_AMPLIFIED: LazyLock = + LazyLock::new(|| { + apply_blending( + SplineFunction::::new( + create_jaggedness_spline( + CONTINENTS_OVERWORLD.clone(), + EROSION_OVERWORLD.clone(), + RIDGES_OVERWORLD.clone(), + RIDGES_FOLDED_OVERWORLD.clone(), + true, + ) + .into(), ) - .into() + .into(), + ZERO.clone(), ) - .into(), - ZERO.clone() - ); - pub static ref DEPTH_OVERWORLD_AMPLIFIED: SharedComponentReference = - YClampedFunction::new(-64, 320, 1.5f64, -1.5f64) - .add(OFFSET_OVERWORLD_AMPLIFIED.clone()); - pub static ref SLOPED_CHEESE_OVERWORLD_AMPLIFIED: SharedComponentReference = { + }); + pub static DEPTH_OVERWORLD_AMPLIFIED: LazyLock = + LazyLock::new(|| { + YClampedFunction::new(-64, 320, 1.5f64, -1.5f64).add(OFFSET_OVERWORLD_AMPLIFIED.clone()) + }); + pub static SLOPED_CHEESE_OVERWORLD_AMPLIFIED: LazyLock = + LazyLock::new(|| { let density1 = JAGGEDNESS_OVERWORLD_AMPLIFIED .clone() .mul(JAGGED_NOISE.clone().half_negative()); @@ -457,10 +505,11 @@ pub mod built_in_density_function { ); density2.add(BASE_3D_NOISE_OVERWORLD.clone()) - }; - pub static ref SLOPED_CHEESE_END: SharedComponentReference = - EndIslandFunction::new(0).add(BASE_3D_NOISE_END.clone()); - pub static ref CAVES_SPAGHETTI_ROUGHNESS_FUNCTION_OVERWORLD: SharedComponentReference = { + }); + pub static SLOPED_CHEESE_END: LazyLock = + LazyLock::new(|| EndIslandFunction::new(0).add(BASE_3D_NOISE_END.clone())); + pub static CAVES_SPAGHETTI_ROUGHNESS_FUNCTION_OVERWORLD: LazyLock = + LazyLock::new(|| { let function = NoiseFunction::new( Arc::new(InternalNoise::new( &built_in_noise_params::SPAGHETTI_ROUGHNESS, @@ -483,20 +532,23 @@ pub mod built_in_density_function { WrapperType::OnceCache, ) .into() - }; - pub static ref CAVES_SPAGHETTI_2D_THICKNESS_MODULAR_OVERWORLD: SharedComponentReference = + }); + pub static CAVES_SPAGHETTI_2D_THICKNESS_MODULAR_OVERWORLD: LazyLock = + LazyLock::new(|| { WrapperFunction::::new( noise_in_range( &built_in_noise_params::SPAGHETTI_2D_THICKNESS, 2f64, 1f64, -0.6f64, - -1.3f64 + -1.3f64, ), WrapperType::OnceCache, ) - .into(); - pub static ref CAVES_SPAGHETTI_2D_OVERWORLD: SharedComponentReference = { + .into() + }); + pub static CAVES_SPAGHETTI_2D_OVERWORLD: LazyLock = + LazyLock::new(|| { let function1 = NoiseFunction::new( Arc::new(InternalNoise::new( &built_in_noise_params::SPAGHETTI_2D_MODULATOR, @@ -534,8 +586,9 @@ pub mod built_in_density_function { let function7 = function2.add(function4.mul_const(0.083f64)); function7.max(function6).clamp(-1f64, 1f64) - }; - pub static ref CAVES_ENTRANCES_OVERWORLD: SharedComponentReference = { + }); + pub static CAVES_ENTRANCES_OVERWORLD: LazyLock = + LazyLock::new(|| { let function_ref: SharedComponentReference = WrapperFunction::::new( NoiseFunction::new( @@ -601,115 +654,114 @@ pub mod built_in_density_function { WrapperType::OnceCache, ) .into() - }; - pub static ref CAVES_NOODLE_OVERWORLD: SharedComponentReference = { - let function2 = vertical_range_choice( - Y.clone(), - NoiseFunction::new( - Arc::new(InternalNoise::new(&built_in_noise_params::NOODLE, None)), - 1f64, - 1f64, - ) - .into(), - -60, - 320, - -1, - ); - - let function3 = vertical_range_choice( - Y.clone(), - noise_in_range( - &built_in_noise_params::NOODLE_THICKNESS, - 1f64, - 1f64, - -0.05f64, - -0.1f64, - ), - -60, - 320, - 0, - ); - - let function4 = vertical_range_choice( - Y.clone(), - NoiseFunction::new( - Arc::new(InternalNoise::new( - &built_in_noise_params::NOODLE_RIDGE_A, - None, - )), - 2.6666666666666665f64, - 2.6666666666666665f64, - ) - .into(), - -60, - 320, - 0, - ); - - let function5 = vertical_range_choice( - Y.clone(), - NoiseFunction::new( - Arc::new(InternalNoise::new( - &built_in_noise_params::NOODLE_RIDGE_B, - None, - )), - 2.6666666666666665f64, - 2.6666666666666665f64, - ) - .into(), - -60, - 320, - 0, - ); - - let function6 = function4.abs().max(function5.abs()).mul_const(1.5f64); - - RangeFunction::< - NoEnvironment, - SharedComponentReference, - SharedComponentReference, - SharedComponentReference, - >::new( - function2, - -1000000f64, - 0f64, - ConstantFunction::new(64f64).into(), - function3.add(function6), + }); + pub static CAVES_NOODLE_OVERWORLD: LazyLock = LazyLock::new(|| { + let function2 = vertical_range_choice( + Y.clone(), + NoiseFunction::new( + Arc::new(InternalNoise::new(&built_in_noise_params::NOODLE, None)), + 1f64, + 1f64, ) - .into() - }; - pub static ref CAVES_PILLARS_OVERWORLD: SharedComponentReference = { - let function = NoiseFunction::new( - Arc::new(InternalNoise::new(&built_in_noise_params::PILLAR, None)), - 25f64, - 0.3f64, - ); + .into(), + -60, + 320, + -1, + ); - let function2 = noise_in_range( - &built_in_noise_params::PILLAR_RARENESS, + let function3 = vertical_range_choice( + Y.clone(), + noise_in_range( + &built_in_noise_params::NOODLE_THICKNESS, 1f64, 1f64, - 0f64, - -2f64, - ); + -0.05f64, + -0.1f64, + ), + -60, + 320, + 0, + ); - let function3 = noise_in_range( - &built_in_noise_params::PILLAR_THICKNESS, - 1f64, - 1f64, - 0f64, - 1.1f64, - ); - - let function4 = function.mul_const(2f64).add(function2); - - WrapperFunction::::new( - function4.mul(function3.cube()), - WrapperType::OnceCache, + let function4 = vertical_range_choice( + Y.clone(), + NoiseFunction::new( + Arc::new(InternalNoise::new( + &built_in_noise_params::NOODLE_RIDGE_A, + None, + )), + 2.6666666666666665f64, + 2.6666666666666665f64, ) - .into() - }; - } + .into(), + -60, + 320, + 0, + ); + + let function5 = vertical_range_choice( + Y.clone(), + NoiseFunction::new( + Arc::new(InternalNoise::new( + &built_in_noise_params::NOODLE_RIDGE_B, + None, + )), + 2.6666666666666665f64, + 2.6666666666666665f64, + ) + .into(), + -60, + 320, + 0, + ); + + let function6 = function4.abs().max(function5.abs()).mul_const(1.5f64); + + RangeFunction::< + NoEnvironment, + SharedComponentReference, + SharedComponentReference, + SharedComponentReference, + >::new( + function2, + -1000000f64, + 0f64, + ConstantFunction::new(64f64).into(), + function3.add(function6), + ) + .into() + }); + pub static CAVES_PILLARS_OVERWORLD: LazyLock = LazyLock::new(|| { + let function = NoiseFunction::new( + Arc::new(InternalNoise::new(&built_in_noise_params::PILLAR, None)), + 25f64, + 0.3f64, + ); + + let function2 = noise_in_range( + &built_in_noise_params::PILLAR_RARENESS, + 1f64, + 1f64, + 0f64, + -2f64, + ); + + let function3 = noise_in_range( + &built_in_noise_params::PILLAR_THICKNESS, + 1f64, + 1f64, + 0f64, + 1.1f64, + ); + + let function4 = function.mul_const(2f64).add(function2); + + WrapperFunction::::new( + function4.mul(function3.cube()), + WrapperType::OnceCache, + ) + .into() + }); } pub fn peaks_valleys_noise(variance: f32) -> f32 { diff --git a/pumpkin-world/src/world_gen/noise/router.rs b/pumpkin-world/src/world_gen/noise/router.rs index 0627d8c6b..782600fdf 100644 --- a/pumpkin-world/src/world_gen/noise/router.rs +++ b/pumpkin-world/src/world_gen/noise/router.rs @@ -1,6 +1,4 @@ -use std::sync::Arc; - -use lazy_static::lazy_static; +use std::sync::{Arc, LazyLock}; use crate::world_gen::{ noise::density::{ @@ -37,14 +35,12 @@ use super::{ }, }; -lazy_static! { - pub static ref OVERWORLD_NOISE_ROUTER: BaseRouter = - BaseRouter::create_surface_noise_router(false, false); - pub static ref OVERWORLD_NOISE_ROUTER_LARGE: BaseRouter = - BaseRouter::create_surface_noise_router(true, false); - pub static ref OVERWORLD_NOISE_ROUTER_AMPLIFIED: BaseRouter = - BaseRouter::create_surface_noise_router(false, true); -} +pub static OVERWORLD_NOISE_ROUTER: LazyLock = + LazyLock::new(|| BaseRouter::create_surface_noise_router(false, false)); +pub static OVERWORLD_NOISE_ROUTER_LARGE: LazyLock = + LazyLock::new(|| BaseRouter::create_surface_noise_router(true, false)); +pub static OVERWORLD_NOISE_ROUTER_AMPLIFIED: LazyLock = + LazyLock::new(|| BaseRouter::create_surface_noise_router(false, true)); pub struct BaseRouter { pub(crate) barrier: SharedComponentReference, diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index 476258e2b..38bd71902 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -64,11 +64,11 @@ sha2 = "0.10.8" # icon loading base64 = "0.22.1" -png = "0.17.14" +png = "0.17.15" # logging simple_logger = { version = "5.0.0", features = ["threads"] } -time = "0.3.36" +time = "0.3.37" # commands async-trait = "0.1.83" diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index d10eaec2c..1c8d1057c 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -404,7 +404,6 @@ impl Client { "Failed to handle client packet id {} in Status State", packet.id.0 ); - return Err(DeserializerError::UnknownPacket); } }; @@ -479,7 +478,6 @@ impl Client { "Failed to handle client packet id {} in Config State", packet.id.0 ); - return Err(DeserializerError::UnknownPacket); } }; Ok(()) diff --git a/pumpkin/src/command/args/arg_bossbar_color.rs b/pumpkin/src/command/args/arg_bossbar_color.rs index 976f796e9..94df5a4c8 100644 --- a/pumpkin/src/command/args/arg_bossbar_color.rs +++ b/pumpkin/src/command/args/arg_bossbar_color.rs @@ -57,7 +57,7 @@ impl ArgumentConsumer for BossbarColorArgumentConsumer { let colors = ["blue", "green", "pink", "purple", "red", "white", "yellow"]; let suggestions: Vec = colors .iter() - .map(|color| CommandSuggestion::new((*color).to_string(), None)) + .map(|color| CommandSuggestion::new(color, None)) .collect(); Ok(Some(suggestions)) } diff --git a/pumpkin/src/command/args/arg_bossbar_style.rs b/pumpkin/src/command/args/arg_bossbar_style.rs index 61d5f66e9..6111688be 100644 --- a/pumpkin/src/command/args/arg_bossbar_style.rs +++ b/pumpkin/src/command/args/arg_bossbar_style.rs @@ -61,7 +61,7 @@ impl ArgumentConsumer for BossbarStyleArgumentConsumer { ]; let suggestions: Vec = styles .iter() - .map(|style| CommandSuggestion::new((*style).to_string(), None)) + .map(|style| CommandSuggestion::new(style, None)) .collect(); Ok(Some(suggestions)) } diff --git a/pumpkin/src/command/args/arg_command.rs b/pumpkin/src/command/args/arg_command.rs index b65d9b0d5..ef9339778 100644 --- a/pumpkin/src/command/args/arg_command.rs +++ b/pumpkin/src/command/args/arg_command.rs @@ -59,7 +59,7 @@ impl ArgumentConsumer for CommandTreeArgumentConsumer { .commands .keys() .filter(|suggestion| suggestion.starts_with(input)) - .map(|suggestion| CommandSuggestion::new((*suggestion).to_string(), None)) + .map(|suggestion| CommandSuggestion::new(suggestion, None)) .collect(); Ok(Some(suggestions)) } diff --git a/pumpkin/src/command/args/arg_resource_location.rs b/pumpkin/src/command/args/arg_resource_location.rs index 7ed52f2b6..027815937 100644 --- a/pumpkin/src/command/args/arg_resource_location.rs +++ b/pumpkin/src/command/args/arg_resource_location.rs @@ -44,17 +44,18 @@ impl ArgumentConsumer for ResourceLocationArgumentConsumer { if !self.autocomplete { return Ok(None); } + // TODO - let suggestions = _server - .bossbars - .lock() - .await - .custom_bossbars - .keys() - .map(|suggestion| CommandSuggestion::new(suggestion.clone(), None)) - .collect(); + // let suggestions = server + // .bossbars + // .lock() + // .await + // .custom_bossbars + // .keys() + // .map(|suggestion| CommandSuggestion::new(suggestion, None)) + // .collect(); - Ok(Some(suggestions)) + Ok(None) } } diff --git a/pumpkin/src/command/commands/cmd_help.rs b/pumpkin/src/command/commands/cmd_help.rs index fe4fabbc7..8c714dcbc 100644 --- a/pumpkin/src/command/commands/cmd_help.rs +++ b/pumpkin/src/command/commands/cmd_help.rs @@ -50,10 +50,10 @@ impl CommandExecutor for CommandHelpExecutor { TextComponent::text_string("-".repeat((52 - header_text.len()) / 2) + " ") .color_named(NamedColor::Yellow), ) - .add_child(TextComponent::text_string(header_text.clone())) + .add_child(TextComponent::text(&header_text)) .add_child( TextComponent::text_string( - " ".to_owned().to_string() + &"-".repeat((52 - header_text.len()) / 2) + "\n", + " ".to_owned() + &"-".repeat((52 - header_text.len()) / 2) + "\n", ) .color_named(NamedColor::Yellow), ) @@ -168,13 +168,11 @@ impl CommandExecutor for BaseHelpExecutor { .color_named(NamedColor::Yellow), ) .add_child(arrow_left.clone()) - .add_child(TextComponent::text_string(header_text.clone())) + .add_child(TextComponent::text(&header_text)) .add_child(arrow_right.clone()) .add_child( TextComponent::text_string( - " ".to_owned().to_string() - + &"-".repeat((52 - header_text.len() - 3) / 2) - + "\n", + " ".to_owned() + &"-".repeat((52 - header_text.len() - 3) / 2) + "\n", ) .color_named(NamedColor::Yellow), ); @@ -201,18 +199,17 @@ impl CommandExecutor for BaseHelpExecutor { } let footer_text = format!(" Page {page}/{total_pages} "); - message = message .add_child( TextComponent::text_string("-".repeat((52 - footer_text.len() - 3) / 2) + " ") .color_named(NamedColor::Yellow), ) .add_child(arrow_left) - .add_child(TextComponent::text_string(footer_text.clone())) + .add_child(TextComponent::text(&footer_text)) .add_child(arrow_right) .add_child( TextComponent::text_string( - " ".to_owned().to_string() + &"-".repeat((52 - footer_text.len() - 3) / 2), + " ".to_owned() + &"-".repeat((52 - footer_text.len() - 3) / 2), ) .color_named(NamedColor::Yellow), ); diff --git a/pumpkin/src/command/dispatcher.rs b/pumpkin/src/command/dispatcher.rs index 46208d36d..6b25bb25b 100644 --- a/pumpkin/src/command/dispatcher.rs +++ b/pumpkin/src/command/dispatcher.rs @@ -14,7 +14,6 @@ use pumpkin_core::text::color::{Color, NamedColor}; use std::collections::{HashMap, HashSet}; #[derive(Debug)] -#[allow(dead_code)] pub(crate) enum CommandError { /// This error means that there was an error while parsing a previously consumed argument. /// That only happens when consumption is wrongly implemented, as it should ensure parsing may @@ -92,7 +91,7 @@ impl<'a> CommandDispatcher<'a> { let Some(key) = parts.next() else { return Vec::new(); }; - let raw_args: Vec<&str> = parts.rev().collect(); + let mut raw_args: Vec<&str> = parts.rev().collect(); let Ok(tree) = self.get_tree(key) else { return Vec::new(); @@ -103,15 +102,8 @@ impl<'a> CommandDispatcher<'a> { // try paths and collect the nodes that fail // todo: make this more fine-grained for path in tree.iter_paths() { - match Self::try_find_suggestions_on_path( - src, - server, - &path, - tree, - raw_args.clone(), - cmd, - ) - .await + match Self::try_find_suggestions_on_path(src, server, &path, tree, &mut raw_args, cmd) + .await { Err(InvalidConsumption(s)) => { log::error!("Error while parsing command \"{cmd}\": {s:?} was consumed, but couldn't be parsed"); @@ -137,7 +129,7 @@ impl<'a> CommandDispatcher<'a> { } let mut suggestions = Vec::from_iter(suggestions); - suggestions.sort_by(|a, b| a.suggestion.cmp(&b.suggestion)); + suggestions.sort_by(|a, b| a.suggestion.cmp(b.suggestion)); suggestions } @@ -153,13 +145,13 @@ impl<'a> CommandDispatcher<'a> { let key = parts .next() .ok_or(GeneralCommandIssue("Empty Command".to_string()))?; - let raw_args: Vec<&str> = parts.rev().collect(); + let mut raw_args: Vec<&str> = parts.rev().collect(); let tree = self.get_tree(key)?; // try paths until fitting path is found for path in tree.iter_paths() { - if Self::try_is_fitting_path(src, server, &path, tree, raw_args.clone()).await? { + if Self::try_is_fitting_path(src, server, &path, tree, &mut raw_args).await? { return Ok(()); } } @@ -193,7 +185,7 @@ impl<'a> CommandDispatcher<'a> { server: &'a Server, path: &[usize], tree: &CommandTree<'a>, - mut raw_args: RawArgs<'a>, + raw_args: &mut RawArgs<'a>, ) -> Result { let mut parsed_args: ConsumedArgs = HashMap::new(); @@ -213,7 +205,7 @@ impl<'a> CommandDispatcher<'a> { } } NodeType::Argument { consumer, name, .. } => { - match consumer.consume(src, server, &mut raw_args).await { + match consumer.consume(src, server, raw_args).await { Some(consumed) => { parsed_args.insert(name, consumed); } @@ -236,7 +228,7 @@ impl<'a> CommandDispatcher<'a> { server: &'a Server, path: &[usize], tree: &CommandTree<'a>, - mut raw_args: RawArgs<'a>, + raw_args: &mut RawArgs<'a>, input: &'a str, ) -> Result>>, CommandError> { let mut parsed_args: ConsumedArgs = HashMap::new(); @@ -252,7 +244,7 @@ impl<'a> CommandDispatcher<'a> { } } NodeType::Argument { consumer, name } => { - match consumer.consume(src, server, &mut raw_args).await { + match consumer.consume(src, server, raw_args).await { Some(consumed) => { parsed_args.insert(name, consumed); }