From 33348feca17502921d22215fddd510177362b68a Mon Sep 17 00:00:00 2001 From: To_Craft Date: Thu, 31 Oct 2024 12:38:02 +0100 Subject: [PATCH] add Carver --- .../1feb4c76a7f661f0310d685620450608f5a76bca | 14 +++--- .../worldgen/map_based/zones/deep_ocean.json | 4 +- .../worldgen/map_based/zones/frozen_lake.json | 4 +- .../map_based/zones/frozen_river.json | 4 +- .../ctgen/worldgen/map_based/zones/ocean.json | 4 +- .../ctgen/worldgen/map_based/zones/river.json | 4 +- .../worldgen/MapBasedChunkGenerator.java | 20 ++------ .../tocraft/ctgen/worldgen/MapSettings.java | 18 +++---- .../ctgen/worldgen/MapSettingsBuilder.java | 20 ++++---- .../dev/tocraft/ctgen/xtend/CTRegistries.java | 2 + .../tocraft/ctgen/xtend/carver/Carver.java | 22 +++++++++ .../carver}/CarverSetting.java | 2 +- .../ctgen/xtend/carver/NoiseCarver.java | 47 +++++++++++++++++++ .../ctgen/xtend/height/NoiseHeight.java | 2 +- .../java/dev/tocraft/ctgen/zone/Zone.java | 4 +- .../dev/tocraft/ctgen/zone/ZoneBuilder.java | 8 ++-- .../java/dev/tocraft/ctgen/zone/Zones.java | 10 ++-- .../dev/tocraft/ctgen/fabric/CTGFabric.java | 4 +- .../dev/tocraft/ctgen/forge/CTGForge.java | 4 +- 19 files changed, 132 insertions(+), 65 deletions(-) create mode 100644 common/src/main/java/dev/tocraft/ctgen/xtend/carver/Carver.java rename common/src/main/java/dev/tocraft/ctgen/{worldgen => xtend/carver}/CarverSetting.java (94%) create mode 100644 common/src/main/java/dev/tocraft/ctgen/xtend/carver/NoiseCarver.java diff --git a/common/src/main/generated/.cache/1feb4c76a7f661f0310d685620450608f5a76bca b/common/src/main/generated/.cache/1feb4c76a7f661f0310d685620450608f5a76bca index 3b64faf..cf98355 100644 --- a/common/src/main/generated/.cache/1feb4c76a7f661f0310d685620450608f5a76bca +++ b/common/src/main/generated/.cache/1feb4c76a7f661f0310d685620450608f5a76bca @@ -1,18 +1,18 @@ -// 1.20.1 2024-10-31T12:11:48.172926144 CTGen/Registries +// 1.20.1 2024-10-31T12:27:26.172865087 CTGen/Registries 09917112f8476aaef3e39f5780a478b955edc3e7 data/ctgen/worldgen/map_based/zones/plains.json 3ca73f0225adf1fd168bfc73558fbf63bcf54aec data/ctgen/worldgen/map_based/zones/badlands_mountains.json -ea8abee99ec67bf274bec024eff481325863952a data/ctgen/worldgen/map_based/zones/stony_flats.json 4e10b1b02ad79d86538524c470d56dedf8c779f1 data/ctgen/worldgen/map_based/zones/desert.json -b24dcc94b75a2092b2386357c78a1f93808fd7f8 data/ctgen/worldgen/map_based/zones/river.json +ea8abee99ec67bf274bec024eff481325863952a data/ctgen/worldgen/map_based/zones/stony_flats.json +0bd4367d5837e151081d147227d11e56c29ecffb data/ctgen/worldgen/map_based/zones/river.json 166eb560b75b90c63217a66b4eac9cf59dcb8f9e data/ctgen/worldgen/map_based/zones/lake.json 786353e42c828bf1348fb727db3e60adec29c18d data/ctgen/worldgen/map_based/zones/forest.json a78f910d231a5d843042462e8517155aab8b5ca2 data/ctgen/worldgen/map_based/zones/snowy_mountains.json 3fcf216d906f96f57ba447df2dab0a13157af1ce data/ctgen/worldgen/map_based/zones/snowy_slopes.json -10fbdfeee308b501bed36a2d800c40b11810ce63 data/ctgen/worldgen/map_based/zones/ocean.json +a034954687c0b0280accf18519f3022d029489b8 data/ctgen/worldgen/map_based/zones/ocean.json 178d1061c64452922300ec3d5db0f066c59ca438 data/ctgen/worldgen/map_based/zones/badlands.json b5339019d9316486c132e0832d7f86a08a9ec1e4 data/ctgen/worldgen/map_based/zones/mountains.json d281f3a59adaf68e61a56c40493788015fd6ef95 data/ctgen/worldgen/map_based/zones/hills.json -12195224411b05e2dc54730b03a6ed894279f49c data/ctgen/worldgen/map_based/zones/frozen_river.json +2a289331bed4faa0aabefde7efaaff6ade8fd966 data/ctgen/worldgen/map_based/zones/frozen_river.json bdedb4d289b62ce9049dad7260e5e2a58987dfb3 data/ctgen/worldgen/map_based/zones/snowy_flats.json -e09748905aab9f3b627aabb7cf3e1ae3eee3b2b1 data/ctgen/worldgen/map_based/zones/deep_ocean.json -c6a7a763fb76dc1de84eb2511629ae6faeb17945 data/ctgen/worldgen/map_based/zones/frozen_lake.json +e20907968549754b4f2bdd776a641ca5c6f44fcd data/ctgen/worldgen/map_based/zones/deep_ocean.json +ae7297b8304833244f8be82c73215aefae5bb273 data/ctgen/worldgen/map_based/zones/frozen_lake.json diff --git a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/deep_ocean.json b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/deep_ocean.json index 2764b04..2af613c 100644 --- a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/deep_ocean.json +++ b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/deep_ocean.json @@ -1,11 +1,11 @@ { "biome": "minecraft:deep_ocean", + "carver_modifier": 26.0, "color": { "b": 85, "g": 35, "r": 0 }, "height": -60, - "terrain_modifier": 33.0, - "threshold_modifier": 26 + "terrain_modifier": 33.0 } \ No newline at end of file diff --git a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/frozen_lake.json b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/frozen_lake.json index bec2a45..6ff6919 100644 --- a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/frozen_lake.json +++ b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/frozen_lake.json @@ -1,5 +1,6 @@ { "biome": "minecraft:frozen_ocean", + "carver_modifier": 26.0, "color": { "b": 204, "g": 126, @@ -9,6 +10,5 @@ "layers": { "surface": "minecraft:sand" }, - "pixel_weight": 3.0, - "threshold_modifier": 26 + "pixel_weight": 3.0 } \ No newline at end of file diff --git a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/frozen_river.json b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/frozen_river.json index 93677e1..9db7a89 100644 --- a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/frozen_river.json +++ b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/frozen_river.json @@ -1,5 +1,6 @@ { "biome": "minecraft:frozen_river", + "carver_modifier": 26.0, "color": { "b": 240, "g": 145, @@ -10,6 +11,5 @@ "dirt": "minecraft:sand", "surface": "minecraft:sand" }, - "pixel_weight": 2.0, - "threshold_modifier": 26 + "pixel_weight": 2.0 } \ No newline at end of file diff --git a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/ocean.json b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/ocean.json index a723eee..00f4cdf 100644 --- a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/ocean.json +++ b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/ocean.json @@ -1,5 +1,6 @@ { "biome": "minecraft:ocean", + "carver_modifier": 26.0, "color": { "b": 103, "g": 42, @@ -9,6 +10,5 @@ "layers": { "surface": "minecraft:sand" }, - "terrain_modifier": 16.0, - "threshold_modifier": 26 + "terrain_modifier": 16.0 } \ No newline at end of file diff --git a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/river.json b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/river.json index 0a67e67..563175c 100644 --- a/common/src/main/generated/data/ctgen/worldgen/map_based/zones/river.json +++ b/common/src/main/generated/data/ctgen/worldgen/map_based/zones/river.json @@ -1,5 +1,6 @@ { "biome": "minecraft:river", + "carver_modifier": 26.0, "color": { "b": 255, "g": 98, @@ -10,6 +11,5 @@ "dirt": "minecraft:sand", "surface": "minecraft:sand" }, - "pixel_weight": 2.0, - "threshold_modifier": 26 + "pixel_weight": 2.0 } \ No newline at end of file diff --git a/common/src/main/java/dev/tocraft/ctgen/worldgen/MapBasedChunkGenerator.java b/common/src/main/java/dev/tocraft/ctgen/worldgen/MapBasedChunkGenerator.java index fafccb2..51ded24 100644 --- a/common/src/main/java/dev/tocraft/ctgen/worldgen/MapBasedChunkGenerator.java +++ b/common/src/main/java/dev/tocraft/ctgen/worldgen/MapBasedChunkGenerator.java @@ -74,7 +74,7 @@ public void buildSurface(@NotNull WorldGenRegion pLevel, @NotNull StructureManag Zone zone = getSettings().getZone(xOff >> 2, zOff >> 2).value(); double surfaceHeight = getSettings().getHeight(noise, xOff, zOff) + getSettings().surfaceLevel; - int thresholdModifier = (int) getSettings().getValueWithTransition(xOff, zOff, zo -> (double) zo.thresholdModifier().orElse(getSettings().thresholdModifier)); + double carverModifier = getSettings().getValueWithTransition(xOff, zOff, zo -> zo.carverModifier().orElse(getSettings().carverModifier)); int shift = (int) (noise.getValue(xOff, zOff) * 3); int bedrockLevel = minHeight + shift; @@ -96,7 +96,7 @@ public void buildSurface(@NotNull WorldGenRegion pLevel, @NotNull StructureManag BlockPlacer placer = layer != null ? zone.layers().getOrDefault(layer.getName(), layer.getFallback()) : BasicPlacer.AIR; Block block = placer.get(this.noise, x, y, z, layer != null ? layer.getName() : "fill"); - if (layer != null && !layer.hasCaves() || canSetBlock(pos, surfaceHeight, minHeight, thresholdModifier)) { + if (layer != null && !layer.hasCaves() || canSetBlock(pos, surfaceHeight, minHeight, carverModifier)) { // no grass underwater if (surfaceHeight < getSeaLevel() && block == Blocks.GRASS_BLOCK) { block = Blocks.DIRT; @@ -115,20 +115,8 @@ public void buildSurface(@NotNull WorldGenRegion pLevel, @NotNull StructureManag } } - private boolean canSetBlock(@NotNull BlockPos pos, double surfaceHeight, int minHeight, int thresholdModifier) { - double height = (double) (pos.getY() - minHeight) / (surfaceHeight - minHeight) - 0.5; - double addThreshold = height * height * height * height * thresholdModifier; - - for (CarverSetting carver : getSettings().carverSettings) { - double perlin = carver.noise().getPerlin(this.noise, pos.getX(), pos.getY(), pos.getZ()); - - double threshold = carver.threshold() + addThreshold; - if (perlin > threshold) { - return false; - } - } - - return true; + private boolean canSetBlock(@NotNull BlockPos pos, double surfaceHeight, int minHeight, double carverModifier) { + return getSettings().carver.canSetBlock(this.noise, pos, surfaceHeight, minHeight, carverModifier); } @Override 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 47a5dd2..abc900d 100644 --- a/common/src/main/java/dev/tocraft/ctgen/worldgen/MapSettings.java +++ b/common/src/main/java/dev/tocraft/ctgen/worldgen/MapSettings.java @@ -3,6 +3,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.tocraft.ctgen.data.MapImageRegistry; +import dev.tocraft.ctgen.xtend.carver.Carver; +import dev.tocraft.ctgen.xtend.carver.NoiseCarver; import dev.tocraft.ctgen.xtend.height.NoiseHeight; import dev.tocraft.ctgen.xtend.height.TerrainHeight; import dev.tocraft.ctgen.xtend.layer.BlockLayer; @@ -23,12 +25,11 @@ @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public final class MapSettings { - static final MapSettings DEFAULT = new MapSettings(null, false, 1, new ArrayList<>(), null, BlockLayer.defaultLayers(-64), 66, -64, 279, 64, NoiseHeight.DEFAULT, 31, Optional.empty(), Optional.empty(), List.of(CarverSetting.DEFAULT)); + static final MapSettings DEFAULT = new MapSettings(null, false, new ArrayList<>(), null, BlockLayer.defaultLayers(-64), 66, -64, 279, 64, NoiseHeight.DEFAULT, 31, Optional.empty(), Optional.empty(), NoiseCarver.DEFAULT, 1); public static final Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group( ResourceLocation.CODEC.fieldOf("biome_map").forGetter(o -> o.mapId), Codec.BOOL.optionalFieldOf("pixels_are_chunks", DEFAULT.pixelsAreChunks).forGetter(o -> o.pixelsAreChunks), - Codec.INT.optionalFieldOf("default_threshold_modifier", DEFAULT.thresholdModifier).forGetter(o -> o.thresholdModifier), Codec.list(Zone.CODEC).optionalFieldOf("zones", DEFAULT.zones).forGetter(o -> o.zones), Zone.CODEC.fieldOf("default_map_biome").forGetter(o -> o.defaultBiome), Codec.list(BlockLayer.CODEC).optionalFieldOf("layers", DEFAULT.layers).forGetter(o -> o.layers), @@ -40,12 +41,12 @@ public final class MapSettings { Codec.INT.optionalFieldOf("transition", DEFAULT.transition).forGetter(o -> o.transition), Codec.INT.optionalFieldOf("spawn_pixel_x").forGetter(o -> o.spawnX), Codec.INT.optionalFieldOf("spawn_pixel_y").forGetter(o -> o.spawnY), - Codec.list(CarverSetting.CODEC).optionalFieldOf("cave_carver", DEFAULT.carverSettings).forGetter(o -> o.carverSettings) + Carver.CODEC.optionalFieldOf("carver", DEFAULT.carver).forGetter(o -> o.carver), + Codec.DOUBLE.optionalFieldOf("default_carver_modifier", DEFAULT.carverModifier).forGetter(o -> o.carverModifier) ).apply(instance, instance.stable(MapSettings::new))); private final ResourceLocation mapId; final boolean pixelsAreChunks; - final int thresholdModifier; final List> zones; private final Holder defaultBiome; final int surfaceLevel; @@ -57,14 +58,15 @@ public final class MapSettings { private final Supplier mapImage; final Optional spawnX; final Optional spawnY; - final List carverSettings; + final Carver carver; + final double carverModifier; private final List layers; @ApiStatus.Internal - public MapSettings(ResourceLocation mapId, boolean pixelsAreChunks, int thresholdModifier, List> zones, Holder defaultBiome, List layers, int surfaceLevel, int minY, int genHeight, int seaLevel, TerrainHeight terrain, int transition, @NotNull Optional spawnX, @NotNull Optional spawnY, List carverSettings) { + public MapSettings(ResourceLocation mapId, boolean pixelsAreChunks, List> zones, Holder defaultBiome, List layers, int surfaceLevel, int minY, int genHeight, int seaLevel, TerrainHeight terrain, int transition, @NotNull Optional spawnX, @NotNull Optional spawnY, Carver carver, double carverModifier) { this.mapId = mapId; this.pixelsAreChunks = pixelsAreChunks; - this.thresholdModifier = thresholdModifier; + this.carverModifier = carverModifier; this.zones = zones; this.defaultBiome = defaultBiome; this.layers = layers; @@ -89,7 +91,7 @@ public MapSettings(ResourceLocation mapId, boolean pixelsAreChunks, int threshol return sX; } }); - this.carverSettings = carverSettings; + this.carver = carver; } public List getLayers() { diff --git a/common/src/main/java/dev/tocraft/ctgen/worldgen/MapSettingsBuilder.java b/common/src/main/java/dev/tocraft/ctgen/worldgen/MapSettingsBuilder.java index d7286d0..bf25e69 100644 --- a/common/src/main/java/dev/tocraft/ctgen/worldgen/MapSettingsBuilder.java +++ b/common/src/main/java/dev/tocraft/ctgen/worldgen/MapSettingsBuilder.java @@ -1,5 +1,6 @@ package dev.tocraft.ctgen.worldgen; +import dev.tocraft.ctgen.xtend.carver.Carver; import dev.tocraft.ctgen.xtend.height.TerrainHeight; import dev.tocraft.ctgen.xtend.layer.BlockLayer; import dev.tocraft.ctgen.zone.Zone; @@ -13,7 +14,6 @@ public class MapSettingsBuilder { private ResourceLocation biomeMapId; private boolean pixelsAreChunks = MapSettings.DEFAULT.pixelsAreChunks; - private int thresholdModifier = MapSettings.DEFAULT.thresholdModifier; private List> zones = MapSettings.DEFAULT.zones; private Holder defaultBiome; private List layers = MapSettings.DEFAULT.getLayers(); @@ -25,7 +25,8 @@ public class MapSettingsBuilder { private int transition = MapSettings.DEFAULT.transition; private Optional spawnX = MapSettings.DEFAULT.spawnX; private Optional spawnY = MapSettings.DEFAULT.spawnY; - private List carverSettings = MapSettings.DEFAULT.carverSettings; + private Carver carver = MapSettings.DEFAULT.carver; + private double carverModifier = MapSettings.DEFAULT.carverModifier; public MapSettingsBuilder setBiomeMapId(ResourceLocation biomeMapId) { this.biomeMapId = biomeMapId; @@ -37,10 +38,6 @@ public MapSettingsBuilder setPixelsAreChunks(boolean pixelsAreChunks) { return this; } - public MapSettingsBuilder setThresholdModifier(int thresholdModifier) { - this.thresholdModifier = thresholdModifier; - return this; - } public MapSettingsBuilder setZones(List> zones) { this.zones = zones; @@ -102,12 +99,17 @@ public MapSettingsBuilder setSpawnY(int spawnY) { return this; } - public MapSettingsBuilder setCarverSettings(List carverSetting) { - this.carverSettings = carverSetting; + public MapSettingsBuilder setCarver(Carver carver) { + this.carver = carver; + return this; + } + + public MapSettingsBuilder setCarverModifier(double carverModifier) { + this.carverModifier = carverModifier; return this; } public MapSettings build() { - return new MapSettings(biomeMapId, pixelsAreChunks, thresholdModifier, zones, defaultBiome, layers, surfaceLevel, minY, genHeight, seaLevel, terrain, transition, spawnX, spawnY, carverSettings); + return new MapSettings(biomeMapId, pixelsAreChunks, zones, defaultBiome, layers, surfaceLevel, minY, genHeight, seaLevel, terrain, transition, spawnX, spawnY, carver, carverModifier); } } \ No newline at end of file diff --git a/common/src/main/java/dev/tocraft/ctgen/xtend/CTRegistries.java b/common/src/main/java/dev/tocraft/ctgen/xtend/CTRegistries.java index 2b4046e..2f635b2 100644 --- a/common/src/main/java/dev/tocraft/ctgen/xtend/CTRegistries.java +++ b/common/src/main/java/dev/tocraft/ctgen/xtend/CTRegistries.java @@ -2,6 +2,7 @@ import com.mojang.serialization.Codec; import dev.tocraft.ctgen.util.Registrar; +import dev.tocraft.ctgen.xtend.carver.Carver; import dev.tocraft.ctgen.xtend.height.TerrainHeight; import dev.tocraft.ctgen.xtend.layer.BlockLayer; import dev.tocraft.ctgen.xtend.placer.BlockPlacer; @@ -16,4 +17,5 @@ public final class CTRegistries { public static final Registrar> BLOCK_PLACER = new Registrar<>(); public static final Registrar> BLOCK_LAYER = new Registrar<>(); public static final Registrar> TERRAIN = new Registrar<>(); + public static final Registrar> CARVER = new Registrar<>(); } diff --git a/common/src/main/java/dev/tocraft/ctgen/xtend/carver/Carver.java b/common/src/main/java/dev/tocraft/ctgen/xtend/carver/Carver.java new file mode 100644 index 0000000..717ff93 --- /dev/null +++ b/common/src/main/java/dev/tocraft/ctgen/xtend/carver/Carver.java @@ -0,0 +1,22 @@ +package dev.tocraft.ctgen.xtend.carver; + +import com.mojang.serialization.Codec; +import dev.tocraft.ctgen.xtend.CTRegistries; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.levelgen.synth.SimplexNoise; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Function; + +public abstract class Carver { + public static final Codec CODEC = CTRegistries.CARVER.byNameCodec().dispatchStable(Carver::codec, Function.identity()); + + public static void register() { + CTRegistries.CARVER.register(NoiseCarver.ID, NoiseCarver.CODEC); + } + + + public abstract boolean canSetBlock(SimplexNoise noise, @NotNull BlockPos pos, double surfaceHeight, int minHeight, double carverModifier); + + protected abstract Codec codec(); +} diff --git a/common/src/main/java/dev/tocraft/ctgen/worldgen/CarverSetting.java b/common/src/main/java/dev/tocraft/ctgen/xtend/carver/CarverSetting.java similarity index 94% rename from common/src/main/java/dev/tocraft/ctgen/worldgen/CarverSetting.java rename to common/src/main/java/dev/tocraft/ctgen/xtend/carver/CarverSetting.java index eb1c484..1234f42 100644 --- a/common/src/main/java/dev/tocraft/ctgen/worldgen/CarverSetting.java +++ b/common/src/main/java/dev/tocraft/ctgen/xtend/carver/CarverSetting.java @@ -1,4 +1,4 @@ -package dev.tocraft.ctgen.worldgen; +package dev.tocraft.ctgen.xtend.carver; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; 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 new file mode 100644 index 0000000..d6a754e --- /dev/null +++ b/common/src/main/java/dev/tocraft/ctgen/xtend/carver/NoiseCarver.java @@ -0,0 +1,47 @@ +package dev.tocraft.ctgen.xtend.carver; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import dev.tocraft.ctgen.CTerrainGeneration; +import dev.tocraft.ctgen.util.Noise; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.synth.SimplexNoise; +import org.jetbrains.annotations.NotNull; + +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 Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Noise.CODEC.optionalFieldOf("noise", DEFAULT.noise).forGetter(o -> o.noise), + Codec.DOUBLE.optionalFieldOf("threshold", DEFAULT.threshold).forGetter(o -> o.threshold) + ).apply(instance, NoiseCarver::new)); + public static final ResourceLocation ID = CTerrainGeneration.id("noise_carver"); + + private final Noise noise; + private final double threshold; + + public NoiseCarver(Noise noise, double threshold) { + this.noise = noise; + this.threshold = threshold; + } + + + @Override + public boolean canSetBlock(SimplexNoise noise, @NotNull BlockPos pos, double surfaceHeight, int minHeight, double carverModifier) { + double height = (double) (pos.getY() - minHeight) / (surfaceHeight - minHeight) - 0.5; + double addThreshold = height * height * height * height * carverModifier; + + double perlin = this.noise.getPerlin(noise, pos.getX(), pos.getY(), pos.getZ()); + + double threshold = this.threshold + addThreshold; + return perlin <= threshold; + } + + @Override + protected Codec codec() { + return CODEC; + } +} diff --git a/common/src/main/java/dev/tocraft/ctgen/xtend/height/NoiseHeight.java b/common/src/main/java/dev/tocraft/ctgen/xtend/height/NoiseHeight.java index 76c66aa..642844e 100644 --- a/common/src/main/java/dev/tocraft/ctgen/xtend/height/NoiseHeight.java +++ b/common/src/main/java/dev/tocraft/ctgen/xtend/height/NoiseHeight.java @@ -12,7 +12,7 @@ public class NoiseHeight extends TerrainHeight { public static final NoiseHeight DEFAULT = new NoiseHeight(Noise.DEFAULT); public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - Noise.CODEC.optionalFieldOf("noise", Noise.DEFAULT).forGetter(o -> o.noise) + Noise.CODEC.optionalFieldOf("noise", DEFAULT.noise).forGetter(o -> o.noise) ).apply(instance, NoiseHeight::new)); public static final ResourceLocation ID = CTerrainGeneration.id("noise_height"); diff --git a/common/src/main/java/dev/tocraft/ctgen/zone/Zone.java b/common/src/main/java/dev/tocraft/ctgen/zone/Zone.java index af980f8..17edfb5 100644 --- a/common/src/main/java/dev/tocraft/ctgen/zone/Zone.java +++ b/common/src/main/java/dev/tocraft/ctgen/zone/Zone.java @@ -15,7 +15,7 @@ public record Zone(Holder biome, int color, Map layers, int height, double terrainModifier, double pixelWeight, - Optional thresholdModifier) { + Optional carverModifier) { public static final int DEFAULT_HEIGHT = 0; public static final double DEFAULT_TERRAIN_MODIFIER = 8; @@ -28,7 +28,7 @@ public record Zone(Holder biome, int color, Map laye Codec.INT.optionalFieldOf("height", DEFAULT_HEIGHT).forGetter(Zone::height), Codec.DOUBLE.optionalFieldOf("terrain_modifier", DEFAULT_TERRAIN_MODIFIER).forGetter(Zone::terrainModifier), Codec.DOUBLE.optionalFieldOf("pixel_weight", DEFAULT_PIXEL_WEIGHT).forGetter(Zone::pixelWeight), - Codec.INT.optionalFieldOf("threshold_modifier").forGetter(Zone::thresholdModifier) + Codec.DOUBLE.optionalFieldOf("carver_modifier").forGetter(Zone::carverModifier) ).apply(instance, instance.stable(Zone::new))); public static RegistryFileCodec CODEC = RegistryFileCodec.create(CTRegistries.ZONES_KEY, DIRECT_CODEC); diff --git a/common/src/main/java/dev/tocraft/ctgen/zone/ZoneBuilder.java b/common/src/main/java/dev/tocraft/ctgen/zone/ZoneBuilder.java index a299dfe..cd4bf4e 100644 --- a/common/src/main/java/dev/tocraft/ctgen/zone/ZoneBuilder.java +++ b/common/src/main/java/dev/tocraft/ctgen/zone/ZoneBuilder.java @@ -20,7 +20,7 @@ public class ZoneBuilder { private double terrainModifier = Zone.DEFAULT_TERRAIN_MODIFIER; private double pixelWeight = Zone.DEFAULT_PIXEL_WEIGHT; private Map layers = new HashMap<>(); - private Optional thresholdModifier = Optional.empty(); + private Optional carverModifier = Optional.empty(); public ZoneBuilder setBiome(Holder biome) { this.biome = biome; @@ -82,12 +82,12 @@ public ZoneBuilder setSurfaceBlock(Block block) { return this; } - public ZoneBuilder setThresholdModifier(int thresholdModifier) { - this.thresholdModifier = Optional.of(thresholdModifier); + public ZoneBuilder setCarverModifier(double carverModifier) { + this.carverModifier = Optional.of(carverModifier); return this; } public Zone build() { - return new Zone(biome, color, layers, height, terrainModifier, pixelWeight, thresholdModifier); + return new Zone(biome, color, layers, height, terrainModifier, pixelWeight, carverModifier); } } \ No newline at end of file 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 c74924c..cc44cf2 100644 --- a/common/src/main/java/dev/tocraft/ctgen/zone/Zones.java +++ b/common/src/main/java/dev/tocraft/ctgen/zone/Zones.java @@ -47,8 +47,8 @@ public static void bootstrap(@NotNull BootstapContext context) { context.register(SNOWY_FLATS, new ZoneBuilder().setBiome(getBiome(context, Biomes.SNOWY_SLOPES)).setColor(new Color(217, 217, 217)).setHeight(5).build()); context.register(SNOWY_SLOPES, new ZoneBuilder().setBiome(getBiome(context, Biomes.SNOWY_SLOPES)).setColor(new Color(192, 192, 192)).setDirtBlock(Blocks.SNOW_BLOCK).setSurfaceBlock(Blocks.SNOW_BLOCK).setHeight(18).setTerrainModifier(20).setPixelWeight(1.5).build()); context.register(SNOWY_MOUNTAINS, new ZoneBuilder().setBiome(getBiome(context, Biomes.JAGGED_PEAKS)).setColor(new Color(168, 168, 168)).setHeight(40).setTerrainModifier(50).setSurfaceBlock(Blocks.SNOW_BLOCK).build()); - context.register(FROZEN_RIVER, new ZoneBuilder().setBiome(getBiome(context, Biomes.FROZEN_RIVER)).setColor(new Color(87, 145, 240)).setDirtBlock(Blocks.SAND).setSurfaceBlock(Blocks.SAND).setHeight(-15).setPixelWeight(2).setThresholdModifier(26).build()); - context.register(FROZEN_LAKE, new ZoneBuilder().setBiome(getBiome(context, Biomes.FROZEN_OCEAN)).setColor(new Color(78, 126, 204)).setSurfaceBlock(Blocks.SAND).setHeight(-20).setPixelWeight(3).setThresholdModifier(26).build()); + context.register(FROZEN_RIVER, new ZoneBuilder().setBiome(getBiome(context, Biomes.FROZEN_RIVER)).setColor(new Color(87, 145, 240)).setDirtBlock(Blocks.SAND).setSurfaceBlock(Blocks.SAND).setHeight(-15).setPixelWeight(2).setCarverModifier(26).build()); + context.register(FROZEN_LAKE, new ZoneBuilder().setBiome(getBiome(context, Biomes.FROZEN_OCEAN)).setColor(new Color(78, 126, 204)).setSurfaceBlock(Blocks.SAND).setHeight(-20).setPixelWeight(3).setCarverModifier(26).build()); // Eastern Continent context.register(PLAINS, new ZoneBuilder().setBiome(getBiome(context, Biomes.PLAINS)).setColor(new Color(57, 95, 57)).setHeight(5).build()); context.register(FOREST, new ZoneBuilder().setBiome(getBiome(context, Biomes.FOREST)).setColor(new Color(43, 70, 43)).setHeight(12).setTerrainModifier(10).build()); @@ -65,9 +65,9 @@ public static void bootstrap(@NotNull BootstapContext context) { } }, Blocks.BROWN_CONCRETE)).setHeight(28).setTerrainModifier(24).build()); // General Water Biomes - context.register(RIVER, new ZoneBuilder().setBiome(getBiome(context, Biomes.RIVER)).setColor(new Color(1, 98, 255)).setDirtBlock(Blocks.SAND).setSurfaceBlock(Blocks.SAND).setHeight(-15).setPixelWeight(2).setThresholdModifier(26).build()); - context.register(OCEAN, new ZoneBuilder().setBiome(getBiome(context, Biomes.OCEAN)).setColor(new Color(0, 42, 103)).setSurfaceBlock(Blocks.SAND).setHeight(-35).setTerrainModifier(16).setThresholdModifier(26).build()); - context.register(DEEP_OCEAN, new ZoneBuilder().setBiome(getBiome(context, Biomes.DEEP_OCEAN)).setColor(new Color(0, 35, 85)).setHeight(-60).setTerrainModifier(33).setThresholdModifier(26).build()); + context.register(RIVER, new ZoneBuilder().setBiome(getBiome(context, Biomes.RIVER)).setColor(new Color(1, 98, 255)).setDirtBlock(Blocks.SAND).setSurfaceBlock(Blocks.SAND).setHeight(-15).setPixelWeight(2).setCarverModifier(26).build()); + context.register(OCEAN, new ZoneBuilder().setBiome(getBiome(context, Biomes.OCEAN)).setColor(new Color(0, 42, 103)).setSurfaceBlock(Blocks.SAND).setHeight(-35).setTerrainModifier(16).setCarverModifier(26).build()); + context.register(DEEP_OCEAN, new ZoneBuilder().setBiome(getBiome(context, Biomes.DEEP_OCEAN)).setColor(new Color(0, 35, 85)).setHeight(-60).setTerrainModifier(33).setCarverModifier(26).build()); } private static @NotNull Holder getBiome(@NotNull BootstapContext context, ResourceKey biome) { diff --git a/fabric/src/main/java/dev/tocraft/ctgen/fabric/CTGFabric.java b/fabric/src/main/java/dev/tocraft/ctgen/fabric/CTGFabric.java index f470b79..b52f7d2 100644 --- a/fabric/src/main/java/dev/tocraft/ctgen/fabric/CTGFabric.java +++ b/fabric/src/main/java/dev/tocraft/ctgen/fabric/CTGFabric.java @@ -5,9 +5,10 @@ import dev.tocraft.ctgen.impl.CTGCommand; import dev.tocraft.ctgen.worldgen.MapBasedBiomeSource; import dev.tocraft.ctgen.worldgen.MapBasedChunkGenerator; +import dev.tocraft.ctgen.xtend.carver.Carver; +import dev.tocraft.ctgen.xtend.height.TerrainHeight; import dev.tocraft.ctgen.xtend.layer.BlockLayer; import dev.tocraft.ctgen.xtend.placer.BlockPlacer; -import dev.tocraft.ctgen.xtend.height.TerrainHeight; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; @@ -59,5 +60,6 @@ public ResourceLocation getFabricId() { BlockPlacer.register(); BlockLayer.register(); TerrainHeight.register(); + Carver.register(); } } diff --git a/forge/src/main/java/dev/tocraft/ctgen/forge/CTGForge.java b/forge/src/main/java/dev/tocraft/ctgen/forge/CTGForge.java index 7f8a197..2cd05ca 100644 --- a/forge/src/main/java/dev/tocraft/ctgen/forge/CTGForge.java +++ b/forge/src/main/java/dev/tocraft/ctgen/forge/CTGForge.java @@ -2,9 +2,10 @@ import dev.tocraft.ctgen.CTerrainGeneration; import dev.tocraft.ctgen.impl.network.SyncMapPacket; +import dev.tocraft.ctgen.xtend.carver.Carver; +import dev.tocraft.ctgen.xtend.height.TerrainHeight; import dev.tocraft.ctgen.xtend.layer.BlockLayer; import dev.tocraft.ctgen.xtend.placer.BlockPlacer; -import dev.tocraft.ctgen.xtend.height.TerrainHeight; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.common.Mod; @@ -43,5 +44,6 @@ public CTGForge() { BlockPlacer.register(); BlockLayer.register(); TerrainHeight.register(); + Carver.register(); } }