From 9579654fed137258c7ae51714c4f82fa49748440 Mon Sep 17 00:00:00 2001 From: To_Craft Date: Thu, 24 Oct 2024 16:32:45 +0200 Subject: [PATCH] add block layers --- .../crafted/ctgen/CTerrainGeneration.java | 1 - .../ctgen/blockplacer/BasicPlacer.java | 12 ++- .../ctgen/blockplacer/BlockPlacer.java | 3 + .../ctgen/blockplacer/NoisePlacer.java | 4 +- .../ctgen/impl/screen/widget/MapWidget.java | 1 + .../crafted/ctgen/layer/BlockLayer.java | 55 ++++++++++++-- .../crafted/ctgen/layer/HeightLayer.java | 76 +++++++++++++++++++ .../tocraft/crafted/ctgen/layer/SeaLayer.java | 32 ++++++++ .../crafted/ctgen/layer/SurfaceLayer.java | 37 +++++++++ .../crafted/ctgen/layer/WeightLayer.java | 65 ++++++++++++++++ .../worldgen/MapBasedChunkGenerator.java | 62 +++++++-------- .../crafted/ctgen/worldgen/MapSettings.java | 32 +++----- .../ctgen/worldgen/MapSettingsBuilder.java | 14 +++- .../dev/tocraft/crafted/ctgen/zone/Zone.java | 18 ++--- .../crafted/ctgen/zone/ZoneBuilder.java | 43 ++++------- .../dev/tocraft/crafted/ctgen/zone/Zones.java | 2 +- .../worldgen/map_based/zones/badlands.json | 6 +- .../map_based/zones/badlands_mountains.json | 28 +++---- .../worldgen/map_based/zones/desert.json | 6 +- .../worldgen/map_based/zones/frozen_lake.json | 4 +- .../map_based/zones/frozen_river.json | 6 +- .../ctgen/worldgen/map_based/zones/lake.json | 4 +- .../worldgen/map_based/zones/mountains.json | 4 +- .../ctgen/worldgen/map_based/zones/ocean.json | 4 +- .../ctgen/worldgen/map_based/zones/river.json | 6 +- .../map_based/zones/snowy_mountains.json | 4 +- .../map_based/zones/snowy_slopes.json | 6 +- .../worldgen/map_based/zones/stony_flats.json | 6 +- .../crafted/ctgen/fabric/CTGFabric.java | 3 + .../ctgen/forge/CTGForgeEventListener.java | 2 + 30 files changed, 408 insertions(+), 138 deletions(-) create mode 100644 common/src/main/java/dev/tocraft/crafted/ctgen/layer/HeightLayer.java create mode 100644 common/src/main/java/dev/tocraft/crafted/ctgen/layer/SeaLayer.java create mode 100644 common/src/main/java/dev/tocraft/crafted/ctgen/layer/SurfaceLayer.java create mode 100644 common/src/main/java/dev/tocraft/crafted/ctgen/layer/WeightLayer.java diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/CTerrainGeneration.java b/common/src/main/java/dev/tocraft/crafted/ctgen/CTerrainGeneration.java index 14faa00..3815742 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/CTerrainGeneration.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/CTerrainGeneration.java @@ -1,6 +1,5 @@ package dev.tocraft.crafted.ctgen; -import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; import dev.tocraft.crafted.ctgen.zone.Zone; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BasicPlacer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BasicPlacer.java index 32dbdef..4194ce9 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BasicPlacer.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BasicPlacer.java @@ -6,10 +6,18 @@ import dev.tocraft.crafted.ctgen.zone.Codecs; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.levelgen.synth.SimplexNoise; import org.jetbrains.annotations.NotNull; public class BasicPlacer extends BlockPlacer { + public static final BlockPlacer DEEPSLATE_BLOCK = new BasicPlacer(Blocks.DEEPSLATE); + public static final BlockPlacer STONE_BLOCK = new BasicPlacer(Blocks.STONE); + public static final BlockPlacer DIRT_BLOCK = new BasicPlacer(Blocks.DIRT); + public static final BlockPlacer GRASS_BLOCK = new BasicPlacer(Blocks.GRASS_BLOCK); + public static final BlockPlacer WATER_BLOCK = new BasicPlacer(Blocks.WATER); + public static final BlockPlacer AIR = new BasicPlacer(Blocks.AIR); + @NotNull private final Block value; @@ -17,12 +25,12 @@ public BasicPlacer(@NotNull Block value) { this.value = value; } - public Block get(SimplexNoise noise, double x, double y, double z, String layer) { + public @NotNull Block get(SimplexNoise noise, double x, double y, double z, String layer) { return value; } @Override - public Block get(SimplexNoise noise, double x, double z, String layer) { + public @NotNull Block get(SimplexNoise noise, double x, double z, String layer) { return value; } diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BlockPlacer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BlockPlacer.java index 229fbd3..7d37d0b 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BlockPlacer.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/BlockPlacer.java @@ -7,6 +7,7 @@ import net.minecraft.core.Registry; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.synth.SimplexNoise; +import org.jetbrains.annotations.NotNull; import java.util.Optional; import java.util.function.Function; @@ -33,8 +34,10 @@ public static void register() { Registry.register(CTRegistries.BLOCK_PLACER, NoisePlacer.ID, NoisePlacer.CODEC); } + @NotNull public abstract Block get(SimplexNoise noise, double x, double y, double z, String layer); + @NotNull public abstract Block get(SimplexNoise noise, double x, double z, String layer); protected abstract Codec codec(); diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/NoisePlacer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/NoisePlacer.java index 0467569..e959cd7 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/NoisePlacer.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/blockplacer/NoisePlacer.java @@ -38,7 +38,7 @@ public boolean hasNoise() { return noise != null && !thresholdMap.isEmpty(); } - public Block get(SimplexNoise noise, double x, double y, double z, String layer) { + public @NotNull Block get(SimplexNoise noise, double x, double y, double z, String layer) { double perlin; if (this.noise != null && hasNoise()) { @@ -60,7 +60,7 @@ public Block get(SimplexNoise noise, double x, double y, double z, String layer) } @Override - public Block get(SimplexNoise noise, double x, double z, String layer) { + public @NotNull Block get(SimplexNoise noise, double x, double z, String layer) { double perlin; if (this.noise != null && hasNoise()) { diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/impl/screen/widget/MapWidget.java b/common/src/main/java/dev/tocraft/crafted/ctgen/impl/screen/widget/MapWidget.java index 5319c12..f125430 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/impl/screen/widget/MapWidget.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/impl/screen/widget/MapWidget.java @@ -89,6 +89,7 @@ public MapWidget(Minecraft minecraft, int x, int y, int width, int height, Resou updateZoomedWidth(); updateZoomedHeight(); + resetTextureOffsets(); } public float defaultZoom() { diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/layer/BlockLayer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/BlockLayer.java index 92a077e..da02ec7 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/layer/BlockLayer.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/BlockLayer.java @@ -1,27 +1,72 @@ package dev.tocraft.crafted.ctgen.layer; import com.mojang.serialization.Codec; +import dev.tocraft.crafted.ctgen.blockplacer.BasicPlacer; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; import dev.tocraft.crafted.ctgen.util.CTRegistries; +import dev.tocraft.crafted.ctgen.zone.Zone; +import net.minecraft.core.Registry; import net.minecraft.world.level.levelgen.synth.SimplexNoise; +import java.util.List; import java.util.function.Function; public abstract class BlockLayer { public static final Codec CODEC = CTRegistries.BLOCK_LAYER.byNameCodec().dispatchStable(BlockLayer::codec, Function.identity()); + private final String name; + private final boolean hasCaves; + private final BlockPlacer fallback; - protected final String name; - - public BlockLayer(String name) { + public BlockLayer(String name, boolean hasCaves, BlockPlacer fallback) { this.name = name; + this.hasCaves = hasCaves; + this.fallback = fallback; + } + + public static void register() { + Registry.register(CTRegistries.BLOCK_LAYER, SeaLayer.ID, SeaLayer.CODEC); + Registry.register(CTRegistries.BLOCK_LAYER, HeightLayer.ID, HeightLayer.CODEC); + Registry.register(CTRegistries.BLOCK_LAYER, WeightLayer.ID, WeightLayer.CODEC); + } + + public static BlockLayer deepslate(int minY) { + return new HeightLayer(minY, 0, true, "deepslate", BasicPlacer.DEEPSLATE_BLOCK); + } + + public static BlockLayer stone() { + return new WeightLayer(0, 0.96, "stone", BasicPlacer.STONE_BLOCK); + } + + public static BlockLayer dirt() { + // max is 200% to ensure there's no gap caused by "shifted" blocks + return new WeightLayer(0.96, 2, "dirt", BasicPlacer.DIRT_BLOCK); } - public abstract boolean is(SimplexNoise noise, double x, double y, double z); + public static BlockLayer surface() { + return new SurfaceLayer("surface", BasicPlacer.GRASS_BLOCK); + } + + public static BlockLayer sea() { + return new SeaLayer("sea", BasicPlacer.WATER_BLOCK); + } + + public static List defaultLayers(int minY) { + return List.of(surface(), deepslate(minY), sea(), stone(), dirt()); + } + + public abstract boolean is(SimplexNoise noise, int x, int y, int z, Zone zone, int minY, int seaLevel, double surfaceHeight, int genHeight, int shift); public String getName() { return this.name; } - ; + public boolean hasCaves() { + return hasCaves; + } + + public BlockPlacer getFallback() { + return fallback; + } protected abstract Codec codec(); } diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/layer/HeightLayer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/HeightLayer.java new file mode 100644 index 0000000..391c296 --- /dev/null +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/HeightLayer.java @@ -0,0 +1,76 @@ +package dev.tocraft.crafted.ctgen.layer; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import dev.tocraft.crafted.ctgen.CTerrainGeneration; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; +import dev.tocraft.crafted.ctgen.zone.Zone; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.synth.SimplexNoise; + +@SuppressWarnings("unused") +public class HeightLayer extends BlockLayer { + private final int min; + private final int max; + private final boolean limitedToSurface; + private final boolean hasShift; + + public HeightLayer(int minY, int maxY, String name, BlockPlacer fallback) { + this(minY, maxY, true, name, fallback); + } + + public HeightLayer(int minY, int maxY, boolean hasShift, String name, BlockPlacer fallback) { + this(minY, maxY, hasShift, name, true, fallback); + } + + public HeightLayer(int minY, int maxY, boolean hasShift, String name, boolean hasCaves, BlockPlacer fallback) { + this(minY, maxY, true, hasShift, name, hasCaves, fallback); + } + + public HeightLayer(int minY, int maxY, boolean limitedToSurface, boolean hasShift, String name, boolean hasCaves, BlockPlacer fallback) { + super(name, hasCaves, fallback); + this.min = minY; + this.max = maxY; + this.hasShift = hasShift; + this.limitedToSurface = limitedToSurface; + } + + public int getMaxY() { + return max; + } + + public int getMinY() { + return min; + } + + public boolean hasShift() { + return hasShift; + } + + public boolean isLimitedToSurface() { + return limitedToSurface; + } + + @Override + public boolean is(SimplexNoise noise, int x, int y, int z, Zone zone, int minY, int seaLevel, double surfaceHeight, int genHeight, int shift) { + int y2 = hasShift ? y + shift : y; + return y2 >= min - 1 && y2 <= max && (!limitedToSurface || y < surfaceHeight); + } + + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.INT.fieldOf("min").forGetter(HeightLayer::getMinY), + Codec.INT.fieldOf("max").forGetter(HeightLayer::getMaxY), + Codec.BOOL.optionalFieldOf("limit_to_surface", true).forGetter(HeightLayer::isLimitedToSurface), + Codec.BOOL.optionalFieldOf("shift", true).forGetter(HeightLayer::hasShift), + Codec.STRING.fieldOf("name").forGetter(BlockLayer::getName), + Codec.BOOL.optionalFieldOf("has_caves", true).forGetter(BlockLayer::hasCaves), + BlockPlacer.CODEC.fieldOf("fallback").forGetter(BlockLayer::getFallback) + ).apply(instance, instance.stable(HeightLayer::new))); + + public static final ResourceLocation ID = CTerrainGeneration.id("height"); + + @Override + protected Codec codec() { + return CODEC; + } +} diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/layer/SeaLayer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/SeaLayer.java new file mode 100644 index 0000000..039ff5b --- /dev/null +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/SeaLayer.java @@ -0,0 +1,32 @@ +package dev.tocraft.crafted.ctgen.layer; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import dev.tocraft.crafted.ctgen.CTerrainGeneration; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; +import dev.tocraft.crafted.ctgen.zone.Zone; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.synth.SimplexNoise; + +public class SeaLayer extends BlockLayer { + public SeaLayer(String name, BlockPlacer fallback) { + super(name, false, fallback); + } + + @Override + public boolean is(SimplexNoise noise, int x, int y, int z, Zone zone, int minY, int seaLevel, double surfaceHeight, int genHeight, int shift) { + return y > surfaceHeight && surfaceHeight < seaLevel; + } + + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.STRING.fieldOf("name").forGetter(BlockLayer::getName), + BlockPlacer.CODEC.fieldOf("fallback").forGetter(BlockLayer::getFallback) + ).apply(instance, instance.stable(SeaLayer::new))); + + public static final ResourceLocation ID = CTerrainGeneration.id("sea"); + + @Override + protected Codec codec() { + return CODEC; + } +} diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/layer/SurfaceLayer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/SurfaceLayer.java new file mode 100644 index 0000000..528ab54 --- /dev/null +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/SurfaceLayer.java @@ -0,0 +1,37 @@ +package dev.tocraft.crafted.ctgen.layer; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import dev.tocraft.crafted.ctgen.CTerrainGeneration; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; +import dev.tocraft.crafted.ctgen.zone.Zone; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.synth.SimplexNoise; + +public class SurfaceLayer extends BlockLayer { + public SurfaceLayer(String name, BlockPlacer fallback) { + this(name, true, fallback); + } + + public SurfaceLayer(String name, boolean hasCaves, BlockPlacer fallback) { + super(name, hasCaves, fallback); + } + + @Override + public boolean is(SimplexNoise noise, int x, int y, int z, Zone zone, int minY, int seaLevel, double surfaceHeight, int genHeight, int shift) { + return y == (int) surfaceHeight; + } + + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.STRING.optionalFieldOf("name", "surface").forGetter(BlockLayer::getName), + Codec.BOOL.optionalFieldOf("has_caves", true).forGetter(BlockLayer::hasCaves), + BlockPlacer.CODEC.fieldOf("fallback").forGetter(BlockLayer::getFallback) + ).apply(instance, instance.stable(SurfaceLayer::new))); + + public static final ResourceLocation ID = CTerrainGeneration.id("sea"); + + @Override + protected Codec codec() { + return CODEC; + } +} diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/layer/WeightLayer.java b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/WeightLayer.java new file mode 100644 index 0000000..5af1af4 --- /dev/null +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/layer/WeightLayer.java @@ -0,0 +1,65 @@ +package dev.tocraft.crafted.ctgen.layer; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import dev.tocraft.crafted.ctgen.CTerrainGeneration; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; +import dev.tocraft.crafted.ctgen.zone.Zone; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.synth.SimplexNoise; + +public class WeightLayer extends BlockLayer { + private final double min; + private final double max; + private final boolean hasShift; + + public WeightLayer(double minPercentage, double maxPercentage, String name, BlockPlacer fallback) { + this(minPercentage, maxPercentage, true, name, fallback); + } + + public WeightLayer(double minPercentage, double maxPercentage, boolean hasShift, String name, BlockPlacer fallback) { + this(minPercentage, maxPercentage, hasShift, name, true, fallback); + } + + public WeightLayer(double minPercentage, double maxPercentage, boolean hasShift, String name, boolean hasCaves, BlockPlacer fallback) { + super(name, hasCaves, fallback); + this.min = minPercentage; + this.max = maxPercentage; + this.hasShift = hasShift; + } + + public double getMaxPercentage() { + return max; + } + + public double getMinPercentage() { + return min; + } + + public boolean hasShift() { + return hasShift; + } + + @Override + public boolean is(SimplexNoise noise, int x, int y, int z, Zone zone, int minY, int seaLevel, double surfaceHeight, int genHeight, int shift) { + int y2 = hasShift ? y + shift : y; + double percentage = (y2 - minY) / (surfaceHeight - minY); + return this.min <= percentage && percentage <= this.max; + } + + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.DOUBLE.fieldOf("min_percentage").forGetter(WeightLayer::getMinPercentage), + Codec.DOUBLE.fieldOf("max_percentage").forGetter(WeightLayer::getMaxPercentage), + Codec.BOOL.optionalFieldOf("shift", true).forGetter(WeightLayer::hasShift), + Codec.STRING.fieldOf("name").forGetter(BlockLayer::getName), + Codec.BOOL.optionalFieldOf("has_caves", true).forGetter(BlockLayer::hasCaves), + BlockPlacer.CODEC.fieldOf("fallback").forGetter(BlockLayer::getFallback) + ).apply(instance, instance.stable(WeightLayer::new))); + + public static final ResourceLocation ID = CTerrainGeneration.id("weight"); + + @Override + protected Codec codec() { + return CODEC; + } +} diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapBasedChunkGenerator.java b/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapBasedChunkGenerator.java index 014daae..52d47e3 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapBasedChunkGenerator.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapBasedChunkGenerator.java @@ -3,6 +3,9 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.tocraft.crafted.ctgen.CTerrainGeneration; +import dev.tocraft.crafted.ctgen.blockplacer.BasicPlacer; +import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; +import dev.tocraft.crafted.ctgen.layer.BlockLayer; import dev.tocraft.crafted.ctgen.zone.CarverSetting; import dev.tocraft.crafted.ctgen.zone.Zone; import net.minecraft.core.BlockPos; @@ -22,6 +25,7 @@ import net.minecraft.world.level.levelgen.synth.SimplexNoise; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -33,7 +37,6 @@ public class MapBasedChunkGenerator extends ChunkGenerator { ).apply(instance, instance.stable(MapBasedChunkGenerator::of))); private static final int BEDROCK_SIZE = 3; - private static final int DIRT_SIZE = 6; protected final MapBasedBiomeSource biomeSource; private SimplexNoise noise = null; @@ -72,40 +75,38 @@ public void buildSurface(@NotNull WorldGenRegion pLevel, @NotNull StructureManag double surfaceHeight = getSettings().getHeight(noise, xOff, zOff) + getSettings().surfaceLevel; int thresholdModifier = (int) getSettings().getValueWithTransition(xOff, zOff, zo -> (double) zo.thresholdModifier().orElse(getSettings().thresholdModifier)); - Block surfaceBlock = zone.surfaceBlock().get(noise, xOff, zOff, ""); - // no grass underwater - if (surfaceHeight < getSeaLevel() && surfaceBlock == Blocks.GRASS_BLOCK) { - surfaceBlock = Blocks.DIRT; - } - int shift = (int) (noise.getValue(xOff, zOff) * 3); int bedrockLevel = minHeight + shift; - int deepslateLevel = getSettings().deepslateLevel + shift; - int dirtLevel = (int) (surfaceHeight - DIRT_SIZE + shift); - for (int y = getSettings().minY; y <= surfaceHeight || y <= getSeaLevel(); y++) { + for (int y = getSettings().minY; y < surfaceHeight || y <= getSeaLevel(); y++) { BlockPos pos = chunk.getPos().getBlockAt(x, y, z); if (y < bedrockLevel) { // place bedrock chunk.setBlockState(pos, Blocks.BEDROCK.defaultBlockState(), false); - } else if (y > surfaceHeight && surfaceHeight < getSeaLevel()) { - // place oceans if the surface isn't higher than the sea level - chunk.setBlockState(pos, Blocks.WATER.defaultBlockState(), false); - // check for caves - } else if (canSetBlock(pos, surfaceHeight, getSettings().deepslateLevel, minHeight + 3, thresholdModifier)) { - if (y < deepslateLevel && deepslateLevel < surfaceHeight) { - // place deepslate - chunk.setBlockState(pos, zone.deepslateBlock().get(noise, pos.getX(), pos.getY(), pos.getZ(), "").defaultBlockState(), false); - } else if (y < dirtLevel) { - // place stone between deepslate and dirt - chunk.setBlockState(pos, zone.stoneBlock().get(noise, pos.getX(), pos.getY(), pos.getZ(), "").defaultBlockState(), false); - } else if (y < surfaceHeight - 1) { - // place dirt below surface - chunk.setBlockState(pos, zone.dirtBlock().get(noise, pos.getX(), pos.getY(), pos.getZ(), "").defaultBlockState(), false); + } else { + @Nullable BlockLayer layer = null; + for (BlockLayer blockLayer : getSettings().getLayers()) { + if (blockLayer.is(this.noise, x, y, z, zone, getMinY(), getSeaLevel(), surfaceHeight, getGenDepth(), shift)) { + layer = blockLayer; + break; + } } - // only surface is missing - else { - chunk.setBlockState(pos, surfaceBlock.defaultBlockState(), false); + + 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)) { + // no grass underwater + if (surfaceHeight < getSeaLevel() && block == Blocks.GRASS_BLOCK) { + block = Blocks.DIRT; + } + + BlockState blockState = block.defaultBlockState(); + + // is air by default, no need to place it again + if (!blockState.isAir()) { + chunk.setBlockState(pos, blockState, false); + } } } } @@ -113,10 +114,9 @@ public void buildSurface(@NotNull WorldGenRegion pLevel, @NotNull StructureManag } } - private boolean canSetBlock(BlockPos pos, double surfaceHeight, int deepslateLevel, int bedrockLevel, int thresholdModifier) { - double height = (double) (pos.getY() - bedrockLevel) / (surfaceHeight - bedrockLevel) - 0.5; - int mod = height > (deepslateLevel / (surfaceHeight - bedrockLevel) - 0.5) ? thresholdModifier : 16; - double addThreshold = height * height * height * height * mod; + private boolean canSetBlock(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()); diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapSettings.java b/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapSettings.java index 9ab77a6..04258b6 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapSettings.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapSettings.java @@ -3,6 +3,7 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.tocraft.crafted.ctgen.data.MapImageRegistry; +import dev.tocraft.crafted.ctgen.layer.BlockLayer; import dev.tocraft.crafted.ctgen.util.Noise; import dev.tocraft.crafted.ctgen.zone.CarverSetting; import dev.tocraft.crafted.ctgen.zone.Zone; @@ -16,14 +17,13 @@ import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.Optional; import java.util.function.Function; import java.util.function.Supplier; @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public final class MapSettings { - static final MapSettings DEFAULT = new MapSettings(null, true, 6, new ArrayList<>(), null, 0, 66, -64, 279, 64, 31, Noise.DEFAULT, Optional.empty(), Optional.empty(), List.of(CarverSetting.DEFAULT)); + static final MapSettings DEFAULT = new MapSettings(null, true, 1, new ArrayList<>(), null, BlockLayer.defaultLayers(-64), 66, -64, 279, 64, 31, Noise.DEFAULT, Optional.empty(), Optional.empty(), List.of(CarverSetting.DEFAULT)); public static final Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group( ResourceLocation.CODEC.fieldOf("biome_map").forGetter(o -> o.mapId), @@ -31,7 +31,7 @@ public final class MapSettings { 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.INT.optionalFieldOf("deepslate_level", DEFAULT.deepslateLevel).forGetter(o -> o.deepslateLevel), + Codec.list(BlockLayer.CODEC).optionalFieldOf("layers", DEFAULT.layers).forGetter(o -> o.layers), Codec.INT.optionalFieldOf("surface_level", DEFAULT.surfaceLevel).forGetter(o -> o.surfaceLevel), Codec.INT.optionalFieldOf("min_y", DEFAULT.minY).forGetter(o -> o.minY), Codec.INT.optionalFieldOf("gen_height", DEFAULT.genHeight).forGetter(o -> o.genHeight), @@ -48,7 +48,6 @@ public final class MapSettings { final int thresholdModifier; final List> zones; private final Holder defaultBiome; - final int deepslateLevel; final int surfaceLevel; final int minY; final int genHeight; @@ -59,15 +58,16 @@ public final class MapSettings { final Optional spawnX; final Optional spawnY; final List carverSettings; + private final List layers; @ApiStatus.Internal - public MapSettings(ResourceLocation mapId, boolean pixelsAreChunks, int thresholdModifier, List> zones, Holder defaultBiome, int deepslateLevel, int surfaceLevel, int minY, int genHeight, int seaLevel, int transition, Noise noise, Optional spawnX, Optional spawnY, List carverSettings) { + public MapSettings(ResourceLocation mapId, boolean pixelsAreChunks, int thresholdModifier, List> zones, Holder defaultBiome, List layers, int surfaceLevel, int minY, int genHeight, int seaLevel, int transition, Noise noise, Optional spawnX, Optional spawnY, List carverSettings) { this.mapId = mapId; this.pixelsAreChunks = pixelsAreChunks; this.thresholdModifier = thresholdModifier; this.zones = zones; this.defaultBiome = defaultBiome; - this.deepslateLevel = deepslateLevel; + this.layers = layers; this.surfaceLevel = surfaceLevel; this.minY = minY; this.genHeight = genHeight; @@ -92,6 +92,10 @@ public MapSettings(ResourceLocation mapId, boolean pixelsAreChunks, int threshol this.carverSettings = carverSettings; } + public List getLayers() { + return layers; + } + /** * Gets the Color from a position on the map * @@ -185,22 +189,6 @@ public int yOffset(int y) { return y + spawnY.orElseGet(() -> mapImage.get().getHeight() / 2); } - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; - var that = (MapSettings) obj; - return Objects.equals(this.mapId, that.mapId) && - Objects.equals(this.zones, that.zones) && - Objects.equals(this.defaultBiome, that.defaultBiome) && - this.deepslateLevel == that.deepslateLevel && - this.surfaceLevel == that.surfaceLevel && - this.minY == that.minY && - this.genHeight == that.genHeight && - this.seaLevel == that.seaLevel && - this.transition == that.transition; - } - @Nullable private Holder getByColor(int color) { return zones.stream().filter(biome -> biome.value().color() == color).findAny().orElse(null); diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapSettingsBuilder.java b/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapSettingsBuilder.java index d4d5bcd..c41eb87 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapSettingsBuilder.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/worldgen/MapSettingsBuilder.java @@ -1,5 +1,6 @@ package dev.tocraft.crafted.ctgen.worldgen; +import dev.tocraft.crafted.ctgen.layer.BlockLayer; import dev.tocraft.crafted.ctgen.util.Noise; import dev.tocraft.crafted.ctgen.zone.CarverSetting; import dev.tocraft.crafted.ctgen.zone.Zone; @@ -16,7 +17,7 @@ public class MapSettingsBuilder { private int thresholdModifier = MapSettings.DEFAULT.thresholdModifier; private List> zones = MapSettings.DEFAULT.zones; private Holder defaultBiome; - private int deepslateLevel = MapSettings.DEFAULT.deepslateLevel; + private List layers = MapSettings.DEFAULT.getLayers(); private int surfaceLevel = MapSettings.DEFAULT.surfaceLevel; private int minY = MapSettings.DEFAULT.minY; private int genHeight = MapSettings.DEFAULT.genHeight; @@ -52,8 +53,13 @@ public MapSettingsBuilder setDefaultBiome(Holder defaultBiome) { return this; } - public MapSettingsBuilder setDeepslateLevel(int deepslateLevel) { - this.deepslateLevel = deepslateLevel; + public MapSettingsBuilder setLayers(List layers) { + this.layers = layers; + return this; + } + + public MapSettingsBuilder addLayer(BlockLayer layer) { + this.layers.add(layer); return this; } @@ -103,6 +109,6 @@ public MapSettingsBuilder setCarverSettings(List carverSetting) { } public MapSettings build() { - return new MapSettings(biomeMapId, pixelsAreChunks, thresholdModifier, zones, defaultBiome, deepslateLevel, surfaceLevel, minY, genHeight, seaLevel, transition, noise, spawnX, spawnY, carverSettings); + return new MapSettings(biomeMapId, pixelsAreChunks, thresholdModifier, zones, defaultBiome, layers, surfaceLevel, minY, genHeight, seaLevel, transition, noise, spawnX, spawnY, carverSettings); } } \ No newline at end of file diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zone.java b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zone.java index b2066fc..aad0e20 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zone.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zone.java @@ -3,24 +3,19 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.tocraft.crafted.ctgen.CTerrainGeneration; -import dev.tocraft.crafted.ctgen.blockplacer.BasicPlacer; import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; import net.minecraft.core.Holder; import net.minecraft.resources.RegistryFileCodec; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.block.Blocks; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; -public record Zone(Holder biome, int color, BlockPlacer deepslateBlock, BlockPlacer stoneBlock, - BlockPlacer dirtBlock, - BlockPlacer surfaceBlock, int height, double perlinMultiplier, double pixelWeight, +public record Zone(Holder biome, int color, Map layers, int height, double perlinMultiplier, + double pixelWeight, Optional thresholdModifier) { - public static final BlockPlacer DEFAULT_DEEPSLATE_BLOCK = new BasicPlacer(Blocks.DEEPSLATE); - public static final BlockPlacer DEFAULT_STONE_BLOCK = new BasicPlacer(Blocks.STONE); - public static final BlockPlacer DEFAULT_DIRT_BLOCK = new BasicPlacer(Blocks.DIRT); - public static final BlockPlacer DEFAULT_SURFACE_BLOCK = new BasicPlacer(Blocks.GRASS_BLOCK); public static final int DEFAULT_HEIGHT = 0; public static final double DEFAULT_PERLIN_MULTIPLIER = 8; public static final double DEFAULT_PIXEL_WEIGHT = 1; @@ -28,10 +23,7 @@ public record Zone(Holder biome, int color, BlockPlacer deepslateBlock, B public static final Codec DIRECT_CODEC = RecordCodecBuilder.create((instance) -> instance.group( Biome.CODEC.fieldOf("biome").forGetter(Zone::biome), Codecs.COLOR.fieldOf("color").forGetter(Zone::color), - BlockPlacer.CODEC.optionalFieldOf("deepslate_block", DEFAULT_DEEPSLATE_BLOCK).forGetter(Zone::deepslateBlock), - BlockPlacer.CODEC.optionalFieldOf("stone_block", DEFAULT_STONE_BLOCK).forGetter(Zone::stoneBlock), - BlockPlacer.CODEC.optionalFieldOf("dirt_block", DEFAULT_DIRT_BLOCK).forGetter(Zone::dirtBlock), - BlockPlacer.CODEC.optionalFieldOf("surface_block", DEFAULT_SURFACE_BLOCK).forGetter(Zone::surfaceBlock), + Codec.unboundedMap(Codec.STRING, BlockPlacer.CODEC).optionalFieldOf("layers", new HashMap<>()).forGetter(Zone::layers), Codec.INT.optionalFieldOf("height", DEFAULT_HEIGHT).forGetter(Zone::height), Codec.DOUBLE.optionalFieldOf("perlin_multiplier", DEFAULT_PERLIN_MULTIPLIER).forGetter(Zone::perlinMultiplier), Codec.DOUBLE.optionalFieldOf("pixel_weight", DEFAULT_PIXEL_WEIGHT).forGetter(Zone::pixelWeight), diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/ZoneBuilder.java b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/ZoneBuilder.java index 4248dd3..ef354ae 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/ZoneBuilder.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/ZoneBuilder.java @@ -7,6 +7,8 @@ import net.minecraft.world.level.block.Block; import java.awt.*; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; @SuppressWarnings({"unused", "OptionalUsedAsFieldOrParameterType"}) @@ -16,10 +18,7 @@ public class ZoneBuilder { private int height = Zone.DEFAULT_HEIGHT; private double perlinMultiplier = Zone.DEFAULT_PERLIN_MULTIPLIER; private double pixelWeight = Zone.DEFAULT_PIXEL_WEIGHT; - private BlockPlacer deepslateBlock = Zone.DEFAULT_DEEPSLATE_BLOCK; - private BlockPlacer stoneBlock = Zone.DEFAULT_STONE_BLOCK; - private BlockPlacer dirtBlock = Zone.DEFAULT_DIRT_BLOCK; - private BlockPlacer surfaceBlock = Zone.DEFAULT_SURFACE_BLOCK; + private Map layers = new HashMap<>(); private Optional thresholdModifier = Optional.empty(); public ZoneBuilder setBiome(Holder biome) { @@ -52,43 +51,33 @@ public ZoneBuilder setPixelWeight(double pixelWeight) { return this; } - public ZoneBuilder setDeepslateBlockPlacer(BlockPlacer deepslateBlock) { - this.deepslateBlock = deepslateBlock; + public ZoneBuilder setLayers(Map layers) { + this.layers = layers; return this; } - public ZoneBuilder setStoneBlockPlacer(BlockPlacer stoneBlock) { - this.stoneBlock = stoneBlock; + public ZoneBuilder putLayer(String layer, BlockPlacer placer) { + this.layers.put(layer, placer); return this; } - public ZoneBuilder setDirtBlockPlacer(BlockPlacer dirtBlock) { - this.dirtBlock = dirtBlock; + public ZoneBuilder setDeepslateBlock(Block block) { + this.layers.put("deepslate", new BasicPlacer(block)); return this; } - public ZoneBuilder setSurfaceBlockPlacer(BlockPlacer surfaceBlock) { - this.surfaceBlock = surfaceBlock; + public ZoneBuilder setStoneBlock(Block block) { + this.layers.put("stone", new BasicPlacer(block)); return this; } - public ZoneBuilder setDeepslateBlock(Block deepslateBlock) { - this.deepslateBlock = new BasicPlacer(deepslateBlock); + public ZoneBuilder setDirtBlock(Block block) { + this.layers.put("dirt", new BasicPlacer(block)); return this; } - public ZoneBuilder setStoneBlock(Block stoneBlock) { - this.stoneBlock = new BasicPlacer(stoneBlock); - return this; - } - - public ZoneBuilder setDirtBlock(Block dirtBlock) { - this.dirtBlock = new BasicPlacer(dirtBlock); - return this; - } - - public ZoneBuilder setSurfaceBlock(Block surfaceBlock) { - this.surfaceBlock = new BasicPlacer(surfaceBlock); + public ZoneBuilder setSurfaceBlock(Block block) { + this.layers.put("surface", new BasicPlacer(block)); return this; } @@ -98,6 +87,6 @@ public ZoneBuilder setThresholdModifier(int thresholdModifier) { } public Zone build() { - return new Zone(biome, color, deepslateBlock, stoneBlock, dirtBlock, surfaceBlock, height, perlinMultiplier, pixelWeight, thresholdModifier); + return new Zone(biome, color, layers, height, perlinMultiplier, pixelWeight, thresholdModifier); } } \ No newline at end of file diff --git a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zones.java b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zones.java index b808a6e..675dc8b 100644 --- a/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zones.java +++ b/common/src/main/java/dev/tocraft/crafted/ctgen/zone/Zones.java @@ -56,7 +56,7 @@ public static void bootstrap(BootstapContext 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).setPerlinMultiplier(4).build()); context.register(BADLANDS, new ZoneBuilder().setBiome(getBiome(context, Biomes.BADLANDS)).setColor(new Color(84, 84, 56)).setDirtBlock(Blocks.RED_CONCRETE).setSurfaceBlock(Blocks.BROWN_CONCRETE).setHeight(18).setPerlinMultiplier(12).build()); - context.register(BADLANDS_MOUNTAINS, new ZoneBuilder().setBiome(getBiome(context, Biomes.BADLANDS)).setColor(new Color(70, 71, 53)).setDirtBlock(Blocks.RED_CONCRETE).setSurfaceBlockPlacer(NoisePlacer.of(new Noise(List.of(1f), 1, 1), 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(1f), 1, 1), new HashMap<>() { { put(-0.5d, Blocks.ORANGE_CONCRETE); put(0d, Blocks.RED_CONCRETE); diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands.json index c7c091b..2e88f89 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands.json @@ -5,8 +5,10 @@ "g": 84, "r": 84 }, - "dirt_block": "minecraft:red_concrete", "height": 18, "perlin_multiplier": 12.0, - "surface_block": "red_sand" + "layers": { + "dirt": "minecraft:red_concrete", + "surface": "minecraft:red_sand" + } } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands_mountains.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands_mountains.json index 5d6d867..c8d6180 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands_mountains.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/badlands_mountains.json @@ -5,21 +5,23 @@ "g": 71, "r": 70 }, - "dirt_block": "minecraft:red_concrete", "height": 28, "perlin_multiplier": 24.0, - "surface_block": { - "type": "ctgen:noise", - "default": "minecraft:brown_concrete", - "noise": { - "octaves": [ - 1 - ] - }, - "values": { - "-0.5": "minecraft:orange_concrete", - "0": "minecraft:red_concrete", - "0.5": "minecraft:gray_concrete" + "layers": { + "dirt": "minecraft:red_concrete", + "surface": { + "type": "ctgen:noise", + "default": "minecraft:brown_concrete", + "noise": { + "octaves": [ + 1 + ] + }, + "values": { + "-0.5": "minecraft:orange_concrete", + "0": "minecraft:red_concrete", + "0.5": "minecraft:gray_concrete" + } } } } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/desert.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/desert.json index 415c052..fbf5a45 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/desert.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/desert.json @@ -5,8 +5,10 @@ "g": 171, "r": 165 }, - "dirt_block": "minecraft:sandstone", "height": 5, "perlin_multiplier": 4.0, - "surface_block": "minecraft:sand" + "layers": { + "dirt": "minecraft:sandstone", + "surface": "minecraft:sand" + } } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/frozen_lake.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/frozen_lake.json index 111f8ba..4154072 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/frozen_lake.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/frozen_lake.json @@ -7,6 +7,8 @@ }, "height": -20, "pixel_weight": 3.0, - "surface_block": "minecraft:sand", + "layers": { + "surface": "minecraft:sand" + }, "threshold_modifier": 26 } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/frozen_river.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/frozen_river.json index 434b151..a26842e 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/frozen_river.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/frozen_river.json @@ -5,9 +5,11 @@ "g": 145, "r": 87 }, - "dirt_block": "minecraft:sand", "height": -15, "pixel_weight": 2.0, - "surface_block": "minecraft:sand", + "layers": { + "dirt": "minecraft:sand", + "surface": "minecraft:sand" + }, "threshold_modifier": 26 } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/lake.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/lake.json index c0612c1..b793071 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/lake.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/lake.json @@ -7,5 +7,7 @@ }, "height": -20, "pixel_weight": 3.0, - "surface_block": "minecraft:sand" + "layers": { + "surface": "minecraft:sand" + } } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/mountains.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/mountains.json index 7d502dc..31149c6 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/mountains.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/mountains.json @@ -9,5 +9,7 @@ "dirt_block": "minecraft:stone", "height": 50, "perlin_multiplier": 28.0, - "surface_block": "minecraft:stone" + "layers": { + "surface": "minecraft:stone" + } } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/ocean.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/ocean.json index 4223521..1f2585b 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/ocean.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/ocean.json @@ -7,6 +7,8 @@ }, "height": -35, "perlin_multiplier": 16.0, - "surface_block": "minecraft:sand", + "layers": { + "surface": "minecraft:sand" + }, "threshold_modifier": 26 } diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/river.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/river.json index d533c95..d2072e3 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/river.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/river.json @@ -5,9 +5,11 @@ "g": 98, "r": 1 }, - "dirt_block": "minecraft:sand", "height": -15, "pixel_weight": 2.0, - "surface_block": "minecraft:sand", + "layers": { + "dirt": "minecraft:sand", + "surface": "minecraft:sand" + }, "threshold_modifier": 26 } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/snowy_mountains.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/snowy_mountains.json index 6411882..6eefe9a 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/snowy_mountains.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/snowy_mountains.json @@ -9,5 +9,7 @@ "dirt_block": "minecraft:stone", "height": 60, "perlin_multiplier": 28.0, - "surface_block": "minecraft:snow_block" + "layers": { + "surface": "minecraft:snow_block" + } } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/snowy_slopes.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/snowy_slopes.json index 8e363d3..37dc095 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/snowy_slopes.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/snowy_slopes.json @@ -5,9 +5,11 @@ "g": 192, "r": 192 }, - "dirt_block": "minecraft:snow_block", "height": 24, "perlin_multiplier": 20.0, "pixel_weight": 1.5, - "surface_block": "minecraft:snow_block" + "layers": { + "dirt": "minecraft:snow_block", + "surface": "minecraft:snow_block" + } } \ No newline at end of file diff --git a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/stony_flats.json b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/stony_flats.json index 153280c..b073f73 100644 --- a/common/src/main/resources/data/ctgen/worldgen/map_based/zones/stony_flats.json +++ b/common/src/main/resources/data/ctgen/worldgen/map_based/zones/stony_flats.json @@ -5,7 +5,9 @@ "g": 140, "r": 130 }, - "dirt_block": "minecraft:stone", "height": 12, - "surface_block": "minecraft:stone" + "layers": { + "dirt": "minecraft:stone", + "surface": "minecraft:stone" + } } \ No newline at end of file diff --git a/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabric.java b/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabric.java index 5b81f76..ad59e39 100644 --- a/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabric.java +++ b/fabric/src/main/java/dev/tocraft/crafted/ctgen/fabric/CTGFabric.java @@ -4,6 +4,7 @@ import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; import dev.tocraft.crafted.ctgen.data.MapImageRegistry; import dev.tocraft.crafted.ctgen.impl.CTGCommand; +import dev.tocraft.crafted.ctgen.layer.BlockLayer; import dev.tocraft.crafted.ctgen.worldgen.MapBasedBiomeSource; import dev.tocraft.crafted.ctgen.worldgen.MapBasedChunkGenerator; import net.fabricmc.api.ModInitializer; @@ -52,6 +53,8 @@ public ResourceLocation getFabricId() { CommandRegistrationCallback.EVENT.register((dispatcher, context, environment) -> CTGCommand.register(dispatcher, context)); + // register built-in registry entries BlockPlacer.register(); + BlockLayer.register(); } } diff --git a/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForgeEventListener.java b/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForgeEventListener.java index 1f3118f..63b79af 100644 --- a/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForgeEventListener.java +++ b/forge/src/main/java/dev/tocraft/crafted/ctgen/forge/CTGForgeEventListener.java @@ -4,6 +4,7 @@ import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; import dev.tocraft.crafted.ctgen.data.MapImageRegistry; import dev.tocraft.crafted.ctgen.impl.CTGCommand; +import dev.tocraft.crafted.ctgen.layer.BlockLayer; import dev.tocraft.crafted.ctgen.util.CTRegistries; import dev.tocraft.crafted.ctgen.worldgen.MapBasedBiomeSource; import dev.tocraft.crafted.ctgen.worldgen.MapBasedChunkGenerator; @@ -52,5 +53,6 @@ public void register(RegisterEvent event) { // values for the built-in registries BlockPlacer.register(); + BlockLayer.register(); } }