Skip to content

Commit

Permalink
Reimplement chunkgen: fewer oceans, flatter terrain, vanilla sea leve…
Browse files Browse the repository at this point in the history
…l & caves, but still no entrances
  • Loading branch information
maityyy committed Oct 14, 2024
1 parent 591cc6e commit 3d11dd7
Show file tree
Hide file tree
Showing 14 changed files with 3,098 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,62 @@
import net.minecraft.world.biome.source.util.VanillaTerrainParametersCreator;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.densityfunction.DensityFunction;
import net.minecraft.world.gen.densityfunction.DensityFunctionTypes.Spline.DensityFunctionWrapper;
import net.minecraft.world.gen.densityfunction.DensityFunctions;
import net.minecraft.world.gen.noise.NoiseParametersKeys;

import static net.minecraft.world.gen.densityfunction.DensityFunctionTypes.*;

import static moriyashiine.aylyth.common.data.world.terrain.AylythDensityFunctions.*;
import static moriyashiine.aylyth.common.data.world.terrain.AylythNoises.*;
import static net.minecraft.world.gen.densityfunction.DensityFunctions.*;
import static net.minecraft.world.gen.densityfunction.DensityFunctions.applySurfaceSlides;

public final class AylythDensityFunctionBootstrap {
private AylythDensityFunctionBootstrap() {}

public static void bootstrap(Registerable<DensityFunction> context) {
var densityFunctions = context.getRegistryLookup(RegistryKeys.DENSITY_FUNCTION);
var noiseParameters = context.getRegistryLookup(RegistryKeys.NOISE_PARAMETERS);

// VANILLACOPY

// The correct way would be to change the DensityFunctions.OFFSET_OVERWORLD

var vanillaContinentsSplinePos = new DensityFunctionWrapper(densityFunctions.getOrThrow(DensityFunctions.CONTINENTS_OVERWORLD));
var modifiedContinents = context.register(MODIFIED_CONTINENTS, flatCache(spline(net.minecraft.util.math.Spline.builder(vanillaContinentsSplinePos).add(-0.2f, 0, 0.8f).build())));

var vanillaErosionSplinePos = new DensityFunctionWrapper(densityFunctions.getOrThrow(DensityFunctions.EROSION_OVERWORLD));
var modifiedErosion = context.register(MODIFIED_EROSION, flatCache(spline(net.minecraft.util.math.Spline.builder(vanillaErosionSplinePos).add(-0.3f, 0, 0.7f).build())));

var modifiedCavesEntrances = context.register(MODIFIED_CAVES_ENTRANCES, constant(1));

// Use our continents and erosion functions

var vanillaJaggedNoise = noise(noiseParameters.getOrThrow(NoiseParametersKeys.JAGGED), 1500, 0);
registerSlopedCheeseFunction(context, densityFunctions, vanillaJaggedNoise, modifiedContinents, modifiedErosion, OVERRIDDEN_OFFSET, OVERRIDDEN_FACTOR, OVERRIDDEN_JAGGEDNESS, OVERRIDDEN_DEPTH, OVERRIDDEN_SLOPED_CHEESE, false);

var overriddenInitialDensity = createInitialDensityFunction(cache2d(holderFunction(densityFunctions.getOrThrow(OVERRIDDEN_FACTOR))), holderFunction(densityFunctions.getOrThrow(OVERRIDDEN_DEPTH)));
context.register(OVERRIDDEN_INITIAL_DENSITY_WITHOUT_JAGGEDNESS, applySurfaceSlides(false, add(overriddenInitialDensity, constant(DensityFunctions.field_38250)).clamp(-DensityFunctions.field_37691, DensityFunctions.field_37691)));

var overriddenSlopedCheese = holderFunction(densityFunctions.getOrThrow(OVERRIDDEN_SLOPED_CHEESE));
var overriddenCavesEntrance = min(overriddenSlopedCheese, mul(constant(5), holderFunction(modifiedCavesEntrances)));
var overriddenFinalCaves = rangeChoice(overriddenSlopedCheese, -1000000, DensityFunctions.field_36617, overriddenCavesEntrance, createCavesFunction(densityFunctions, noiseParameters, overriddenSlopedCheese));
context.register(OVERRIDDEN_FINALE_DENSITY, min(applyBlendDensity(applySurfaceSlides(false, overriddenFinalCaves)), holderFunction(densityFunctions.getOrThrow(DensityFunctions.CAVES_NOODLE_OVERWORLD))));

// Old

var shiftX = context.register(SHIFT_X_KEY, flatCache(cache2d(shiftA(noiseParameters.getOrThrow(OFFSET)))));
var shiftZ = context.register(SHIFT_Z_KEY, flatCache(cache2d(shiftB(noiseParameters.getOrThrow(OFFSET)))));
var ridges = context.register(RIDGES_FUNCTION_KEY, flatCache(shiftedNoise(holderFunction(shiftX), holderFunction(shiftZ), 0.25, noiseParameters.getOrThrow(RIDGE))));
var ridgesFolded = context.register(RIDGES_FOLDED_FUNCTION_KEY, mul(constant(-3.0), add(constant(-0.3333333333333333), add(constant(-0.6666666666666666), holderFunction(ridges).abs()).abs())));
var continents = context.register(CONTINENTS_FUNCTION_KEY, flatCache(shiftedNoise(holderFunction(shiftX), holderFunction(shiftZ), 0.25, noiseParameters.getOrThrow(CONTINENTS))));
var erosion = context.register(EROSION_FUNCTION_KEY, flatCache(shiftedNoise(holderFunction(shiftX), holderFunction(shiftZ), 0.25, noiseParameters.getOrThrow(EROSION))));

Spline.DensityFunctionWrapper continentsCoordinate = new Spline.DensityFunctionWrapper(continents);
Spline.DensityFunctionWrapper erosionCoordinate = new Spline.DensityFunctionWrapper(erosion);
Spline.DensityFunctionWrapper ridgesCoordinate = new Spline.DensityFunctionWrapper(ridges);
Spline.DensityFunctionWrapper ridgesFoldedCoordinate = new Spline.DensityFunctionWrapper(ridgesFolded);
DensityFunctionWrapper continentsCoordinate = new DensityFunctionWrapper(continents);
DensityFunctionWrapper erosionCoordinate = new DensityFunctionWrapper(erosion);
DensityFunctionWrapper ridgesCoordinate = new DensityFunctionWrapper(ridges);
DensityFunctionWrapper ridgesFoldedCoordinate = new DensityFunctionWrapper(ridgesFolded);

var offset = context.register(OFFSET_FUNCTION_KEY, offset(continentsCoordinate, erosionCoordinate, ridgesFoldedCoordinate));
var factor = context.register(FACTOR_FUNCTION_KEY, factor(continentsCoordinate, erosionCoordinate, ridgesCoordinate, ridgesFoldedCoordinate));
Expand All @@ -47,7 +80,7 @@ public static void bootstrap(Registerable<DensityFunction> context) {
context.register(SLOPED_CHEESE_FUNCTION_KEY, slopedCheese(depth, jaggedness, factor, noiseParameters));
}

private static DensityFunction offset(Spline.DensityFunctionWrapper continentsCoordinate, Spline.DensityFunctionWrapper erosionCoordinate, Spline.DensityFunctionWrapper ridgesFoldedCoordinate) {
private static DensityFunction offset(DensityFunctionWrapper continentsCoordinate, DensityFunctionWrapper erosionCoordinate, DensityFunctionWrapper ridgesFoldedCoordinate) {
return withBlending(
add(
constant(-0.50375f),
Expand Down Expand Up @@ -76,14 +109,14 @@ private static DensityFunction aylythY() {
);
}

private static DensityFunction factor(Spline.DensityFunctionWrapper continentsCoordinate, Spline.DensityFunctionWrapper erosionCoordinate, Spline.DensityFunctionWrapper ridgesCoordinate, Spline.DensityFunctionWrapper ridgesFoldedCoordinate) {
private static DensityFunction factor(DensityFunctionWrapper continentsCoordinate, DensityFunctionWrapper erosionCoordinate, DensityFunctionWrapper ridgesCoordinate, DensityFunctionWrapper ridgesFoldedCoordinate) {
return withBlending(
spline(VanillaTerrainParametersCreator.createFactorSpline(continentsCoordinate, erosionCoordinate, ridgesCoordinate, ridgesFoldedCoordinate, false)),
constant(10)
);
}

private static DensityFunction jaggedness(Spline.DensityFunctionWrapper continentsCoordinate, Spline.DensityFunctionWrapper erosionCoordinate, Spline.DensityFunctionWrapper ridgesCoordinate, Spline.DensityFunctionWrapper ridgesFoldedCoordinate) {
private static DensityFunction jaggedness(DensityFunctionWrapper continentsCoordinate, DensityFunctionWrapper erosionCoordinate, DensityFunctionWrapper ridgesCoordinate, DensityFunctionWrapper ridgesFoldedCoordinate) {
return withBlending(
spline(VanillaTerrainParametersCreator.createJaggednessSpline(continentsCoordinate, erosionCoordinate, ridgesCoordinate, ridgesFoldedCoordinate, false)),
constant(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package moriyashiine.aylyth.datagen.common.world.terrain;

import moriyashiine.aylyth.common.data.world.AylythDimensionData;
import moriyashiine.aylyth.common.data.world.terrain.AylythDensityFunctions;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand All @@ -9,9 +10,11 @@
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.math.noise.DoublePerlinNoiseSampler;
import net.minecraft.world.biome.source.util.MultiNoiseUtil;
import net.minecraft.world.biome.source.util.MultiNoiseUtil.NoiseHypercube;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import net.minecraft.world.gen.chunk.GenerationShapeConfig;
import net.minecraft.world.gen.densityfunction.DensityFunction;
import net.minecraft.world.gen.densityfunction.DensityFunctions;
import net.minecraft.world.gen.noise.NoiseRouter;

import java.util.List;
Expand All @@ -24,7 +27,44 @@ public final class AylythNoiseSettingBootstrap {
private AylythNoiseSettingBootstrap() {}

public static void bootstrap(Registerable<ChunkGeneratorSettings> context) {
context.register(AylythDimensionData.CHUNK_GEN_SETTINGS, createSettings(context.getRegistryLookup(RegistryKeys.DENSITY_FUNCTION), context.getRegistryLookup(RegistryKeys.NOISE_PARAMETERS)));
var densityFunctions = context.getRegistryLookup(RegistryKeys.DENSITY_FUNCTION);
var noiseParameters = context.getRegistryLookup(RegistryKeys.NOISE_PARAMETERS);

// VANILLACOPY ChunkGeneratorSettings.OVERWORLD
// Fewer oceans, flatter terrain, disable ore veins, no caves entrances, height 384 -> 304, vertical size 2 -> 1

var vanillaChunkGenSettings = ChunkGeneratorSettings.createSurfaceSettings(context, false, false);

var vanillaShape = vanillaChunkGenSettings.generationShapeConfig();
var shape = new GenerationShapeConfig(vanillaShape.minimumY(), 304, vanillaShape.horizontalSize(), 1);

var vanillaNoiseRouter = DensityFunctions.createSurfaceNoiseRouter(densityFunctions, noiseParameters, false, false);
var noiseRouter = new NoiseRouter(
vanillaNoiseRouter.barrierNoise(),
vanillaNoiseRouter.fluidLevelFloodednessNoise(),
vanillaNoiseRouter.fluidLevelSpreadNoise(),
vanillaNoiseRouter.lavaNoise(),
vanillaNoiseRouter.temperature(),
vanillaNoiseRouter.vegetation(),
AylythDensityFunctionBootstrap.holderFunction(densityFunctions.getOrThrow(MODIFIED_CONTINENTS)),
AylythDensityFunctionBootstrap.holderFunction(densityFunctions.getOrThrow(AylythDensityFunctions.MODIFIED_EROSION)),
AylythDensityFunctionBootstrap.holderFunction(densityFunctions.getOrThrow(OVERRIDDEN_DEPTH)),
vanillaNoiseRouter.ridges(),
AylythDensityFunctionBootstrap.holderFunction(densityFunctions.getOrThrow(OVERRIDDEN_INITIAL_DENSITY_WITHOUT_JAGGEDNESS)),
AylythDensityFunctionBootstrap.holderFunction(densityFunctions.getOrThrow(OVERRIDDEN_FINALE_DENSITY)),
zero(),
zero(),
zero()
);

var materialRules = AylythMaterialRuleBootstrap.materialRules();
var spawnTarget = List.<NoiseHypercube>of();
var seaLevel = vanillaChunkGenSettings.seaLevel();

context.register(AylythDimensionData.CHUNK_GEN_SETTINGS, new ChunkGeneratorSettings(shape, Blocks.DEEPSLATE.getDefaultState(), Blocks.WATER.getDefaultState(), noiseRouter, materialRules, spawnTarget, seaLevel, false, true, false, false));

// Old
// context.register(AylythDimensionData.CHUNK_GEN_SETTINGS, createSettings(context.getRegistryLookup(RegistryKeys.DENSITY_FUNCTION), context.getRegistryLookup(RegistryKeys.NOISE_PARAMETERS)));
}

static ChunkGeneratorSettings createSettings(RegistryEntryLookup<DensityFunction> functions, RegistryEntryLookup<DoublePerlinNoiseSampler.NoiseParameters> noiseParameters) {
Expand Down Expand Up @@ -164,7 +204,7 @@ static DensityFunction finalDensity(RegistryEntryLookup<DensityFunction> functio
);
}

static List<MultiNoiseUtil.NoiseHypercube> spawnTargets() {
static List<NoiseHypercube> spawnTargets() {
return List.of();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type": "minecraft:flat_cache",
"argument": {
"type": "minecraft:spline",
"spline": {
"coordinate": "minecraft:overworld/continents",
"points": [
{
"derivative": 0.8,
"location": -0.2,
"value": 0.0
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type": "minecraft:flat_cache",
"argument": {
"type": "minecraft:spline",
"spline": {
"coordinate": "minecraft:overworld/erosion",
"points": [
{
"derivative": 0.7,
"location": -0.3,
"value": 0.0
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "minecraft:add",
"argument1": {
"type": "minecraft:y_clamped_gradient",
"from_value": 1.5,
"from_y": -64,
"to_value": -1.5,
"to_y": 320
},
"argument2": "aylyth:overridden_offset"
}
Loading

0 comments on commit 3d11dd7

Please sign in to comment.