mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 12:51:20 +00:00
implementation of BiomePipeline
This commit is contained in:
@@ -6,11 +6,9 @@ import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.math.noise.samplers.Normalizer;
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.palette.PaletteHolder;
|
||||
import com.dfsek.terra.biome.palette.PaletteLayer;
|
||||
import com.dfsek.terra.carving.CarverPalette;
|
||||
import com.dfsek.terra.config.loaders.ImageLoaderLoader;
|
||||
import com.dfsek.terra.config.loaders.MaterialSetLoader;
|
||||
import com.dfsek.terra.config.loaders.ProbabilityCollectionLoader;
|
||||
import com.dfsek.terra.config.loaders.RangeLoader;
|
||||
@@ -24,7 +22,6 @@ import com.dfsek.terra.config.loaders.palette.CarverPaletteLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.PaletteHolderLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.PaletteLayerLoader;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import com.dfsek.terra.population.items.flora.FloraLayer;
|
||||
import com.dfsek.terra.population.items.flora.TerraFlora;
|
||||
import com.dfsek.terra.population.items.ores.Ore;
|
||||
@@ -55,10 +52,6 @@ public class GenericLoaders implements LoaderRegistrar {
|
||||
.registerLoader(TreeLayer.class, new TreeLayerLoader())
|
||||
.registerLoader(MaterialSet.class, new MaterialSetLoader())
|
||||
.registerLoader(OreHolder.class, new OreHolderLoader())
|
||||
.registerLoader(ImageLoader.class, new ImageLoaderLoader())
|
||||
.registerLoader(TerraBiomeGrid.Type.class, (t, o, l) -> TerraBiomeGrid.Type.valueOf(o.toString()))
|
||||
.registerLoader(ImageLoader.Channel.class, (t, o, l) -> ImageLoader.Channel.valueOf(o.toString()))
|
||||
.registerLoader(ImageLoader.Align.class, (t, o, l) -> ImageLoader.Align.valueOf(o.toString()))
|
||||
.registerLoader(TerraFlora.Search.class, (t, o, l) -> TerraFlora.Search.valueOf(o.toString()))
|
||||
.registerLoader(Normalizer.NormalType.class, (t, o, l) -> Normalizer.NormalType.valueOf(o.toString().toUpperCase()));
|
||||
}
|
||||
|
||||
@@ -178,6 +178,14 @@ public class Vector2 implements Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getBlockX() {
|
||||
return FastMath.floorToInt(x);
|
||||
}
|
||||
|
||||
public int getBlockZ() {
|
||||
return FastMath.floorToInt(z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + z + ")";
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ import com.dfsek.terra.api.structures.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.api.structures.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.api.structures.structure.RotationUtil;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import com.dfsek.terra.biome.BiomeProvider;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
public class BiomeFunction implements Function<String> {
|
||||
@@ -36,7 +36,7 @@ public class BiomeFunction implements Function<String> {
|
||||
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
TerraBiomeGrid grid = main.getWorld(arguments.getBuffer().getOrigin().getWorld()).getGrid();
|
||||
BiomeProvider grid = main.getWorld(arguments.getBuffer().getOrigin().getWorld()).getBiomeProvider();
|
||||
|
||||
return ((UserDefinedBiome) grid.getBiome(arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).intValue(), FastMath.roundToInt(xz.getZ()))))).getID();
|
||||
}
|
||||
|
||||
+3
-4
@@ -12,9 +12,8 @@ import com.dfsek.terra.api.structures.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.api.structures.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.api.structures.structure.RotationUtil;
|
||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||
import com.dfsek.terra.biome.BiomeProvider;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.generation.math.SamplerCache;
|
||||
import net.jafama.FastMath;
|
||||
@@ -54,8 +53,8 @@ public class CheckFunction implements Function<String> {
|
||||
|
||||
if(comp > 0) return "LAND"; // If noise val is greater than zero, location will always be land.
|
||||
|
||||
TerraBiomeGrid grid = tw.getGrid();
|
||||
UserDefinedBiome b = (UserDefinedBiome) grid.getBiome(vector.getBlockX(), vector.getBlockZ(), GenerationPhase.POPULATE);
|
||||
BiomeProvider provider = tw.getBiomeProvider();
|
||||
UserDefinedBiome b = (UserDefinedBiome) provider.getBiome(vector.getBlockX(), vector.getBlockZ());
|
||||
BiomeTemplate c = b.getConfig();
|
||||
|
||||
if(vector.getY() > c.getSeaLevel()) return "AIR"; // Above sea level
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
package com.dfsek.terra.api.world.biome;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||
|
||||
public abstract class BiomeGrid {
|
||||
private final FastNoiseLite noiseX;
|
||||
private final FastNoiseLite noiseZ;
|
||||
private final int sizeX;
|
||||
private final int sizeZ;
|
||||
private TerraBiome[][] grid;
|
||||
|
||||
|
||||
public BiomeGrid(long seed, double freq1, double freq2, int sizeX, int sizeZ) {
|
||||
this.sizeX = sizeX;
|
||||
this.sizeZ = sizeZ;
|
||||
this.noiseX = new FastNoiseLite((int) seed);
|
||||
this.noiseZ = new FastNoiseLite((int) seed + 1);
|
||||
this.noiseX.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
this.noiseX.setFractalType(FastNoiseLite.FractalType.FBm);
|
||||
this.noiseX.setFractalOctaves(4);
|
||||
this.noiseZ.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
this.noiseZ.setFractalType(FastNoiseLite.FractalType.FBm);
|
||||
this.noiseZ.setFractalOctaves(4);
|
||||
this.noiseX.setFrequency(freq1);
|
||||
this.noiseZ.setFrequency(freq2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the biome at a pair of coordinates.
|
||||
*
|
||||
* @param x - X-coordinate at which to fetch biome
|
||||
* @param z - Z-coordinate at which to fetch biome
|
||||
* @return TerraBiome - TerraBiome at the given coordinates.
|
||||
*/
|
||||
public TerraBiome getBiome(int x, int z, GenerationPhase phase) {
|
||||
return grid[getBiomeNoiseX(x, z)][getBiomeNoiseZ(x, z)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the biome at a location.
|
||||
*
|
||||
* @param l - The location at which to fetch the biome.
|
||||
* @return TerraBiome - TerraBiome at the given coordinates.
|
||||
*/
|
||||
public TerraBiome getBiome(Location l) {
|
||||
return getBiome(l, GenerationPhase.POST_GEN);
|
||||
}
|
||||
|
||||
public double[] getRawNoise(int x, int z) {
|
||||
return new double[] {noiseX.getNoise(x, z), noiseZ.getNoise(x, z)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw X-noise for coordinates in the Grid.
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return Normalized noise
|
||||
*/
|
||||
public int getBiomeNoiseX(int x, int z) {
|
||||
return normalize(noiseX.getNoise(x, z), sizeX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw Z-noise for coordinates in the Grid.
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return Normalized noise
|
||||
*/
|
||||
public int getBiomeNoiseZ(int x, int z) {
|
||||
return normalize(noiseZ.getNoise(x, z), sizeZ);
|
||||
}
|
||||
|
||||
public TerraBiome[][] getGrid() {
|
||||
return grid;
|
||||
}
|
||||
|
||||
public void setGrid(TerraBiome[][] grid) {
|
||||
if(grid.length != sizeX) throw new IllegalArgumentException("Invalid length for grid, expected " + sizeX + ", got " + grid.length);
|
||||
for(TerraBiome[] gridLayer : grid) {
|
||||
if(gridLayer.length != sizeZ)
|
||||
throw new IllegalArgumentException("Invalid length for grid layer, expected " + sizeZ + ", got " + gridLayer.length);
|
||||
}
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
public TerraBiome getBiome(Location l, GenerationPhase phase) {
|
||||
double biomeNoise = noiseX.getNoise(l.getBlockX(), l.getBlockZ());
|
||||
double climateNoise = noiseZ.getNoise(l.getBlockX(), l.getBlockZ());
|
||||
return grid[normalize(biomeNoise, sizeX)][normalize(climateNoise, sizeZ)];
|
||||
}
|
||||
|
||||
public int getSizeX() {
|
||||
return sizeX;
|
||||
}
|
||||
|
||||
public int getSizeZ() {
|
||||
return sizeZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a noise input and normalizes it to a value between 0 and 15 inclusive.
|
||||
*
|
||||
* @param i - The noise value to normalize.
|
||||
* @return int - The normalized value.
|
||||
*/
|
||||
protected int normalize(double i, int range) {
|
||||
return NormalizationUtil.normalize(i, range, 4);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user