Skip to content

Commit 11ad4ce

Browse files
committed
Add terrain generation highlighting
1 parent a03520b commit 11ad4ce

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

includes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
--include-function genBiomeNoiseBetaScaled
1818
--include-function genBiomeNoiseChunkSection
1919
--include-function genBiomeNoiseScaled
20+
--include-function generateColumn
21+
--include-function generateRegion
2022
--include-function genEndScaled
2123
--include-function genNetherScaled
2224
--include-function getBiomeDepthAndScale
@@ -43,6 +45,7 @@
4345
--include-function sampleClimatePara
4446
--include-function sampleEntrances
4547
--include-function sampleFinalDensity
48+
--include-function sampleNoiseColumn
4649
--include-function sampleNoodle
4750
--include-function samplePillars
4851
--include-function samplePreliminarySurfaceLevel

src/main/java/dev/xpple/seedmapper/command/commands/HighlightCommand.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import org.jetbrains.annotations.Nullable;
3131

3232
import java.lang.foreign.Arena;
33+
import java.lang.foreign.MemoryLayout;
3334
import java.lang.foreign.MemorySegment;
35+
import java.lang.foreign.SequenceLayout;
3436
import java.util.Comparator;
3537
import java.util.HashMap;
3638
import java.util.HashSet;
@@ -252,6 +254,14 @@ private static int highlightTerrain(CustomClientCommandSource source, int chunkR
252254
int version = source.getVersion();
253255

254256
ChunkPos center = new ChunkPos(BlockPos.containing(source.getPosition()));
257+
int minChunkX = center.x - chunkRange;
258+
int minChunkZ = center.z - chunkRange;
259+
int chunkW = chunkRange * 2 + 1;
260+
int chunkH = chunkRange * 2 + 1;
261+
int blockW = chunkW << 4;
262+
int blockH = chunkH << 4;
263+
int minX = minChunkX << 4;
264+
int minZ = minChunkZ << 4;
255265

256266
try (Arena arena = Arena.ofConfined()) {
257267
MemorySegment params = TerrainNoiseParameters.allocate(arena);
@@ -260,24 +270,23 @@ private static int highlightTerrain(CustomClientCommandSource source, int chunkR
260270
}
261271

262272
Set<BlockPos> blocks = new HashSet<>();
263-
SpiralLoop.spiral(center.x, center.z, chunkRange, (chunkX, chunkZ) -> {
264-
final int minChunkX = chunkX << 4;
265-
final int minChunkZ = chunkZ << 4;
266-
for (int x = minChunkX; x < minChunkX + 16; x++) {
267-
for (int z = minChunkZ; z < minChunkZ + 16; z++) {
268-
for (int y = -64; y < 320; y++) {
269-
double spaghettiRoughness = Cubiomes.sampleSpaghettiRoughness(params, x, y, z);
270-
double entrances = Cubiomes.sampleEntrances(params, x, y, z, spaghettiRoughness);
271-
double slopedCheese = Cubiomes.sampleSlopedCheese(params, x, y, z);
272-
double sample = Cubiomes.sampleFinalDensity(params, x, y, z, spaghettiRoughness, entrances, slopedCheese);
273-
if (sample <= 0) {
274-
blocks.add(new BlockPos(x, y, z));
275-
}
273+
SequenceLayout columnLayout = MemoryLayout.sequenceLayout(384, Cubiomes.C_INT);
274+
MemorySegment blockStates = arena.allocate(columnLayout, (long) blockW * blockH);
275+
Cubiomes.generateRegion(params, minChunkX, minChunkZ, chunkW, chunkH, blockStates, MemorySegment.NULL, 0);
276+
277+
for (int relX = 0; relX < blockW; relX++) {
278+
int x = minX + relX;
279+
for (int relZ = 0; relZ < blockH; relZ++) {
280+
int z = minZ + relZ;
281+
int columnIdx = (relX * blockH + relZ) * 384;
282+
for (int y = -64; y < 320; y++) {
283+
int block = blockStates.getAtIndex(Cubiomes.C_INT, columnIdx + y + 64);
284+
if (block == 1) {
285+
blocks.add(new BlockPos(x, y, z));
276286
}
277287
}
278288
}
279-
return false;
280-
});
289+
}
281290
RenderManager.drawBoxes(blocks, 0xFF_FF0000);
282291
return blocks.size();
283292
}

src/main/java/dev/xpple/seedmapper/seedmap/SeedMapScreen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
import java.lang.foreign.Arena;
8787
import java.lang.foreign.MemoryLayout;
8888
import java.lang.foreign.MemorySegment;
89+
import java.lang.foreign.SequenceLayout;
8990
import java.lang.foreign.ValueLayout;
9091
import java.util.ArrayList;
9192
import java.util.Arrays;
@@ -123,7 +124,7 @@ public class SeedMapScreen extends Screen {
123124

124125
static {
125126
// unsigned char color[3]
126-
MemoryLayout rgbLayout = MemoryLayout.sequenceLayout(3, Cubiomes.C_CHAR);
127+
SequenceLayout rgbLayout = MemoryLayout.sequenceLayout(3, Cubiomes.C_CHAR);
127128

128129
try (Arena arena = Arena.ofConfined()) {
129130
MemorySegment biomeColoursInternal = arena.allocate(rgbLayout, biomeColours.length);

0 commit comments

Comments
 (0)