Skip to content

Commit

Permalink
Added feature to fill ground with stone
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg4260 committed Feb 3, 2025
1 parent 6b52785 commit 622edaf
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 5 deletions.
8 changes: 8 additions & 0 deletions gui-src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ button:hover {
margin: 15px 0;
}

#fillground-toggle {
accent-color: #fecc44;
}

.fillground-toggle-container, .scale-slider-container {
margin: 15px 0;
}

#winter-toggle {
accent-color: #fecc44;
}
Expand Down
6 changes: 5 additions & 1 deletion gui-src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ <h2 data-localize="customization_settings">Customization Settings</h2>
<label for="terrain-toggle" data-localize="terrain">Terrain:</label>
<input type="checkbox" id="terrain-toggle" name="terrain-toggle">
</div>

<!-- Fill ground Toggle Button -->
<div class="fillground-toggle-container">
<label for="fillground-toggle" data-localize="fillground">Fill Ground:</label>
<input type="checkbox" id="fillground-toggle" name="fillground-toggle">
</div>
<!-- Winter Mode Toggle Button -->
<div class="winter-toggle-container">
<label for="winter-toggle" data-localize="winter_mode">Winter Mode:</label>
Expand Down
4 changes: 3 additions & 1 deletion gui-src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ async function startGeneration() {

var terrain = document.getElementById("terrain-toggle").checked;
var winter_mode = document.getElementById("winter-toggle").checked;
var fill_ground = document.getElementById("fillground-toggle").checked;
var scale = parseFloat(document.getElementById("scale-value-slider").value);
var floodfill_timeout = parseInt(document.getElementById("floodfill-timeout").value, 10);
var ground_level = parseInt(document.getElementById("ground-level").value, 10);
Expand All @@ -496,7 +497,8 @@ async function startGeneration() {
groundLevel: ground_level,
winterMode: winter_mode,
floodfillTimeout: floodfill_timeout,
terrainEnabled: terrain
terrainEnabled: terrain,
fillgroundEnabled: fill_ground
});

console.log("Generation process started.");
Expand Down
4 changes: 3 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ pub struct Args {
/// Enable terrain (optional)
#[arg(long, default_value_t = false, action = clap::ArgAction::SetFalse)]
pub terrain: bool,

/// Enable filling ground (optional)
#[arg(long, default_value_t = false, action = clap::ArgAction::SetFalse)]
pub fillground: bool,
/// Enable debug mode (optional)
#[arg(long, default_value_t = false, action = clap::ArgAction::SetTrue)]
pub debug: bool,
Expand Down
12 changes: 10 additions & 2 deletions src/data_processing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::args::Args;
use crate::block_definitions::{DIRT, GRASS_BLOCK, SNOW_BLOCK};
use crate::block_definitions::{BEDROCK, DIRT, GRASS_BLOCK, SNOW_BLOCK, STONE};
use crate::cartesian::XZPoint;
use crate::element_processing::*;
use crate::ground::Ground;
Expand All @@ -9,7 +9,7 @@ use crate::world_editor::WorldEditor;
use colored::Colorize;
use indicatif::{ProgressBar, ProgressStyle};

const MIN_Y: i32 = -64;
pub const MIN_Y: i32 = -64;

pub fn generate_world(
elements: Vec<ProcessedElement>,
Expand Down Expand Up @@ -170,6 +170,13 @@ pub fn generate_world(
editor.set_block(groundlayer_block, x, max_y, z, None, None);
editor.set_block(DIRT, x, max_y - 1, z, None, None);
editor.set_block(DIRT, x, max_y - 2, z, None, None);
// Fill underground with stone
if args.fillground {
for y in MIN_Y + 1..max_y - 2 {
editor.set_block(STONE, x, y, z, None, None);
}
}
editor.set_block(BEDROCK, x, MIN_Y, z, None, Some(&[BEDROCK]));

block_counter += 1;
if block_counter % batch_size == 0 {
Expand All @@ -196,6 +203,7 @@ pub fn generate_world(
let ground_level = ground.level(XZPoint::new(x, z));
editor.set_block(groundlayer_block, x, ground_level, z, None, None);
editor.set_block(DIRT, x, ground_level - 1, z, None, None);
editor.set_block(BEDROCK, x, MIN_Y, z, None, Some(&[BEDROCK]));

block_counter += 1;
if block_counter % batch_size == 0 {
Expand Down
7 changes: 7 additions & 0 deletions src/element_processing/landuse.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::args::Args;
use crate::block_definitions::*;
use crate::cartesian::XZPoint;
use crate::data_processing::MIN_Y;
use crate::element_processing::tree::create_tree;
use crate::floodfill::flood_fill_area;
use crate::ground::Ground;
Expand Down Expand Up @@ -363,6 +364,12 @@ pub fn generate_landuse(
if random_choice < 5 {
editor.set_block(ore_block, x, ground_level, z, Some(&[STONE]), None);
}
// Fill everything with stone so dirt won't be there
if args.fillground {
for y in MIN_Y + 1..ground_level {
editor.set_block(STONE, x, y, z, None, None);
}
}
}
}
_ => {}
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ fn gui_start_generation(
winter_mode: bool,
floodfill_timeout: u64,
terrain_enabled: bool,
fillground_enabled: bool,
) -> Result<(), String> {
tauri::async_runtime::spawn(async move {
if let Err(e) = tokio::task::spawn_blocking(move || {
Expand Down Expand Up @@ -427,6 +428,7 @@ fn gui_start_generation(
scale: world_scale,
ground_level,
terrain: terrain_enabled,
fillground: fillground_enabled,
winter: winter_mode,
debug: false,
timeout: Some(std::time::Duration::from_secs(floodfill_timeout)),
Expand Down

0 comments on commit 622edaf

Please sign in to comment.