mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-20 15:20:25 +00:00
Completely redo config
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import org.bukkit.World;
|
||||
@@ -14,29 +15,22 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BiomeZone {
|
||||
private BiomeGrid[] grids;
|
||||
private final BiomeGrid[] grids;
|
||||
private final FastNoise noise;
|
||||
private static final Map<World, BiomeZone> zones = new HashMap<>();
|
||||
@Nullable
|
||||
private final ImageLoader imageLoader;
|
||||
private final boolean useImage;
|
||||
private final ImageLoader.Channel channel;
|
||||
|
||||
private BiomeZone(World w) {
|
||||
public BiomeZone(World w, WorldConfig wc, BiomeGrid[] grids) {
|
||||
this.noise = new FastNoise((int) w.getSeed()+2);
|
||||
this.noise.setNoiseType(FastNoise.NoiseType.SimplexFractal);
|
||||
this.noise.setFractalOctaves(4);
|
||||
this.noise.setFrequency(WorldConfig.fromWorld(w).zoneFreq);
|
||||
WorldConfig c = WorldConfig.fromWorld(w);
|
||||
setZones(c.definedGrids);
|
||||
imageLoader = c.imageLoader;
|
||||
useImage = c.fromImage;
|
||||
channel = c.zoneChannel;
|
||||
zones.put(w, this);
|
||||
}
|
||||
|
||||
public void setZones(@NotNull BiomeGrid[] grids) {
|
||||
this.noise.setFrequency(wc.getConfig().zoneFreq);
|
||||
this.grids = grids;
|
||||
imageLoader = wc.imageLoader;
|
||||
useImage = wc.fromImage;
|
||||
channel = wc.zoneChannel;
|
||||
}
|
||||
|
||||
protected BiomeGrid getGrid(int x, int z) {
|
||||
@@ -54,13 +48,4 @@ public class BiomeZone {
|
||||
public double getRawNoise(int x, int z) {
|
||||
return useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z);
|
||||
}
|
||||
|
||||
public static BiomeZone fromWorld(World w) {
|
||||
if(zones.containsKey(w)) return zones.get(w);
|
||||
else return new BiomeZone(w);
|
||||
}
|
||||
|
||||
public static void invalidate() {
|
||||
zones.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
@@ -16,36 +18,16 @@ 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) {
|
||||
public TerraBiomeGrid(World w, float freq1, float freq2, BiomeZone zone, TerraConfig c) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public static TerraBiomeGrid fromWorld(World w) {
|
||||
try {
|
||||
if(grids.containsKey(w)) return grids.get(w);
|
||||
else return new TerraBiomeGrid(w, WorldConfig.fromWorld(w).freq1, WorldConfig.fromWorld(w).freq2, false);
|
||||
} 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. Please check your configuration for errors. Any config errors will have been reported above.");
|
||||
failNum++;
|
||||
return new TerraBiomeGrid(w, 0.001f, 0.002f, true);
|
||||
}
|
||||
this.zone = zone;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,11 +55,7 @@ public class TerraBiomeGrid extends BiomeGrid {
|
||||
return getBiome(l.getBlockX(), l.getBlockZ(), phase);
|
||||
}
|
||||
|
||||
public static void invalidate() {
|
||||
grids.clear();
|
||||
}
|
||||
|
||||
public UserDefinedGrid getGrid(int x, int z) {
|
||||
return (UserDefinedGrid) BiomeZone.fromWorld(w).getGrid(x, z);
|
||||
return (UserDefinedGrid) zone.getGrid(x, z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,10 @@ public class UserDefinedGrid extends BiomeGrid {
|
||||
private final boolean fromImage;
|
||||
private final ImageLoader.Channel channelX;
|
||||
private final ImageLoader.Channel channelZ;
|
||||
public UserDefinedGrid(World w, float freq1, float freq2, UserDefinedBiome[][] b) {
|
||||
public UserDefinedGrid(World w, float freq1, float freq2, UserDefinedBiome[][] b, WorldConfig c) {
|
||||
super(w, freq1, freq2, b.length, b[0].length);
|
||||
super.setNormalType(NormalType.LOOKUP4096);
|
||||
super.setGrid(b);
|
||||
WorldConfig c = WorldConfig.fromWorld(w);
|
||||
imageLoader = c.imageLoader;
|
||||
fromImage = c.fromImage;
|
||||
channelX = c.biomeXChannel;
|
||||
|
||||
Reference in New Issue
Block a user