This commit is contained in:
mcrcortex
2023-11-15 10:10:03 +10:00
parent 046a419e4f
commit da9897a11e
7 changed files with 122 additions and 4 deletions

View File

@@ -33,6 +33,7 @@ dependencies {
modImplementation(fabricApi.module("fabric-api-base", project.fabric_version)) modImplementation(fabricApi.module("fabric-api-base", project.fabric_version))
modImplementation(fabricApi.module("fabric-rendering-fluids-v1", project.fabric_version)) modImplementation(fabricApi.module("fabric-rendering-fluids-v1", project.fabric_version))
modImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_version)) modImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_version))
modImplementation(fabricApi.module("fabric-command-api-v2", project.fabric_version))
modImplementation("net.fabricmc.fabric-api:fabric-rendering-data-attachment-v1:0.3.38+73761d2e9a") modImplementation("net.fabricmc.fabric-api:fabric-rendering-data-attachment-v1:0.3.38+73761d2e9a")
modImplementation "maven.modrinth:sodium:mc1.20.2-0.5.3" modImplementation "maven.modrinth:sodium:mc1.20.2-0.5.3"

View File

@@ -1,4 +1,13 @@
package me.cortex.voxelmon; package me.cortex.voxelmon;
public class Voxelmon { import me.cortex.voxelmon.terrain.TestSparseGenCommand;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
public class Voxelmon implements ClientModInitializer {
@Override
public void onInitializeClient() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> TestSparseGenCommand.register(dispatcher));
}
} }

View File

@@ -57,7 +57,7 @@ public class VoxelCore {
//Trigger the shared index buffer loading //Trigger the shared index buffer loading
SharedIndexBuffer.INSTANCE.id(); SharedIndexBuffer.INSTANCE.id();
this.renderer = new Gl46FarWorldRenderer(); this.renderer = new Gl46FarWorldRenderer();
this.world = new WorldEngine(new File("ethoslab.db"), 16, 5);//"hc9.db"//"storagefile.db" this.world = new WorldEngine(new File("storagefile.db"), 16, 5);//"hc9.db"//"storagefile.db"
this.renderTracker = new RenderTracker(this.world, this.renderer); this.renderTracker = new RenderTracker(this.world, this.renderer);
this.renderGen = new RenderGenerationService(this.world, this.renderTracker,4); this.renderGen = new RenderGenerationService(this.world, this.renderTracker,4);
@@ -90,7 +90,7 @@ public class VoxelCore {
//WorldImporter importer = new WorldImporter(this.world, MinecraftClient.getInstance().world); //WorldImporter importer = new WorldImporter(this.world, MinecraftClient.getInstance().world);
//importer.importWorldAsyncStart(new File("saves/Etho's LP Ep550/region")); //importer.importWorldAsyncStart(new File("saves/New World/region"));
Set<Block> biomeTintableAllFaces = new HashSet<>(List.of(Blocks.OAK_LEAVES, Blocks.JUNGLE_LEAVES, Blocks.ACACIA_LEAVES, Blocks.DARK_OAK_LEAVES, Blocks.VINE, Blocks.MANGROVE_LEAVES, Set<Block> biomeTintableAllFaces = new HashSet<>(List.of(Blocks.OAK_LEAVES, Blocks.JUNGLE_LEAVES, Blocks.ACACIA_LEAVES, Blocks.DARK_OAK_LEAVES, Blocks.VINE, Blocks.MANGROVE_LEAVES,
Blocks.TALL_GRASS, Blocks.LARGE_FERN)); Blocks.TALL_GRASS, Blocks.LARGE_FERN));

View File

@@ -78,11 +78,13 @@ public class WorldEngine {
public void tryUnload(WorldSection section) { public void tryUnload(WorldSection section) {
synchronized (this.loadedSectionCache[section.lvl]) { synchronized (this.loadedSectionCache[section.lvl]) {
if (section.getRefCount() != 0) { if (section.getRefCount() != 0) {
section.assertNotFree();
return; return;
} }
//TODO: make a thing where it checks if the section is dirty, if it is, enqueue it for a save first and return //TODO: make a thing where it checks if the section is dirty, if it is, enqueue it for a save first and return
section.setFreed(); section.setFreed();//TODO: FIXME THIS IS SOMEHOW FAILING
var removedSection = this.loadedSectionCache[section.lvl].remove(section.getKey()); var removedSection = this.loadedSectionCache[section.lvl].remove(section.getKey());
if (removedSection != section) { if (removedSection != section) {
throw new IllegalStateException("Removed section not the same as attempted to remove"); throw new IllegalStateException("Removed section not the same as attempted to remove");

View File

@@ -0,0 +1,75 @@
package me.cortex.voxelmon.terrain;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.math.ColumnPos;
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

@@ -0,0 +1,30 @@
package me.cortex.voxelmon.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

@@ -11,6 +11,7 @@
"icon": "assets/voxelmon/icon.png", "icon": "assets/voxelmon/icon.png",
"environment": "client", "environment": "client",
"entrypoints": { "entrypoints": {
"client": ["me.cortex.voxelmon.Voxelmon"]
}, },
"mixins": [ "mixins": [
"voxelmon.mixins.json" "voxelmon.mixins.json"