Skip to content

Commit 703dd96

Browse files
authored
Add terrain noise debug features (xpple#101)
* Add terrain noise debug features * Fix DLL name * Add debug ls command * Fix DLL location * Update Cubiomes * Update Windows build script to use MSYS2 * [ci skip] Add windows-latest to step name * Update README * Add dimension checks
1 parent 7c7edff commit 703dd96

File tree

16 files changed

+279
-22
lines changed

16 files changed

+279
-22
lines changed

.github/workflows/build.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ jobs:
1414
matrix:
1515
os: [ubuntu-latest, macos-latest, windows-latest]
1616
runs-on: ${{ matrix.os }}
17-
env:
18-
SRC_FILES: noise.c biomes.c layers.c biomenoise.c generator.c finders.c util.c quadbase.c loot/items.c loot/loot_functions.c loot/loot_tables.c loot/loot_table_context.c loot/loot_table_parser.c loot/loot_tables/bastion_bridge_1_16_1.c loot/loot_tables/bastion_bridge_1_16_5.c loot/loot_tables/bastion_bridge_1_20.c loot/loot_tables/bastion_other_1_16_1.c loot/loot_tables/bastion_other_1_16_5.c loot/loot_tables/bastion_other_1_20.c loot/loot_tables/bastion_other_1_21_1.c loot/loot_tables/bastion_other_1_21_9.c loot/loot_tables/buried_treasure_1_13.c loot/loot_tables/buried_treasure_1_18.c loot/loot_tables/desert_pyramid_1_13.c loot/loot_tables/desert_pyramid_1_20.c loot/loot_tables/desert_pyramid_1_21_6.c loot/loot_tables/desert_pyramid_1_21_9.c loot/loot_tables/end_city_treasure_1_13.c loot/loot_tables/end_city_treasure_1_20.c loot/loot_tables/end_city_treasure_1_21_9.c loot/loot_tables/igloo_chest_1_13.c loot/loot_tables/jungle_temple_1_13.c loot/loot_tables/jungle_temple_1_14.c loot/loot_tables/jungle_temple_1_20.c loot/loot_tables/jungle_temple_1_21_6.c loot/loot_tables/jungle_temple_1_21_9.c loot/loot_tables/jungle_temple_dispenser_1_13.c loot/loot_tables/nether_bridge_1_13.c loot/loot_tables/nether_bridge_1_20.c loot/loot_tables/nether_bridge_1_21_9.c loot/loot_tables/pillager_outpost_1_14.c loot/loot_tables/pillager_outpost_1_19_2.c loot/loot_tables/pillager_outpost_1_20.c loot/loot_tables/ruined_portal_1_16_1.c loot/loot_tables/ruined_portal_1_21_5.c loot/loot_tables/shipwreck_map_1_13.c loot/loot_tables/shipwreck_map_1_18.c loot/loot_tables/shipwreck_map_1_20.c loot/loot_tables/shipwreck_supply_1_13.c loot/loot_tables/shipwreck_supply_1_14.c loot/loot_tables/shipwreck_supply_1_17.c loot/loot_tables/shipwreck_supply_1_20.c loot/loot_tables/shipwreck_treasure_1_13.c loot/loot_tables/shipwreck_treasure_1_20.c loot/cjson/cJSON.c
1917
steps:
2018
- name: Checkout repository
2119
uses: actions/checkout@v4
@@ -25,20 +23,35 @@ jobs:
2523
- name: Compile shared library (ubuntu-latest)
2624
if: matrix.os == 'ubuntu-latest'
2725
working-directory: src/main/c/cubiomes
28-
run: gcc -shared -o ../../resources/libcubiomes.so $SRC_FILES -O3 -fPIC
26+
run: |
27+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
28+
cmake --build build --config Release
29+
cp build/libcubiomes.so ../../resources/libcubiomes.so
2930
- name: Compile shared library (macos-latest)
3031
if: matrix.os == 'macos-latest'
3132
working-directory: src/main/c/cubiomes
3233
run: |
33-
gcc -shared -o ../../resources/libcubiomes_arm64.dylib -arch arm64 $SRC_FILES -O3 -fPIC
34-
gcc -shared -o ../../resources/libcubiomes_x86_64.dylib -arch x86_64 $SRC_FILES -O3 -fPIC
35-
lipo -create -output ../../resources/libcubiomes.dylib ../../resources/libcubiomes_arm64.dylib ../../resources/libcubiomes_x86_64.dylib
34+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
35+
cmake --build build --config Release
36+
cp build/libcubiomes.dylib ../../resources/libcubiomes.dylib
37+
- name: Set up MSYS2 (windows-latest)
38+
if: matrix.os == 'windows-latest'
39+
uses: msys2/setup-msys2@v2
40+
with:
41+
update: true
42+
install: >
43+
base-devel
44+
mingw-w64-x86_64-toolchain
45+
mingw-w64-x86_64-cmake
46+
mingw-w64-x86_64-ninja
3647
- name: Compile shared library (windows-latest)
3748
if: matrix.os == 'windows-latest'
3849
working-directory: src/main/c/cubiomes
50+
shell: msys2 {0}
3951
run: |
40-
$src = $env:SRC_FILES.Split(" ")
41-
gcc -shared -o ../../resources/cubiomes.dll $src -O3
52+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
53+
cmake --build build --config Release
54+
cp build/cubiomes.dll ../../resources/cubiomes.dll
4255
4356
- name: Compute SHA256 hash (ubuntu-latest)
4457
if: matrix.os == 'ubuntu-latest'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ classes/
1616
*.ipr
1717
*.iws
1818

19+
!.idea/scopes/
20+
!.idea/icon.png
21+
1922
# vscode
2023

2124
.settings/

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ To build the mod locally, follow these steps:
8282
git clone --recurse-submodules https://github.com/xpple/SeedMapper
8383
cd SeedMapper
8484
```
85-
2. Compile cubiomes to a shared library. The following is for Windows:
85+
2. Compile cubiomes to a shared library. MSVC cannot be used to build the project! The following is for Windows:
8686
```shell
87-
gcc -shared -o src/main/resources/cubiomes.dll [...] -O3
87+
cd src/main/c/cubiomes
88+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
89+
cmake --build build --config Release
90+
cp build/cubiomes.dll ../../resources/cubiomes.dll
91+
cd ../../../../
8892
```
8993
3. Install LLVM (version 13.0.0 is recommended) and set the environment variable `LLVM_HOME` to the directory where LLVM was installed.
9094
4. Compile jextract. Again, the following is for Windows:

buildSrc/src/main/java/dev/xpple/seedmapper/buildscript/CreateJavaBindingsTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public abstract class CreateJavaBindingsTask extends Exec {
1313

1414
this.setWorkingDir(this.getProject().getRootDir());
1515
this.setStandardOutput(System.out);
16-
this.commandLine("./jextract/build/jextract/bin/jextract" + EXTENSION, "--include-dir", "src/main/c/cubiomes", "--output", "src/main/java", "--use-system-load-library", "--target-package", "com.github.cubiomes", "--header-class-name", "Cubiomes", "@includes.txt", "biomenoise.h", "biomes.h", "finders.h", "generator.h", "layers.h", "noise.h", "quadbase.h", "rng.h", "util.h", "loot/items.h", "loot/logging.h", "loot/loot_functions.h", "loot/loot_table_context.h", "loot/loot_table_parser.h", "loot/loot_tables.h", "loot/mc_loot.h");
16+
this.commandLine("./jextract/build/jextract/bin/jextract" + EXTENSION, "--include-dir", "src/main/c/cubiomes", "--output", "src/main/java", "--use-system-load-library", "--target-package", "com.github.cubiomes", "--header-class-name", "Cubiomes", "@includes.txt", "biomenoise.h", "biomes.h", "finders.h", "generator.h", "layers.h", "biomenoise.h", "biomes.h", "noise.h", "rng.h", "util.h", "quadbase.h", "xrms.h", "loot/items.h", "loot/logging.h", "loot/loot_functions.h", "loot/loot_table_context.h", "loot/loot_table_parser.h", "loot/loot_tables.h", "loot/mc_loot.h");
1717
}
1818
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ minecraft_version_dependency=>=1.21.10 <1.22
1414
# Fabric Properties
1515
# check these on https://fabricmc.net/develop
1616
# https://maven.parchmentmc.org/org/parchmentmc/data/
17-
fabric_api_version=0.135.0+1.21.10
17+
fabric_api_version=0.138.3+1.21.10
1818
parchment_mappings=parchment-1.21.9:2025.10.05@zip
1919
fabric_loader_version=0.17.3
20-
fabric_loom_version=1.11-SNAPSHOT
20+
fabric_loom_version=1.13-SNAPSHOT
2121

2222
# Library dependencies
2323
betterconfig_version=2.5.0

includes.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
--include-struct BiomeNoise
22
--include-struct BiomeNoiseBeta
33
--include-struct BiomeTree
4+
--include-struct BlendedNoise
45
--include-struct EndNoise
56
--include-struct FixSpline
67
--include-struct NetherNoise
@@ -10,6 +11,7 @@
1011
--include-struct SplineStack
1112
--include-struct SurfaceNoise
1213
--include-struct SurfaceNoiseBeta
14+
--include-struct TerrainNoiseParameters
1315
--include-function approxSurfaceBeta
1416
--include-function climateToBiome
1517
--include-function genBiomeNoiseBetaScaled
@@ -23,18 +25,35 @@
2325
--include-function getOldBetaBiome
2426
--include-function getVoronoiSrcRange
2527
--include-function initBiomeNoise
28+
--include-function initBlendedNoise
2629
--include-function initSurfaceNoise
2730
--include-function initSurfaceNoiseBeta
31+
--include-function initTerrainNoise
2832
--include-function mapEnd
2933
--include-function mapEndBiome
3034
--include-function mapEndSurfaceHeight
3135
--include-function mapNether2D
3236
--include-function mapNether3D
37+
--include-function sampleBase3dNoise
3338
--include-function sampleBiomeNoise
3439
--include-function sampleBiomeNoiseBeta
40+
--include-function sampleCaveCheese
41+
--include-function sampleCaveEntrance
42+
--include-function sampleCaveLayer
3543
--include-function sampleClimatePara
44+
--include-function sampleEntrances
45+
--include-function sampleFinalDensity
46+
--include-function sampleNoodle
47+
--include-function samplePillars
48+
--include-function samplePreliminarySurfaceLevel
49+
--include-function sampleSlopedCheese
50+
--include-function sampleSpaghetti2d
51+
--include-function sampleSpaghetti3d
52+
--include-function sampleSpaghetti2dThicknessModulator
53+
--include-function sampleSpaghettiRoughness
3654
--include-function sampleSurfaceNoise
3755
--include-function sampleSurfaceNoiseBetween
56+
--include-function sampleUnderground
3857
--include-function setBetaBiomeSeed
3958
--include-function setBiomeSeed
4059
--include-function setClimateParaSeed
@@ -907,6 +926,7 @@
907926
--include-function sampleSimplex2D
908927
--include-function xDoublePerlinInit
909928
--include-function xOctaveInit
929+
--include-function xOctaveLegacyInit
910930
--include-function xPerlinInit
911931

912932
--include-function getOptimalAfk

src/main/java/dev/xpple/seedmapper/SeedMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import dev.xpple.seedmapper.command.commands.DiscordCommand;
1212
import dev.xpple.seedmapper.command.commands.HighlightCommand;
1313
import dev.xpple.seedmapper.command.commands.LocateCommand;
14+
import dev.xpple.seedmapper.command.commands.SampleCommand;
1415
import dev.xpple.seedmapper.command.commands.SeedMapCommand;
1516
import dev.xpple.seedmapper.command.commands.SourceCommand;
1617
import dev.xpple.seedmapper.command.commands.StopTaskCommand;
@@ -96,5 +97,6 @@ private static void registerCommands(CommandDispatcher<FabricClientCommandSource
9697
StopTaskCommand.register(dispatcher);
9798
SeedMapCommand.register(dispatcher);
9899
DiscordCommand.register(dispatcher);
100+
SampleCommand.register(dispatcher);
99101
}
100102
}

src/main/java/dev/xpple/seedmapper/command/CommandExceptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ private CommandExceptions() {
2323
public static final DynamicCommandExceptionType UNKNOWN_ENCHANTMENT_EXCEPTION = new DynamicCommandExceptionType(arg -> Component.translatable("commands.exceptions.unknownEnchantment", arg));
2424
public static final DynamicCommandExceptionType UNKNOWN_CANYON_CARVER_EXCEPTION = new DynamicCommandExceptionType(arg -> Component.translatable("commands.exceptions.unknownCanyonCarver", arg));
2525
public static final DynamicCommandExceptionType UNKNOWN_CAVE_CARVER_EXCEPTION = new DynamicCommandExceptionType(arg -> Component.translatable("commands.exceptions.unknownCaveCarver", arg));
26+
public static final DynamicCommandExceptionType UNKNOWN_DENSITY_FUNCTION_EXCEPTION = new DynamicCommandExceptionType(arg -> Component.translatable("commands.exceptions.unknownDensityFunction", arg));
2627
public static final DynamicCommandExceptionType UNKNOWN_MAP_FEATURE_EXCEPTION = new DynamicCommandExceptionType(arg -> Component.translatable("commands.exceptions.unknownMapFeature", arg));
2728
public static final SimpleCommandExceptionType NO_SEED_AVAILABLE_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.exceptions.noSeedAvailable"));
2829
public static final DynamicCommandExceptionType NO_BIOME_FOUND_EXCEPTION = new DynamicCommandExceptionType(arg -> Component.translatable("commands.exceptions.noBiomeFound", arg));
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package dev.xpple.seedmapper.command.arguments;
2+
3+
import com.github.cubiomes.Cubiomes;
4+
import com.github.cubiomes.TerrainNoiseParameters;
5+
import com.google.common.collect.ImmutableMap;
6+
import com.mojang.brigadier.StringReader;
7+
import com.mojang.brigadier.arguments.ArgumentType;
8+
import com.mojang.brigadier.context.CommandContext;
9+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
10+
import com.mojang.brigadier.suggestion.Suggestions;
11+
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
12+
import dev.xpple.seedmapper.command.CommandExceptions;
13+
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
14+
import net.minecraft.commands.SharedSuggestionProvider;
15+
16+
import java.lang.foreign.MemorySegment;
17+
import java.util.Arrays;
18+
import java.util.Collection;
19+
import java.util.Map;
20+
import java.util.concurrent.CompletableFuture;
21+
22+
public class DensityFunctionArgument implements ArgumentType<DensityFunctionArgument.DensityFunction> {
23+
24+
private static final Collection<String> EXAMPLES = Arrays.asList("overworld", "the_nether", "the_end");
25+
26+
public static final Map<String, DensityFunction> DENSITY_FUNCTIONS = ImmutableMap.<String, DensityFunction>builder()
27+
.put("overworld.base_3d_noise", (params, x, y, z) -> Cubiomes.sampleBase3dNoise(TerrainNoiseParameters.bln(params), x, y, z))
28+
.put("overworld.caves.spaghetti_roughness_function", Cubiomes::sampleSpaghettiRoughness)
29+
.put("overworld.caves.spaghetti_2d_thickness_modulator", Cubiomes::sampleSpaghetti2dThicknessModulator)
30+
.put("overworld.caves.spaghetti_2d", Cubiomes::sampleSpaghetti2d)
31+
.put("spaghetti_3d", Cubiomes::sampleSpaghetti3d)
32+
.put("cave_entrance", Cubiomes::sampleCaveEntrance)
33+
.put("overworld.caves.entrances", (params, x, y, z) -> Cubiomes.sampleEntrances(params, x, y, z, Cubiomes.sampleSpaghettiRoughness(params, x, y, z)))
34+
.put("cave_layer", Cubiomes::sampleCaveLayer)
35+
.put("overworld.sloped_cheese", Cubiomes::sampleSlopedCheese)
36+
.put("cave_cheese", (params, x, y, z) -> Cubiomes.sampleCaveCheese(params, x, y, z, Cubiomes.sampleSlopedCheese(params, x, y, z)))
37+
.put("overworld.caves.pillars", Cubiomes::samplePillars)
38+
.put("overworld.caves.noodle", Cubiomes::sampleNoodle)
39+
.put("underground", (params, x, y, z) -> {
40+
double spaghettiRoughness = Cubiomes.sampleSpaghettiRoughness(params, x, y, z);
41+
return Cubiomes.sampleUnderground(params, x, y, z, spaghettiRoughness, Cubiomes.sampleEntrances(params, x, y, z, spaghettiRoughness), Cubiomes.sampleSlopedCheese(params, x, y, z));
42+
})
43+
.put("final_density", (params, x, y, z) -> {
44+
double spaghettiRoughness = Cubiomes.sampleSpaghettiRoughness(params, x, y, z);
45+
return Cubiomes.sampleFinalDensity(params, x, y, z, spaghettiRoughness, Cubiomes.sampleEntrances(params, x, y, z, spaghettiRoughness), Cubiomes.sampleSlopedCheese(params, x, y, z));
46+
})
47+
.put("preliminary_surface_level", (params, x, _, z) -> Cubiomes.samplePreliminarySurfaceLevel(params, x, z))
48+
.build();
49+
50+
public static DensityFunctionArgument densityFunction() {
51+
return new DensityFunctionArgument();
52+
}
53+
54+
public static DensityFunction getDensityFunction(CommandContext<FabricClientCommandSource> context, String name) {
55+
return context.getArgument(name, DensityFunction.class);
56+
}
57+
58+
@Override
59+
public DensityFunction parse(StringReader reader) throws CommandSyntaxException {
60+
int cursor = reader.getCursor();
61+
String densityFunctionString = reader.readUnquotedString();
62+
DensityFunction densityFunction = DENSITY_FUNCTIONS.get(densityFunctionString);
63+
if (densityFunction == null) {
64+
reader.setCursor(cursor);
65+
throw CommandExceptions.UNKNOWN_DENSITY_FUNCTION_EXCEPTION.create(densityFunctionString);
66+
}
67+
return densityFunction;
68+
}
69+
70+
@Override
71+
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
72+
return SharedSuggestionProvider.suggest(DENSITY_FUNCTIONS.keySet(), builder);
73+
}
74+
75+
@Override
76+
public Collection<String> getExamples() {
77+
return EXAMPLES;
78+
}
79+
80+
@FunctionalInterface
81+
public interface DensityFunction {
82+
double compute(MemorySegment terrainNoiseParameters, int x, int y, int z);
83+
}
84+
}

0 commit comments

Comments
 (0)