mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 23:47:50 +00:00
begin work on terrain samplers
This commit is contained in:
parent
798f3423a5
commit
54e6fb0587
@ -2,6 +2,9 @@ package com.dfsek.terra.api.world.biome;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
import com.dfsek.terra.world.generation.math.samplers.terrain.TerrainSampler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Generator {
|
||||
/**
|
||||
@ -41,4 +44,6 @@ public interface Generator {
|
||||
double getElevationWeight();
|
||||
|
||||
int getBlendStep();
|
||||
|
||||
List<TerrainSampler> getTerrainSamplers();
|
||||
}
|
||||
|
@ -4,6 +4,10 @@ import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.world.biome.Generator;
|
||||
import com.dfsek.terra.api.world.palette.Palette;
|
||||
import com.dfsek.terra.api.world.palette.holder.PaletteHolder;
|
||||
import com.dfsek.terra.world.generation.math.samplers.terrain.TerrainSampler;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class WorldGenerator implements Generator {
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
@ -85,6 +89,11 @@ public class WorldGenerator implements Generator {
|
||||
return blendStep;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TerrainSampler> getTerrainSamplers() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public Palette getSlantPalette(int y) {
|
||||
return slantPalettes.getPalette(y);
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.world.generation.math.samplers.terrain;
|
||||
|
||||
import com.dfsek.paralithic.Expression;
|
||||
import com.dfsek.terra.world.generation.math.interpolation.Interpolator3;
|
||||
|
||||
public class ExpressionSampler implements TerrainSampler {
|
||||
private final Expression expression;
|
||||
|
||||
public ExpressionSampler(Expression expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interpolator3 sample(double x, double y, double z) {
|
||||
return (i, i1, i2) -> expression.evaluate(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXResolution() {
|
||||
return 1;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.dfsek.terra.world.generation.math.samplers.terrain;
|
||||
|
||||
import com.dfsek.terra.world.generation.math.interpolation.Interpolator3;
|
||||
|
||||
public class InterpolatedSampler implements TerrainSampler {
|
||||
private final InterpolatorSupplier supplier;
|
||||
|
||||
public InterpolatedSampler(InterpolatorSupplier supplier) {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interpolator3 sample(double x, double y, double z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXResolution() {
|
||||
return supplier.getXResolution();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getYResolution() {
|
||||
return supplier.getYResolution();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZResolution() {
|
||||
return supplier.getZResolution();
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.dfsek.terra.world.generation.math.samplers.terrain;
|
||||
|
||||
import com.dfsek.terra.world.generation.math.interpolation.Interpolator2;
|
||||
import com.dfsek.terra.world.generation.math.interpolation.Interpolator3;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface InterpolatorSupplier {
|
||||
int getXResolution();
|
||||
int getYResolution();
|
||||
int getZResolution();
|
||||
|
||||
Interpolator2 get(double t, double v0, double v1);
|
||||
|
||||
Interpolator3 get(double _000, double _100,
|
||||
double _010, double _110,
|
||||
double _001, double _101,
|
||||
double _011, double _111);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.world.generation.math.samplers.terrain;
|
||||
|
||||
import com.dfsek.terra.world.generation.math.interpolation.Interpolator2;
|
||||
import com.dfsek.terra.world.generation.math.interpolation.Interpolator3;
|
||||
|
||||
public interface TerrainSampler {
|
||||
Interpolator3 sample(double x, double y, double z);
|
||||
|
||||
default Interpolator2 sample(double x, double z) {
|
||||
return (s, t) -> sample(x, 0, z).interpolate(s, 0, t);
|
||||
}
|
||||
|
||||
int getXResolution();
|
||||
|
||||
default int getYResolution() {
|
||||
return getXResolution();
|
||||
}
|
||||
|
||||
default int getZResolution() {
|
||||
return getXResolution();
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.world.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricSeededWorldAccess;
|
||||
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
|
||||
import com.dfsek.terra.world.generation.math.samplers.Sampler;
|
||||
import com.dfsek.terra.world.population.CavePopulator;
|
||||
import com.dfsek.terra.world.population.FloraPopulator;
|
||||
import com.dfsek.terra.world.population.OrePopulator;
|
||||
@ -15,6 +16,7 @@ import com.dfsek.terra.world.population.StructurePopulator;
|
||||
import com.dfsek.terra.world.population.TreePopulator;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.jafama.FastMath;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
@ -45,6 +47,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
PACK_CODEC.fieldOf("pack").stable().forGetter(generator -> generator.pack))
|
||||
.apply(instance, instance.stable(FabricChunkGeneratorWrapper::new)));
|
||||
private final ConfigPack pack;
|
||||
private FabricSeededWorldAccess worldAccess;
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
@ -84,7 +87,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
|
||||
@Override
|
||||
public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk chunk) {
|
||||
FabricSeededWorldAccess worldAccess = new FabricSeededWorldAccess(world, seed, this);
|
||||
this.worldAccess = new FabricSeededWorldAccess(world, seed, this);
|
||||
delegate.generateChunkData(worldAccess, new FastRandom(), chunk.getPos().x, chunk.getPos().z, new FabricChunkData(chunk));
|
||||
}
|
||||
|
||||
@ -107,7 +110,15 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
|
||||
@Override
|
||||
public int getHeight(int x, int z, Heightmap.Type heightmapType) {
|
||||
return 0;
|
||||
Sampler sampler = TerraFabricPlugin.getInstance().getWorld(worldAccess).getConfig().getSamplerCache().getChunk(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16));
|
||||
int cx = FastMath.floorMod(x, 16);
|
||||
int cz = FastMath.floorMod(z, 16);
|
||||
|
||||
int height = worldAccess.getMaxHeight();
|
||||
|
||||
while(height >= 0 && sampler.sample(cx, height, cz) < 0) height--;
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user