Skip to content

Commit

Permalink
Add empty world generator as a config option (feather-rs#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iaiao committed Jan 18, 2022
1 parent c754e4f commit 3779032
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion feather/server/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ hash = ""
# The name of the directory containing the world.
name = "world"
# The generator to use if the world does not exist.
# Implemented values are: default, flat
# Implemented values are: default, flat, void
generator = "default"
# The seed to use if the world does not exist.
# Leaving this value empty will generate a random seed.
Expand Down
3 changes: 2 additions & 1 deletion feather/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use common::{Game, TickLoop, World};
use ecs::SystemExecutor;
use feather_server::{config::Config, Server};
use plugin_host::PluginManager;
use worldgen::{ComposableGenerator, SuperflatWorldGenerator, WorldGenerator};
use worldgen::{ComposableGenerator, SuperflatWorldGenerator, VoidWorldGenerator, WorldGenerator};

mod logging;

Expand Down Expand Up @@ -70,6 +70,7 @@ fn init_world_source(game: &mut Game, config: &Config) {
"flat" => Arc::new(SuperflatWorldGenerator::new(
SuperflatGeneratorOptions::default(),
)),
"void" => Arc::new(VoidWorldGenerator),
_ => Arc::new(ComposableGenerator::default_with_seed(seed)),
};
game.world = World::with_gen_and_path(generator, config.world.name.clone());
Expand Down
8 changes: 4 additions & 4 deletions feather/worldgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pub trait WorldGenerator: Send + Sync {
fn generate_chunk(&self, position: ChunkPosition) -> Chunk;
}

pub struct EmptyWorldGenerator {}
pub struct VoidWorldGenerator;

impl WorldGenerator for EmptyWorldGenerator {
impl WorldGenerator for VoidWorldGenerator {
fn generate_chunk(&self, position: ChunkPosition) -> Chunk {
Chunk::new(position)
}
Expand Down Expand Up @@ -408,9 +408,9 @@ mod tests {
}

#[test]
pub fn test_worldgen_empty() {
pub fn test_worldgen_void() {
let chunk_pos = ChunkPosition { x: 1, z: 2 };
let generator = EmptyWorldGenerator {};
let generator = VoidWorldGenerator;
let chunk = generator.generate_chunk(chunk_pos);

// No sections have been generated
Expand Down

0 comments on commit 3779032

Please sign in to comment.