mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Fix bizarre elevation equation issues
This commit is contained in:
parent
0bc2c6e897
commit
700d1d0a6c
@ -1,32 +0,0 @@
|
|||||||
package com.dfsek.terra.generation;
|
|
||||||
|
|
||||||
import parsii.eval.Expression;
|
|
||||||
import parsii.eval.Parser;
|
|
||||||
import parsii.eval.Scope;
|
|
||||||
import parsii.eval.Variable;
|
|
||||||
import parsii.tokenizer.ParseException;
|
|
||||||
|
|
||||||
public class ElevationEquation {
|
|
||||||
private final Expression delegate;
|
|
||||||
|
|
||||||
private final Variable xVar;
|
|
||||||
private final Variable zVar;
|
|
||||||
|
|
||||||
public ElevationEquation(String elevateEquation, Scope vScope, Parser p) {
|
|
||||||
Scope s = new Scope().withParent(vScope);
|
|
||||||
xVar = s.create("x");
|
|
||||||
zVar = s.create("z");
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.delegate = p.parse(elevateEquation, s);
|
|
||||||
} catch(ParseException e) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized double getNoise(double x, double z) {
|
|
||||||
xVar.setValue(x);
|
|
||||||
zVar.setValue(z);
|
|
||||||
return delegate.evaluate();
|
|
||||||
}
|
|
||||||
}
|
|
@ -70,8 +70,7 @@ public class ElevationInterpolator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private double elevate(WorldGenerator g, int x, int z) {
|
private double elevate(WorldGenerator g, int x, int z) {
|
||||||
if(g.getElevationEquation() != null) return g.getElevationEquation().getNoise(x, z);
|
return g.getElevation(x, z);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getElevation(int x, int z) {
|
public double getElevation(int x, int z) {
|
||||||
|
@ -147,7 +147,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
|||||||
ChunkData chunk = createChunkData(world);
|
ChunkData chunk = createChunkData(world);
|
||||||
TerraWorld tw = TerraWorld.getWorld(world);
|
TerraWorld tw = TerraWorld.getWorld(world);
|
||||||
if(!tw.isSafe()) return chunk;
|
if(!tw.isSafe()) return chunk;
|
||||||
ConfigPack config = tw.getConfig();
|
|
||||||
int xOrig = (chunkX << 4);
|
int xOrig = (chunkX << 4);
|
||||||
int zOrig = (chunkZ << 4);
|
int zOrig = (chunkZ << 4);
|
||||||
org.polydev.gaea.biome.BiomeGrid grid = getBiomeGrid(world);
|
org.polydev.gaea.biome.BiomeGrid grid = getBiomeGrid(world);
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package com.dfsek.terra.generation.config;
|
package com.dfsek.terra.generation.config;
|
||||||
|
|
||||||
import com.dfsek.terra.Debug;
|
|
||||||
import com.dfsek.terra.config.genconfig.noise.NoiseConfig;
|
import com.dfsek.terra.config.genconfig.noise.NoiseConfig;
|
||||||
import com.dfsek.terra.generation.ElevationEquation;
|
|
||||||
import com.dfsek.terra.math.NoiseFunction2;
|
import com.dfsek.terra.math.NoiseFunction2;
|
||||||
import com.dfsek.terra.math.NoiseFunction3;
|
import com.dfsek.terra.math.NoiseFunction3;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -20,8 +18,6 @@ import parsii.tokenizer.ParseException;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class WorldGenerator extends Generator {
|
public class WorldGenerator extends Generator {
|
||||||
private final ElevationEquation elevationEquation;
|
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||||
private final Palette<BlockData>[] palettes;
|
private final Palette<BlockData>[] palettes;
|
||||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||||
@ -29,14 +25,18 @@ public class WorldGenerator extends Generator {
|
|||||||
|
|
||||||
private final boolean preventSmooth;
|
private final boolean preventSmooth;
|
||||||
private final Expression noiseExp;
|
private final Expression noiseExp;
|
||||||
|
private final Expression elevationExp;
|
||||||
private final Variable xVar;
|
private final Variable xVar;
|
||||||
private final Variable yVar;
|
private final Variable yVar;
|
||||||
private final Variable zVar;
|
private final Variable zVar;
|
||||||
|
private final Variable elevationXVar;
|
||||||
|
private final Variable elevationZVar;
|
||||||
private boolean elevationInterpolation = true;
|
private boolean elevationInterpolation = true;
|
||||||
|
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public WorldGenerator(long seed, String equation, String elevateEquation, Scope vScope, Map<String, NoiseConfig> noiseBuilders, Palette[] palettes, Palette[] slantPalettes, boolean preventSmooth) {
|
public WorldGenerator(long seed, String equation, String elevateEquation, Scope vScope, Map<String, NoiseConfig> noiseBuilders, Palette[] palettes, Palette[] slantPalettes, boolean preventSmooth) {
|
||||||
Parser p = new Parser();
|
Parser p = new Parser();
|
||||||
|
Parser ep = new Parser();
|
||||||
|
|
||||||
Scope s = new Scope().withParent(vScope);
|
Scope s = new Scope().withParent(vScope);
|
||||||
xVar = s.create("x");
|
xVar = s.create("x");
|
||||||
@ -51,28 +51,36 @@ public class WorldGenerator extends Generator {
|
|||||||
for(Map.Entry<String, NoiseConfig> e : noiseBuilders.entrySet()) {
|
for(Map.Entry<String, NoiseConfig> e : noiseBuilders.entrySet()) {
|
||||||
switch(e.getValue().getDimensions()) {
|
switch(e.getValue().getDimensions()) {
|
||||||
case 2:
|
case 2:
|
||||||
NoiseFunction2 function2 = new NoiseFunction2(seed, e.getValue().getBuilder());
|
p.registerFunction(e.getKey(), new NoiseFunction2(seed, e.getValue().getBuilder()));
|
||||||
p.registerFunction(e.getKey(), function2);
|
ep.registerFunction(e.getKey(), new NoiseFunction2(seed, e.getValue().getBuilder()));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
NoiseFunction3 function3 = new NoiseFunction3(seed, e.getValue().getBuilder());
|
p.registerFunction(e.getKey(), new NoiseFunction3(seed, e.getValue().getBuilder()));
|
||||||
p.registerFunction(e.getKey(), function3);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.noiseExp = p.parse(equation, s);
|
this.noiseExp = p.parse(equation, s).simplify();
|
||||||
if(elevateEquation != null) {
|
if(elevateEquation != null) {
|
||||||
Debug.info("Using elevation equation");
|
Scope es = new Scope().withParent(vScope);
|
||||||
this.elevationEquation = new ElevationEquation(elevateEquation, vScope, p);
|
this.elevationXVar = es.create("x");
|
||||||
} else this.elevationEquation = null;
|
this.elevationZVar = es.create("z");
|
||||||
|
this.elevationExp = ep.parse(elevateEquation, es).simplify();
|
||||||
|
} else {
|
||||||
|
this.elevationExp = null;
|
||||||
|
this.elevationXVar = null;
|
||||||
|
this.elevationZVar = null;
|
||||||
|
}
|
||||||
} catch(ParseException e) {
|
} catch(ParseException e) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElevationEquation getElevationEquation() {
|
public synchronized double getElevation(int x, int z) {
|
||||||
return elevationEquation;
|
if(elevationExp == null) return 0;
|
||||||
|
elevationXVar.setValue(x);
|
||||||
|
elevationZVar.setValue(z);
|
||||||
|
return elevationExp.evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,7 +4,6 @@ import com.dfsek.terra.TerraWorld;
|
|||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
||||||
import com.dfsek.terra.generation.ElevationEquation;
|
|
||||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.polydev.gaea.generation.GenerationPhase;
|
import org.polydev.gaea.generation.GenerationPhase;
|
||||||
@ -21,8 +20,7 @@ public class AirSpawn extends Requirement {
|
|||||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||||
BiomeConfig c = wc.getBiome(b);
|
BiomeConfig c = wc.getBiome(b);
|
||||||
if(y <= c.getOcean().getSeaLevel()) return false;
|
if(y <= c.getOcean().getSeaLevel()) return false;
|
||||||
ElevationEquation elevationEquation = ((WorldGenerator) b.getGenerator()).getElevationEquation();
|
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
|
||||||
int yf = y - ((elevationEquation == null) ? 0 : (int) elevationEquation.getNoise(x, z));
|
|
||||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;
|
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.dfsek.terra.structure.spawn;
|
|||||||
|
|
||||||
import com.dfsek.terra.TerraWorld;
|
import com.dfsek.terra.TerraWorld;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.generation.ElevationEquation;
|
|
||||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.polydev.gaea.generation.GenerationPhase;
|
import org.polydev.gaea.generation.GenerationPhase;
|
||||||
@ -16,8 +15,7 @@ public class LandSpawn extends Requirement {
|
|||||||
public boolean matches(int x, int y, int z) {
|
public boolean matches(int x, int y, int z) {
|
||||||
TerraWorld tw = TerraWorld.getWorld(getWorld());
|
TerraWorld tw = TerraWorld.getWorld(getWorld());
|
||||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||||
ElevationEquation elevationEquation = ((WorldGenerator) b.getGenerator()).getElevationEquation();
|
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
|
||||||
int yf = y - ((elevationEquation == null) ? 0 : (int) elevationEquation.getNoise(x, z));
|
|
||||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) > 0;
|
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package com.dfsek.terra.structure.spawn;
|
|||||||
import com.dfsek.terra.TerraWorld;
|
import com.dfsek.terra.TerraWorld;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
||||||
import com.dfsek.terra.generation.ElevationEquation;
|
|
||||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.polydev.gaea.generation.GenerationPhase;
|
import org.polydev.gaea.generation.GenerationPhase;
|
||||||
@ -19,8 +18,7 @@ public class OceanSpawn extends Requirement {
|
|||||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||||
BiomeConfig c = tw.getConfig().getBiome(b);
|
BiomeConfig c = tw.getConfig().getBiome(b);
|
||||||
if(y > c.getOcean().getSeaLevel()) return false;
|
if(y > c.getOcean().getSeaLevel()) return false;
|
||||||
ElevationEquation elevationEquation = ((WorldGenerator) b.getGenerator()).getElevationEquation();
|
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
|
||||||
int yf = y - ((elevationEquation == null) ? 0 : (int) elevationEquation.getNoise(x, z));
|
|
||||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;
|
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user