From 16729f38cb6440f3ad586b70e9f83a5110550b43 Mon Sep 17 00:00:00 2001 From: suprohub Date: Mon, 6 Jan 2025 11:40:10 +0400 Subject: [PATCH 1/2] add confg --- pumpkin-config/src/generator.rs | 10 ++++++++++ pumpkin-config/src/lib.rs | 5 +++++ pumpkin-world/src/generation/mod.rs | 13 ++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 pumpkin-config/src/generator.rs diff --git a/pumpkin-config/src/generator.rs b/pumpkin-config/src/generator.rs new file mode 100644 index 000000000..b9b5afd29 --- /dev/null +++ b/pumpkin-config/src/generator.rs @@ -0,0 +1,10 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +pub enum Generator { + Test, + Plains, + Superflat, + Void, + Custom, +} diff --git a/pumpkin-config/src/lib.rs b/pumpkin-config/src/lib.rs index 4e6625ccc..d39408c1b 100644 --- a/pumpkin-config/src/lib.rs +++ b/pumpkin-config/src/lib.rs @@ -1,3 +1,4 @@ +use generator::Generator; use log::warn; use logging::LoggingConfig; use pumpkin_core::{Difficulty, GameMode, PermissionLvl}; @@ -25,6 +26,7 @@ pub use pvp::PVPConfig; pub use server_links::ServerLinksConfig; mod commands; +pub mod generator; pub mod op; mod pvp; @@ -63,6 +65,8 @@ pub struct BasicConfiguration { pub server_address: SocketAddr, /// The seed for world generation. pub seed: String, + /// The world generator for generation. + pub generator: Generator, /// The maximum number of players allowed on the server. Specifying `0` disables the limit. pub max_players: u32, /// The maximum view distance for players. @@ -99,6 +103,7 @@ impl Default for BasicConfiguration { Self { server_address: SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 25565), seed: "".to_string(), + generator: Generator::Test, max_players: 100000, view_distance: NonZeroU8::new(10).unwrap(), simulation_distance: NonZeroU8::new(10).unwrap(), diff --git a/pumpkin-world/src/generation/mod.rs b/pumpkin-world/src/generation/mod.rs index 3a9019653..37579de9f 100644 --- a/pumpkin-world/src/generation/mod.rs +++ b/pumpkin-world/src/generation/mod.rs @@ -17,16 +17,23 @@ mod seed; pub use generator::WorldGenerator; use implementation::{ //overworld::biome::plains::PlainsGenerator, + overworld::biome::plains::PlainsGenerator, test::{TestBiomeGenerator, TestGenerator, TestTerrainGenerator}, }; +use pumpkin_config::{generator::Generator, BASIC_CONFIG}; pub use seed::Seed; use generator::GeneratorInit; pub fn get_world_gen(seed: Seed) -> Box { - // TODO decide which WorldGenerator to pick based on config. - //Box::new(PlainsGenerator::new(seed)) - Box::new(TestGenerator::::new(seed)) + match BASIC_CONFIG.generator { + Generator::Test => { + Box::new(TestGenerator::::new(seed)) + } + Generator::Plains => Box::new(PlainsGenerator::new(seed)), + Generator::Void => todo!(), + _ => todo!(), + } } pub mod section_coords { From 9f4cdc5584953f1f843f40fc255ce5eb526010f7 Mon Sep 17 00:00:00 2001 From: suprohub Date: Mon, 6 Jan 2025 12:03:35 +0400 Subject: [PATCH 2/2] sup --- pumpkin-config/src/generator.rs | 2 +- pumpkin-world/src/generation/mod.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pumpkin-config/src/generator.rs b/pumpkin-config/src/generator.rs index b9b5afd29..be073ef73 100644 --- a/pumpkin-config/src/generator.rs +++ b/pumpkin-config/src/generator.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] pub enum Generator { Test, - Plains, + BeautifulPlains, Superflat, Void, Custom, diff --git a/pumpkin-world/src/generation/mod.rs b/pumpkin-world/src/generation/mod.rs index 37579de9f..054c0271f 100644 --- a/pumpkin-world/src/generation/mod.rs +++ b/pumpkin-world/src/generation/mod.rs @@ -30,8 +30,7 @@ pub fn get_world_gen(seed: Seed) -> Box { Generator::Test => { Box::new(TestGenerator::::new(seed)) } - Generator::Plains => Box::new(PlainsGenerator::new(seed)), - Generator::Void => todo!(), + Generator::BeautifulPlains => Box::new(PlainsGenerator::new(seed)), _ => todo!(), } }