build chunk generator addon

This commit is contained in:
dfsek
2021-07-07 10:54:25 -07:00
parent 66a5cce399
commit 99d64fec36
20 changed files with 64 additions and 83 deletions

View File

@@ -8,6 +8,7 @@ import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.world.TerraWorld;
import com.dfsek.terra.api.util.seeded.BiomeProviderBuilder;
import com.dfsek.terra.api.world.generator.ChunkGeneratorProvider;
import java.util.Map;
import java.util.Set;
@@ -46,4 +47,6 @@ public interface ConfigPack extends LoaderRegistrar, LoaderHolder, RegistryHolde
boolean vanillaFlora();
RegistryFactory getRegistryFactory();
ChunkGeneratorProvider getGeneratorProvider();
}

View File

@@ -0,0 +1,8 @@
package com.dfsek.terra.api.world;
import com.dfsek.terra.api.world.ChunkAccess;
import com.dfsek.terra.api.world.World;
public interface Carver {
void carve(World world, int chunkX, int chunkZ, ChunkAccess chunk);
}

View File

@@ -3,5 +3,5 @@ package com.dfsek.terra.api.world.generator;
import com.dfsek.terra.api.config.ConfigPack;
public interface ChunkGeneratorProvider {
ChunkGenerator newInstance(ConfigPack pack);
TerraChunkGenerator newInstance(ConfigPack pack);
}

View File

@@ -0,0 +1,38 @@
package com.dfsek.terra.api.world.generator;
import com.dfsek.terra.api.util.mutable.MutableInteger;
import com.dfsek.terra.api.world.biome.Generator;
import java.util.Map;
public interface ChunkInterpolator {
/**
* Gets the noise at a pair of internal chunk coordinates.
*
* @param x The internal X coordinate (0-15).
* @param z The internal Z coordinate (0-15).
* @return double - The interpolated noise at the coordinates.
*/
double getNoise(double x, double y, double z);
default double getNoise(int x, int y, int z) { // Floating-point modulus operations are expensive. This allows implementations to optionally handle integers separately.
return getNoise((double) x, y, z);
}
default double computeNoise(Map<Generator, MutableInteger> gens, double x, double y, double z) {
double n = 0;
double div = 0;
for(Map.Entry<Generator, MutableInteger> entry : gens.entrySet()) {
Generator gen = entry.getKey();
int weight = entry.getValue().get();
double noise = computeNoise(gen, x, y, z);
n += noise * weight;
div += gen.getWeight() * weight;
}
return n / div;
}
double computeNoise(Generator generator, double x, double y, double z);
}