This commit is contained in:
mcrcortex
2024-08-04 12:56:06 +10:00
parent 0366c42cf3
commit 264e26cb90
3 changed files with 0 additions and 196 deletions

View File

@@ -1,74 +0,0 @@
package me.cortex.voxy.client.terrain;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.util.MultiNoiseUtil;
import net.minecraft.world.gen.densityfunction.DensityFunction;
import net.minecraft.world.gen.noise.NoiseConfig;
import java.util.List;
public class SparseTerrainGenerator {
private final DensityFunction initialDensity;
private final DensityFunction finalDensity;
private final BiomeSource biomeSource;
private final MultiNoiseUtil.MultiNoiseSampler biomeSampler;
public SparseTerrainGenerator(NoiseConfig config, BiomeSource biomeSource) {
this.biomeSource = biomeSource;
var router = config.getNoiseRouter();
this.initialDensity = router.initialDensityWithoutJaggedness();
this.finalDensity = router.finalDensity();
this.biomeSampler = new MultiNoiseUtil.MultiNoiseSampler(router.temperature(), router.vegetation(), router.continents(), router.erosion(), router.depth(), router.ridges(), List.of());
}
public int getInitialHeight(int x, int z) {
int minHeight = -64;
int verticalCellBlockCount = 8;
int worldHeight = 384;
for(int y = minHeight + worldHeight; y >= minHeight; y -= verticalCellBlockCount) {
if (this.initialDensity.sample(new DensityFunction.UnblendedNoisePos(x, y, z)) > 0.390625) {
return y;
}
}
return Integer.MAX_VALUE;
}
public RegistryEntry<Biome> getBiome(int bx, int by, int bz) {
return this.biomeSource.getBiome(bx, by, bz, this.biomeSampler);
}
private final class NoisePos implements DensityFunction.NoisePos {
private final int x;
private final int y;
private final int z;
private NoisePos(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public int blockX() {
return this.x;
}
@Override
public int blockY() {
return this.y;
}
@Override
public int blockZ() {
return this.z;
}
}
}

View File

@@ -1,30 +0,0 @@
package me.cortex.voxy.client.terrain;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.client.MinecraftClient;
import net.minecraft.server.command.ServerCommandSource;
import static net.minecraft.server.command.CommandManager.literal;
public class TestSparseGenCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("testsparsegen")
.executes(ctx -> test()));
}
private static int test() {
var world = MinecraftClient.getInstance().getServer().getWorld(MinecraftClient.getInstance().world.getRegistryKey());
var gen = new SparseTerrainGenerator(world.getChunkManager().getNoiseConfig(), world.getChunkManager().getChunkGenerator().getBiomeSource());
long s = System.currentTimeMillis();
int c = 0;
for (int x = -50; x <= 50; x++) {
for (int z = -50; z <= 50; z++) {
var biome = gen.getBiome((x*16)>>2, 64>>2, (z*16)>>2);
int minHeight = gen.getInitialHeight(x*16, z*16);
c += minHeight;
}
}
System.err.println((System.currentTimeMillis()-s) + " e " + c);
return 0;
}
}

View File

@@ -1,92 +0,0 @@
package me.cortex.voxy.client.terrain.util;
public class QuadTreeClosestPositionFinder {
public QuadTreeClosestPositionFinder() {
}
private static abstract class Node {
}
/*
private static class InnerNode extends Node {
private final long[] nodes = new long[1+8*8+8*8*8*8];
private final Node[] children = new Node[8*8*8*8*8*8];
private long getClosestPoint(long nodePos, int cx, int cz) {
long node = -1;//this.nodes[];
if (node == -1) {
return -1;
}
float metric = Float.MAX_VALUE;
int pos = 0;
while (node != -1) {
int id = Long.numberOfTrailingZeros(node);
node &= ~(1L << id);
int x = id & 7;
int y = (id >> 3) & 7;
}
return -1;
}
}*/
/*
private static class PartialNode extends Node {
private long fullMSK;
private final Node[] children = new Node[8*8];
private final int lvl;
private PartialNode(int lvl) {
this.lvl = lvl;
}
private long getClosestPoint(int[] cacheArray, int cx, int cz) {
long node = this.fullMSK;
int minDist = Integer.MAX_VALUE;
int pointCounter = 0;
while (node != -1) {
int id = Long.numberOfTrailingZeros(node);
node &= ~(1L << id);
int x = id & 7;
int z = (id >> 3) & 7;
int dx = Math.abs(x - (cx >> this.lvl));
int dz = Math.abs(z - (cz >> this.lvl));
int dist = Math.max(dx, dz);
if (dist < minDist) {
pointCounter = 0;
minDist = dist;
}
if (dist == minDist) {
cacheArray[pointCounter++] = id;
}
}
return -1;
}
}*/
/*
private static class InnerNode extends Node {
private final Node[] nodes = new Node[4];
private final int lvl;
private static final int[] ORDERING = new int[]{
0b00_01_10_11,
0b01_00_11_10,
0b10_00_11_01,
0b11_01_10_00,
};
private InnerNode(int lvl) {
this.lvl = lvl;
}
public long getClosestEmpty(long cMin, int cx, int cz) {
int id = (((cz>>this.lvl)&1)<<1) | ((cx>>this.lvl)&1);
int ordering = ORDERING[id];
}
}*/
}