mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-23 00:29:51 +00:00
Add advanced biome blending
This commit is contained in:
21
src/main/java/com/dfsek/terra/biome/CoordinatePerturb.java
Normal file
21
src/main/java/com/dfsek/terra/biome/CoordinatePerturb.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import org.polydev.gaea.math.FastNoise;
|
||||
|
||||
public class CoordinatePerturb {
|
||||
private final FastNoise perturbX;
|
||||
private final FastNoise perturbZ;
|
||||
private final int amplitude;
|
||||
public CoordinatePerturb(float frequency, int amplitude, long seed) {
|
||||
perturbX = new FastNoise((int) seed);
|
||||
perturbX.setNoiseType(FastNoise.NoiseType.Simplex);
|
||||
perturbX.setFrequency(frequency);
|
||||
perturbZ = new FastNoise((int) seed+1);
|
||||
perturbZ.setNoiseType(FastNoise.NoiseType.Simplex);
|
||||
perturbZ.setFrequency(frequency);
|
||||
this.amplitude = amplitude;
|
||||
}
|
||||
public int[] getShiftedCoords(int x, int z) {
|
||||
return new int[] {(int) (perturbX.getNoise(x, z)*amplitude+x), (int) (perturbZ.getNoise(x, z)*amplitude+z)};
|
||||
}
|
||||
}
|
||||
@@ -7,21 +7,29 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TerraBiomeGrid extends BiomeGrid {
|
||||
private static int failNum = 0;
|
||||
private CoordinatePerturb perturb;
|
||||
|
||||
private static final Map<World, TerraBiomeGrid> grids = new HashMap<>();
|
||||
private final World w;
|
||||
private final BiomeZone zone;
|
||||
private final boolean perturbPaletteOnly;
|
||||
|
||||
|
||||
|
||||
private TerraBiomeGrid(World w, float freq1, float freq2, boolean blank) {
|
||||
super(w, freq1, freq2);
|
||||
WorldConfig c = WorldConfig.fromWorld(w);
|
||||
if(c.biomeBlend) {
|
||||
perturb = new CoordinatePerturb(c.blendFreq, c.blendAmp, w.getSeed());
|
||||
}
|
||||
perturbPaletteOnly = c.perturbPaletteOnly;
|
||||
this.w = w;
|
||||
this.zone = BiomeZone.fromWorld(w);
|
||||
if(!blank) grids.put(w, this);
|
||||
@@ -41,9 +49,17 @@ public class TerraBiomeGrid extends BiomeGrid {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z) {
|
||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||
int xp = x;
|
||||
int zp = z;
|
||||
if(perturb != null && (!perturbPaletteOnly || phase.equals(GenerationPhase.PALETTE_APPLY))) {
|
||||
int[] perturbCoords = perturb.getShiftedCoords(x, z);
|
||||
xp = perturbCoords[0];
|
||||
zp = perturbCoords[1];
|
||||
}
|
||||
|
||||
try {
|
||||
return zone.getGrid(x, z).getBiome(x, z);
|
||||
return zone.getGrid(xp, zp).getBiome(xp, zp, phase);
|
||||
} catch(NullPointerException e) {
|
||||
if(ConfigUtil.debug) e.printStackTrace();
|
||||
if(failNum % 256 == 0) Bukkit.getLogger().severe("[Terra] A severe configuration error has prevented Terra from properly generating terrain at coordinates: " + x + ", " + z + ". Please check your configuration for errors. Any config errors will have been reported above.");
|
||||
@@ -53,8 +69,8 @@ public class TerraBiomeGrid extends BiomeGrid {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l) {
|
||||
return getBiome(l.getBlockX(), l.getBlockZ());
|
||||
public Biome getBiome(Location l, GenerationPhase phase) {
|
||||
return getBiome(l.getBlockX(), l.getBlockZ(), phase);
|
||||
}
|
||||
|
||||
public static void invalidate() {
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
import org.polydev.gaea.biome.NormalizationUtil;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
import org.polydev.gaea.math.Interpolator;
|
||||
|
||||
public class UserDefinedGrid extends BiomeGrid {
|
||||
private final ImageLoader imageLoader;
|
||||
@@ -26,17 +28,17 @@ public class UserDefinedGrid extends BiomeGrid {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z) {
|
||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||
if(fromImage) {
|
||||
double xi = imageLoader.getNoiseVal(x, z, channelX);
|
||||
double zi = imageLoader.getNoiseVal(x, z, channelZ);
|
||||
return super.getGrid()[NormalizationUtil.normalize(xi, getSizeX())][NormalizationUtil.normalize(zi, getSizeZ())];
|
||||
}
|
||||
return super.getBiome(x, z);
|
||||
return super.getBiome(x, z, phase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l) {
|
||||
return this.getBiome(l.getBlockX(), l.getBlockZ());
|
||||
public Biome getBiome(Location l, GenerationPhase phase) {
|
||||
return this.getBiome(l.getBlockX(), l.getBlockZ(), phase);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user