From f6acbac36de421519d51f62e3e95452c4f5d85de Mon Sep 17 00:00:00 2001 From: To_Craft Date: Wed, 13 Nov 2024 16:30:50 +0100 Subject: [PATCH] update noise codec --- .../1feb4c76a7f661f0310d685620450608f5a76bca | 8 ++--- .../map_based/zones/badlands_mountains.json | 6 ++-- .../java/dev/tocraft/ctgen/util/Noise.java | 35 ++++++++++--------- .../tocraft/ctgen/worldgen/MapSettings.java | 10 ++++++ .../ctgen/xtend/carver/NoiseCarver.java | 2 +- .../java/dev/tocraft/ctgen/zone/Zones.java | 2 +- gradle.properties | 2 +- 7 files changed, 39 insertions(+), 26 deletions(-) diff --git a/common/src/main/generated/.cache/1feb4c76a7f661f0310d685620450608f5a76bca b/common/src/main/generated/.cache/1feb4c76a7f661f0310d685620450608f5a76bca index d090505..409ad51 100644 --- a/common/src/main/generated/.cache/1feb4c76a7f661f0310d685620450608f5a76bca +++ b/common/src/main/generated/.cache/1feb4c76a7f661f0310d685620450608f5a76bca @@ -1,8 +1,8 @@ -// 1.21.3 2024-11-11T14:50:47.678304767 CTGen/Registries +// 1.21.3 2024-11-13T16:30:12.837407206 CTGen/Registries 1c5db5f4593f5fe97dbaf73bdbd63fe354a1185d data/ctgen/worldgen/map_based/zones/plains.json -6558d921786e5388da9f7f0366456041995fe2ff data/ctgen/worldgen/map_based/zones/badlands_mountains.json -3b20f0ae96f94e9a6aed34a730107acbf62fb269 data/ctgen/worldgen/map_based/zones/desert.json +cabb67dcfcfd601de0edcbb9a954770e0d9e5831 data/ctgen/worldgen/map_based/zones/badlands_mountains.json 97ccec666213300c0d55e330c49fad22e57e67f3 data/ctgen/worldgen/map_based/zones/stony_flats.json +3b20f0ae96f94e9a6aed34a730107acbf62fb269 data/ctgen/worldgen/map_based/zones/desert.json a0432f3114eaaeca727c52f71e231dc7abbc6852 data/ctgen/worldgen/map_based/zones/river.json 3f241a73909060b3e47b9c13ae766d4c59568f77 data/ctgen/worldgen/map_based/zones/lake.json 754af079c6a28d87c26f7c9eae41f7a8f35f8261 data/ctgen/worldgen/map_based/zones/forest.json @@ -11,8 +11,8 @@ a0432f3114eaaeca727c52f71e231dc7abbc6852 data/ctgen/worldgen/map_based/zones/riv 201b650496b9dddf4a2282c26e363e0b53718cc2 data/ctgen/worldgen/map_based/zones/ocean.json a7977c1dada7eba7b8061d96da7d062e5807b621 data/ctgen/worldgen/map_based/zones/badlands.json d27c95e66c317aba9c83e1f928dc572cc66e4aa8 data/ctgen/worldgen/map_based/zones/mountains.json -e6faad7f254549d65c1b04bcd3f2bdf8f4690e22 data/ctgen/worldgen/map_based/zones/hills.json c8b6815ea720a5bb4312e5805143598c40b31648 data/ctgen/worldgen/map_based/zones/frozen_river.json +e6faad7f254549d65c1b04bcd3f2bdf8f4690e22 data/ctgen/worldgen/map_based/zones/hills.json c43ae3888694ab66b65eef8cf94a5a041c974a98 data/ctgen/worldgen/map_based/zones/snowy_flats.json bf803d6e35a3e69a5e34361863c82113446e4690 data/ctgen/worldgen/map_based/zones/deep_ocean.json 7e4477583efb49a9ee6fcb344282ed1cefbc6c43 data/ctgen/worldgen/map_based/zones/frozen_lake.json diff --git a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/badlands_mountains.json b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/badlands_mountains.json index c156664..d49e6eb 100644 --- a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/badlands_mountains.json +++ b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/badlands_mountains.json @@ -9,9 +9,11 @@ "default": "minecraft:brown_concrete", "noise": { "octaves": [ - 1.0 + { + "amplitude": 1.0, + "frequency": 1.0 + } ], - "persistence": 1.0, "stretch": 50 }, "values": { diff --git a/common/src/main/java/dev/tocraft/ctgen/util/Noise.java b/common/src/main/java/dev/tocraft/ctgen/util/Noise.java index 6c24f4e..ce6dcbb 100644 --- a/common/src/main/java/dev/tocraft/ctgen/util/Noise.java +++ b/common/src/main/java/dev/tocraft/ctgen/util/Noise.java @@ -6,16 +6,22 @@ import java.util.List; -public record Noise(List octaves, double persistence, int stretchXZ, int stretchY) { - public static final Noise DEFAULT = new Noise(List.of(1f, 2f, 4f), 0.5f, 250); +public record Noise(List octaves, int stretchXZ, int stretchY) { + public record Octave(float frequency, float amplitude) { + public static final Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group( + Codec.FLOAT.fieldOf("frequency").forGetter(Octave::frequency), + Codec.FLOAT.fieldOf("amplitude").forGetter(Octave::amplitude) + ).apply(instance, instance.stable(Octave::new))); + } + + public static final Noise DEFAULT = new Noise(List.of(new Octave(1, 1), new Octave(2, 0.5f), new Octave(4, 0.25f)), 250); - public Noise(List octaves, double persistence, int stretch) { - this(octaves, persistence, stretch, -1); + public Noise(List octaves, int stretch) { + this(octaves, stretch, -1); } public static final Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group( - Codec.list(Codec.FLOAT).optionalFieldOf("octaves", DEFAULT.octaves).forGetter(Noise::octaves), - Codec.DOUBLE.optionalFieldOf("persistence", DEFAULT.persistence).forGetter(Noise::persistence), + Codec.list(Octave.CODEC).optionalFieldOf("octaves", DEFAULT.octaves).forGetter(Noise::octaves), Codec.INT.optionalFieldOf("stretch", DEFAULT.stretchXZ).forGetter(Noise::stretchXZ), Codec.INT.optionalFieldOf("stretch_y", DEFAULT.stretchY).forGetter(Noise::stretchY) ).apply(instance, instance.stable(Noise::new))); @@ -26,12 +32,10 @@ public double getPerlin(SimplexNoise noise, double x, double y, double z) { double z2 = z / stretchXZ; double total = 0; - double amplitude = 1; double totalAmplitude = 0; - for (float frequency : octaves) { - total += noise.getValue(x2 * frequency, y2 * frequency, z2 * frequency) * amplitude; - totalAmplitude += amplitude; - amplitude *= persistence; + for (Octave octave : octaves) { + total += noise.getValue(x2 * octave.frequency, y2 * octave.frequency, z2 * octave.frequency) * octave.amplitude; + totalAmplitude += octave.amplitude; } return total / totalAmplitude; @@ -42,13 +46,10 @@ public double getPerlin(SimplexNoise noise, double x, double z) { double z2 = z / stretchXZ; double total = 0; - double amplitude = 1; double totalAmplitude = 0; - - for (float frequency : octaves) { - total += noise.getValue(x2 * frequency, z2 * frequency) * amplitude; - totalAmplitude += amplitude; - amplitude *= persistence; + for (Octave octave : octaves) { + total += noise.getValue(x2 * octave.frequency, z2 * octave.frequency) * octave.amplitude; + totalAmplitude += octave.amplitude; } total /= totalAmplitude; diff --git a/common/src/main/java/dev/tocraft/ctgen/worldgen/MapSettings.java b/common/src/main/java/dev/tocraft/ctgen/worldgen/MapSettings.java index abc900d..7559774 100644 --- a/common/src/main/java/dev/tocraft/ctgen/worldgen/MapSettings.java +++ b/common/src/main/java/dev/tocraft/ctgen/worldgen/MapSettings.java @@ -1,5 +1,6 @@ package dev.tocraft.ctgen.worldgen; +import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.tocraft.ctgen.data.MapImageRegistry; @@ -9,6 +10,7 @@ import dev.tocraft.ctgen.xtend.height.TerrainHeight; import dev.tocraft.ctgen.xtend.layer.BlockLayer; import dev.tocraft.ctgen.zone.Zone; +import dev.tocraft.ctgen.zone.Zones; import net.minecraft.core.Holder; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.levelgen.synth.SimplexNoise; @@ -16,6 +18,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.awt.*; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.List; @@ -92,6 +95,13 @@ public MapSettings(ResourceLocation mapId, boolean pixelsAreChunks, List zone : this.zones) { + if (zone.is(Zones.RIVER)) { + Color c = new Color(1, 98, 255); + LogUtils.getLogger().warn("Color: " + zone.value().color() + " should be: " + c.getRGB()); + } + } } public List getLayers() { diff --git a/common/src/main/java/dev/tocraft/ctgen/xtend/carver/NoiseCarver.java b/common/src/main/java/dev/tocraft/ctgen/xtend/carver/NoiseCarver.java index c888587..3e39bd8 100644 --- a/common/src/main/java/dev/tocraft/ctgen/xtend/carver/NoiseCarver.java +++ b/common/src/main/java/dev/tocraft/ctgen/xtend/carver/NoiseCarver.java @@ -13,7 +13,7 @@ import java.util.List; public class NoiseCarver extends Carver { - public static final NoiseCarver DEFAULT = new NoiseCarver(new Noise(List.of(1F, 0.5F), 2, 63, 47), 0.55F); + public static final NoiseCarver DEFAULT = new NoiseCarver(new Noise(List.of(new Noise.Octave(1, 1), new Noise.Octave(0.5f, 2)), 63, 47), 0.55F); public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( Noise.CODEC.optionalFieldOf("noise", DEFAULT.noise).forGetter(o -> o.noise), diff --git a/common/src/main/java/dev/tocraft/ctgen/zone/Zones.java b/common/src/main/java/dev/tocraft/ctgen/zone/Zones.java index 102ddaf..05d0671 100644 --- a/common/src/main/java/dev/tocraft/ctgen/zone/Zones.java +++ b/common/src/main/java/dev/tocraft/ctgen/zone/Zones.java @@ -58,7 +58,7 @@ public static void bootstrap(@NotNull BootstrapContext context) { // Western Continent context.register(DESERT, new ZoneBuilder().setBiome(getBiome(context, Biomes.DESERT)).setColor(new Color(165, 171, 54)).setDirtBlock(Blocks.SANDSTONE).setSurfaceBlock(Blocks.SAND).setHeight(5).setTerrainModifier(4).build()); context.register(BADLANDS, new ZoneBuilder().setBiome(getBiome(context, Biomes.BADLANDS)).setColor(new Color(84, 84, 56)).setDirtBlock(Blocks.RED_CONCRETE).setSurfaceBlock(Blocks.RED_SAND).setHeight(18).setTerrainModifier(12).build()); - context.register(BADLANDS_MOUNTAINS, new ZoneBuilder().setBiome(getBiome(context, Biomes.BADLANDS)).setColor(new Color(70, 71, 53)).setDirtBlock(Blocks.RED_CONCRETE).putLayer("surface", NoisePlacer.of(new Noise(List.of(1f), 1, 50), new HashMap<>() { + context.register(BADLANDS_MOUNTAINS, new ZoneBuilder().setBiome(getBiome(context, Biomes.BADLANDS)).setColor(new Color(70, 71, 53)).setDirtBlock(Blocks.RED_CONCRETE).putLayer("surface", NoisePlacer.of(new Noise(List.of(new Noise.Octave(1, 1)), 50), new HashMap<>() { { put(-0.5d, Blocks.ORANGE_CONCRETE); put(0d, Blocks.RED_CONCRETE); diff --git a/gradle.properties b/gradle.properties index dd1f378..c76c1a1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx4G # Base Versions archives_base_name=ctgen artifact_type=release -mod_version=0.25 +mod_version=0.26 maven_group=dev.tocraft main_class=dev.tocraft.ctgen.runtime.Main # Loader Versions