diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/settings/ClimateSettings.java b/TerraForgedCore/src/main/java/com/terraforged/core/settings/ClimateSettings.java new file mode 100644 index 0000000..b6619c4 --- /dev/null +++ b/TerraForgedCore/src/main/java/com/terraforged/core/settings/ClimateSettings.java @@ -0,0 +1,54 @@ +package com.terraforged.core.settings; + +import com.terraforged.core.util.serialization.annotation.Comment; +import com.terraforged.core.util.serialization.annotation.Range; +import com.terraforged.core.util.serialization.annotation.Serializable; +import me.dags.noise.Module; +import me.dags.noise.Source; + +@Serializable +public class ClimateSettings { + + public RangeValue moisture = new RangeValue(0, 1F); + + public RangeValue temperature = new RangeValue(0, 1F); + + @Serializable + public static class RangeValue { + + @Range(min = 0F, max = 1F) + @Comment("The lower limit of the range") + public float min; + + @Range(min = 0F, max = 1F) + @Comment("The upper limit of the range") + public float max; + + public RangeValue() { + this(0, 1); + } + + public RangeValue(float min, float max) { + this.min = min; + this.max = max; + } + + public float getMin() { + return Math.min(min, max); + } + + public float getMax() { + return Math.max(min, max); + } + + public Module clamp(Module module) { + float min = getMin(); + float max = getMax(); + float range = max - min; + if (range == 0) { + return Source.constant(min); + } + return module.scale(range).bias(min); + } + } +} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/settings/Settings.java b/TerraForgedCore/src/main/java/com/terraforged/core/settings/Settings.java index 44ad2b9..d768788 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/settings/Settings.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/settings/Settings.java @@ -32,6 +32,8 @@ public class Settings { public GeneratorSettings generator = new GeneratorSettings(); + public ClimateSettings climate = new ClimateSettings(); + public RiverSettings rivers = new RiverSettings(); public FilterSettings filters = new FilterSettings(); diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java index 1fc5a23..accf2ee 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/Climate.java @@ -50,7 +50,7 @@ public class Climate { private final ClimateModule biomeNoise; public Climate(GeneratorContext context) { - this.biomeNoise = new ClimateModule(context.seed, context.settings.generator); + this.biomeNoise = new ClimateModule(context.seed, context.settings); this.treeLine = Source.perlin(context.seed.next(), context.settings.generator.biome.biomeSize * 2, 1) .scale(0.1).bias(0.4); diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/ClimateModule.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/ClimateModule.java index 7824411..4530609 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/ClimateModule.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/climate/ClimateModule.java @@ -26,7 +26,7 @@ package com.terraforged.core.world.climate; import com.terraforged.core.cell.Cell; -import com.terraforged.core.settings.GeneratorSettings; +import com.terraforged.core.settings.Settings; import com.terraforged.core.util.Seed; import com.terraforged.core.world.biome.BiomeType; import com.terraforged.core.world.terrain.Terrain; @@ -51,8 +51,8 @@ public class ClimateModule { private final Module moisture; private final Module temperature; - public ClimateModule(Seed seed, GeneratorSettings settings) { - int biomeSize = settings.biome.biomeSize; + public ClimateModule(Seed seed, Settings settings) { + int biomeSize = settings.generator.biome.biomeSize; // todo - better solution (reduces the amount that temp/moist grows with biome size) int tempScaler = biomeSize > 500 ? 8 : 10; @@ -63,23 +63,25 @@ public class ClimateModule { int temperatureSize = tempScaler * biomeSize; int moistScale = NoiseUtil.round(moistureSize * biomeFreq); int tempScale = NoiseUtil.round(temperatureSize * biomeFreq); - int warpScale = settings.biome.biomeWarpScale; + int warpScale = settings.generator.biome.biomeWarpScale; this.seed = seed.next(); this.edgeClamp = 1F; this.edgeScale = 1 / edgeClamp; this.biomeFreq = 1F / biomeSize; - this.warpStrength = settings.biome.biomeWarpStrength; + this.warpStrength = settings.generator.biome.biomeWarpStrength; this.warpX = Source.perlin(seed.next(), warpScale, 2).bias(-0.5); this.warpZ = Source.perlin(seed.next(), warpScale, 2).bias(-0.5); - this.moisture = Source.simplex(seed.next(), moistScale, 2) - .clamp(0.15, 0.85).map(0, 1) + Module moisture = Source.simplex(seed.next(), moistScale, 2).clamp(0.15, 0.85).map(0, 1); + this.moisture = settings.climate.moisture.clamp(moisture) .warp(seed.next(), moistScale / 2, 1, moistScale / 4D) .warp(seed.next(), moistScale / 6, 2, moistScale / 12D); - Module temperature = Source.sin(tempScale, Source.constant(0.9)).clamp(0.05, 0.95).map(0, 1); - this.temperature = new Compressor(temperature, 0.1F, 0.2F) + Module temperature = Source.sin(tempScale, Source.constant(0.9)) + .clamp(0.05, 0.95).map(0, 1); + + this.temperature = new Compressor(settings.climate.temperature.clamp(temperature), 0.1F, 0.2F) .warp(seed.next(), tempScale * 4, 2, tempScale * 4) .warp(seed.next(), tempScale, 1, tempScale) .warp(seed.next(), tempScale / 8, 1, tempScale / 8D); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java index 27cacd3..14b3f49 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java @@ -27,6 +27,7 @@ package com.terraforged.mod.gui; import com.terraforged.mod.gui.element.TerraButton; import com.terraforged.mod.gui.element.TerraLabel; +import com.terraforged.mod.gui.page.ClimatePage; import com.terraforged.mod.gui.page.FeaturePage; import com.terraforged.mod.gui.page.FilterPage; import com.terraforged.mod.gui.page.GeneratorPage; @@ -60,6 +61,7 @@ public class SettingsScreen extends OverlayScreen { this.parent = parent; this.pages = new Page[]{ new GeneratorPage(settings, preview), + new ClimatePage(settings, preview), new TerrainPage(settings, preview), new RiverPage(settings, preview), new FilterPage(settings, preview), diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/ClimatePage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/ClimatePage.java new file mode 100644 index 0000000..940c15e --- /dev/null +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/page/ClimatePage.java @@ -0,0 +1,68 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.mod.gui.page; + +import com.terraforged.core.settings.Settings; +import com.terraforged.mod.gui.OverlayScreen; +import com.terraforged.mod.gui.preview.PreviewPage; +import com.terraforged.mod.util.nbt.NBTHelper; +import net.minecraft.nbt.CompoundNBT; + +public class ClimatePage extends BasePage { + + private final Settings settings; + private final PreviewPage preview; + private final CompoundNBT climateSettings; + + public ClimatePage(Settings settings, PreviewPage preview) { + this.settings = settings; + this.preview = preview; + this.climateSettings = NBTHelper.serialize(settings.climate); + } + + @Override + public String getTitle() { + return "Climate Settings"; + } + + @Override + public void save() { + NBTHelper.deserialize(climateSettings, settings.climate); + } + + @Override + public void init(OverlayScreen parent) { + Column center = getColumn(0); + center.scrollPane.setScrollAmount(0D); + addElements(0, 0, center, climateSettings, true, center.scrollPane::addButton, this::update); + } + + @Override + protected void update() { + super.update(); + preview.apply(settings -> NBTHelper.deserialize(climateSettings, settings.climate)); + } +}