Completely redo config

This commit is contained in:
dfsek 2020-10-01 16:31:48 -07:00
parent a5c85a7e5d
commit 6f11222a88
36 changed files with 560 additions and 451 deletions

View File

@ -0,0 +1,73 @@
package com.dfsek.terra;
import com.dfsek.terra.biome.BiomeZone;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.UserDefinedGrid;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.BiomeGridConfig;
import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.util.HashMap;
import java.util.Map;
public class TerraWorld {
private static Map<World, TerraWorld> map = new HashMap<>();
private final TerraBiomeGrid grid;
private BiomeZone zone;
private final TerraConfig config;
private final WorldConfig worldConfig;
private static final Object lock = new Object();
public TerraWorld(World w) {
worldConfig = new WorldConfig(w, Terra.getInstance());
config = worldConfig.getConfig();
UserDefinedGrid[] definedGrids = new UserDefinedGrid[config.biomeList.size()];
for(int i = 0; i < config.biomeList.size(); i++) {
String partName = config.biomeList.get(i);
try {
if(partName.startsWith("BIOME:")) {
UserDefinedBiome[][] temp = new UserDefinedBiome[1][1];
UserDefinedBiome b = config.getBiomes().get(partName.substring(6)).getBiome();
temp[0][0] = b;
definedGrids[i] = new UserDefinedGrid(w, config.freq1, config.freq2, temp, worldConfig);
Terra.getInstance().getLogger().info("Loaded single-biome grid " + partName);
} else {
BiomeGridConfig g = config.getBiomeGrid(partName);
Bukkit.getLogger().info(g.getID());
definedGrids[i] = g.getGrid(w, worldConfig);
}
} catch(NullPointerException e) {
if(ConfigUtil.debug) e.printStackTrace();
Bukkit.getLogger().severe("No such BiomeGrid " + partName);
}
}
zone = new BiomeZone(w, worldConfig, definedGrids);
grid = new TerraBiomeGrid(w, config.freq1, config.freq2, zone, config);
}
public static TerraWorld getWorld(World w) {
synchronized(lock) {
return map.computeIfAbsent(w, TerraWorld::new);
}
}
public TerraBiomeGrid getGrid() {
return grid;
}
public TerraConfig getConfig() {
return config;
}
public WorldConfig getWorldConfig() {
return worldConfig;
}
public BiomeZone getZone() {
return zone;
}
}

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.biome; package com.dfsek.terra.biome;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.WorldConfig; import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.image.ImageLoader; import com.dfsek.terra.image.ImageLoader;
import org.bukkit.World; import org.bukkit.World;
@ -14,29 +15,22 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
public class BiomeZone { public class BiomeZone {
private BiomeGrid[] grids; private final BiomeGrid[] grids;
private final FastNoise noise; private final FastNoise noise;
private static final Map<World, BiomeZone> zones = new HashMap<>();
@Nullable @Nullable
private final ImageLoader imageLoader; private final ImageLoader imageLoader;
private final boolean useImage; private final boolean useImage;
private final ImageLoader.Channel channel; 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 = new FastNoise((int) w.getSeed()+2);
this.noise.setNoiseType(FastNoise.NoiseType.SimplexFractal); this.noise.setNoiseType(FastNoise.NoiseType.SimplexFractal);
this.noise.setFractalOctaves(4); this.noise.setFractalOctaves(4);
this.noise.setFrequency(WorldConfig.fromWorld(w).zoneFreq); this.noise.setFrequency(wc.getConfig().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.grids = grids; this.grids = grids;
imageLoader = wc.imageLoader;
useImage = wc.fromImage;
channel = wc.zoneChannel;
} }
protected BiomeGrid getGrid(int x, int z) { protected BiomeGrid getGrid(int x, int z) {
@ -54,13 +48,4 @@ public class BiomeZone {
public double getRawNoise(int x, int z) { public double getRawNoise(int x, int z) {
return useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, 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();
}
} }

View File

@ -1,10 +1,12 @@
package com.dfsek.terra.biome; package com.dfsek.terra.biome;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.WorldConfig; import com.dfsek.terra.config.base.WorldConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.polydev.gaea.biome.Biome; import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.biome.BiomeGrid; import org.polydev.gaea.biome.BiomeGrid;
import org.polydev.gaea.generation.GenerationPhase; import org.polydev.gaea.generation.GenerationPhase;
@ -16,36 +18,16 @@ public class TerraBiomeGrid extends BiomeGrid {
private static int failNum = 0; private static int failNum = 0;
private CoordinatePerturb perturb; private CoordinatePerturb perturb;
private static final Map<World, TerraBiomeGrid> grids = new HashMap<>();
private final World w;
private final BiomeZone zone; private final BiomeZone zone;
private final boolean perturbPaletteOnly; private final boolean perturbPaletteOnly;
public TerraBiomeGrid(World w, float freq1, float freq2, BiomeZone zone, TerraConfig c) {
private TerraBiomeGrid(World w, float freq1, float freq2, boolean blank) {
super(w, freq1, freq2); super(w, freq1, freq2);
WorldConfig c = WorldConfig.fromWorld(w);
if(c.biomeBlend) { if(c.biomeBlend) {
perturb = new CoordinatePerturb(c.blendFreq, c.blendAmp, w.getSeed()); perturb = new CoordinatePerturb(c.blendFreq, c.blendAmp, w.getSeed());
} }
perturbPaletteOnly = c.perturbPaletteOnly; perturbPaletteOnly = c.perturbPaletteOnly;
this.w = w; this.zone = zone;
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);
}
} }
@Override @Override
@ -73,11 +55,7 @@ public class TerraBiomeGrid extends BiomeGrid {
return getBiome(l.getBlockX(), l.getBlockZ(), phase); return getBiome(l.getBlockX(), l.getBlockZ(), phase);
} }
public static void invalidate() {
grids.clear();
}
public UserDefinedGrid getGrid(int x, int z) { public UserDefinedGrid getGrid(int x, int z) {
return (UserDefinedGrid) BiomeZone.fromWorld(w).getGrid(x, z); return (UserDefinedGrid) zone.getGrid(x, z);
} }
} }

View File

@ -14,11 +14,10 @@ public class UserDefinedGrid extends BiomeGrid {
private final boolean fromImage; private final boolean fromImage;
private final ImageLoader.Channel channelX; private final ImageLoader.Channel channelX;
private final ImageLoader.Channel channelZ; 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(w, freq1, freq2, b.length, b[0].length);
super.setNormalType(NormalType.LOOKUP4096); super.setNormalType(NormalType.LOOKUP4096);
super.setGrid(b); super.setGrid(b);
WorldConfig c = WorldConfig.fromWorld(w);
imageLoader = c.imageLoader; imageLoader = c.imageLoader;
fromImage = c.fromImage; fromImage = c.fromImage;
channelX = c.biomeXChannel; channelX = c.biomeXChannel;

View File

@ -1,5 +1,8 @@
package com.dfsek.terra.carving; package com.dfsek.terra.carving;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.WorldConfig;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
@ -44,7 +47,8 @@ public class UserDefinedCarver extends Carver {
@Override @Override
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) { public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
return new Random(random.nextLong()+hash).nextInt(100) < BiomeConfig.fromBiome((UserDefinedBiome) TerraBiomeGrid.fromWorld(w).getBiome(chunkX << 4, chunkZ << 4, GenerationPhase.POPULATE)).getCarverChance(this); TerraConfig c = TerraWorld.getWorld(w).getConfig();
return new Random(random.nextLong()+hash).nextInt(100) < c.getBiome((UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(chunkX << 4, chunkZ << 4, GenerationPhase.POPULATE)).getCarverChance(this);
} }
private class UserDefinedWorm extends Worm { private class UserDefinedWorm extends Worm {

View File

@ -1,9 +1,11 @@
package com.dfsek.terra.command; package com.dfsek.terra.command;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.command.type.PlayerCommand; import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.base.WorldConfig;
import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -12,16 +14,12 @@ import org.polydev.gaea.generation.GenerationPhase;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class BiomeCommand extends PlayerCommand { public class BiomeCommand extends WorldCommand {
@Override @Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
TerraBiomeGrid grid = TerraBiomeGrid.fromWorld(sender.getWorld()); TerraBiomeGrid grid = TerraWorld.getWorld(sender.getWorld()).getGrid();
if(grid == null) {
sender.sendMessage("Not a Terra world!");
return true;
}
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(sender.getLocation(), GenerationPhase.POPULATE); UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(sender.getLocation(), GenerationPhase.POPULATE);
sender.sendMessage("You are in " + BiomeConfig.fromBiome(biome).getID()); sender.sendMessage("You are in " + TerraWorld.getWorld(w).getConfig().getBiome(biome).getID());
return true; return true;
} }

View File

@ -1,7 +1,11 @@
package com.dfsek.terra.command; package com.dfsek.terra.command;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.command.type.PlayerCommand; import com.dfsek.terra.command.type.PlayerCommand;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.OreConfig; import com.dfsek.terra.config.genconfig.OreConfig;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,12 +15,12 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class OreCommand extends PlayerCommand { public class OreCommand extends WorldCommand {
@Override @Override
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
Block bl = sender.getTargetBlockExact(25); Block bl = sender.getTargetBlockExact(25);
if(args.length > 0) { if(args.length > 0) {
OreConfig ore = OreConfig.fromID(args[0]); OreConfig ore = TerraWorld.getWorld(w).getConfig().getOre(args[0]);
if(ore == null) { if(ore == null) {
sender.sendMessage("Unable to find Ore"); sender.sendMessage("Unable to find Ore");
return true; return true;

View File

@ -45,8 +45,8 @@ public class TerraCommand implements CommandExecutor, TabExecutor {
} }
@Override @Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(args[0].equals("tpbiome")) return BiomeConfig.getBiomeIDs(); /*if(args[0].equals("tpbiome")) return BiomeConfig.getBiomeIDs();
else if(args[0].equals("ore")) return OreConfig.getOreIDs(); else if(args[0].equals("ore")) return OreConfig.getOreIDs();
else return Collections.emptyList(); else*/ return Collections.emptyList();
} }
} }

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.command.image.gui; package com.dfsek.terra.command.image.gui;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.command.type.WorldCommand; import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.WorldConfig; import com.dfsek.terra.config.base.WorldConfig;
@ -19,7 +20,7 @@ public class RawGUICommand extends WorldCommand {
sender.sendMessage("Debug mode must be enabled to use the debug GUI! The debug GUI is NOT PRODUCTION SAFE!"); sender.sendMessage("Debug mode must be enabled to use the debug GUI! The debug GUI is NOT PRODUCTION SAFE!");
return true; return true;
} }
ImageLoader loader = WorldConfig.fromWorld(world).imageLoader; ImageLoader loader = TerraWorld.getWorld(world).getWorldConfig().imageLoader;
if(loader != null) loader.debug(false, sender.getWorld()); if(loader != null) loader.debug(false, sender.getWorld());
else ImageLoader.debugWorld(false, world); else ImageLoader.debugWorld(false, world);
return true; return true;

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.command.image.gui; package com.dfsek.terra.command.image.gui;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.command.type.WorldCommand; import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.WorldConfig; import com.dfsek.terra.config.base.WorldConfig;
@ -19,7 +20,7 @@ public class StepGUICommand extends WorldCommand {
sender.sendMessage("Debug mode must be enabled to use the debug GUI! The debug GUI is NOT PRODUCTION SAFE!"); sender.sendMessage("Debug mode must be enabled to use the debug GUI! The debug GUI is NOT PRODUCTION SAFE!");
return true; return true;
} }
ImageLoader loader = WorldConfig.fromWorld(world).imageLoader; ImageLoader loader = TerraWorld.getWorld(world).getWorldConfig().imageLoader;
if(loader != null) loader.debug(true, sender.getWorld()); if(loader != null) loader.debug(true, sender.getWorld());
else ImageLoader.debugWorld(true, world); else ImageLoader.debugWorld(true, world);
return true; return true;

View File

@ -12,28 +12,26 @@ import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Stream; import java.util.stream.Stream;
public class ConfigLoader { public class ConfigLoader {
private final String path; public static <T extends TerraConfigObject> Map<String, T> load(JavaPlugin main, Path file, TerraConfig config, Class<T> clazz) {
public ConfigLoader(String path) { Map<String, T> configs = new HashMap<>();
this.path = path; file.toFile().mkdirs();
}
public <T extends TerraConfigObject> void load(JavaPlugin main, Class<T> clazz) {
File folder = new File(main.getDataFolder() + File.separator + "config" + File.separator + path);
folder.mkdirs();
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
try (Stream<Path> paths = Files.walk(folder.toPath())) { try (Stream<Path> paths = Files.walk(file)) {
paths paths
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml")) .filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
.forEach(path -> { .forEach(path -> {
try { try {
Constructor<T> c = clazz.getConstructor(File.class); Constructor<T> c = clazz.getConstructor(File.class, TerraConfig.class);
T o = c.newInstance(path.toFile()); T o = c.newInstance(path.toFile(), config);
if(ids.contains(o.getID())) Bukkit.getLogger().severe("Duplicate ID found in file: " + path.toString()); if(ids.contains(o.getID())) Bukkit.getLogger().severe("Duplicate ID found in file: " + path.toString());
ids.add(o.getID()); ids.add(o.getID());
configs.put(o.getID(), o);
main.getLogger().info("Loaded " + o.toString() + " from file " + path.toString()); main.getLogger().info("Loaded " + o.toString() + " from file " + path.toString());
} catch(IllegalAccessException | InstantiationException | NoSuchMethodException e) { } catch(IllegalAccessException | InstantiationException | NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
@ -47,5 +45,6 @@ public class ConfigLoader {
} catch(IOException e) { } catch(IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return configs;
} }
} }

View File

@ -0,0 +1,228 @@
package com.dfsek.terra.config;
import com.dfsek.terra.biome.BiomeZone;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.UserDefinedGrid;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.command.TerraCommand;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.genconfig.AbstractBiomeConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.config.genconfig.BiomeGridConfig;
import com.dfsek.terra.config.genconfig.CarverConfig;
import com.dfsek.terra.config.genconfig.FloraConfig;
import com.dfsek.terra.config.genconfig.OreConfig;
import com.dfsek.terra.config.genconfig.PaletteConfig;
import com.dfsek.terra.config.genconfig.StructureConfig;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class TerraConfig extends YamlConfiguration {
private static final Map<String, TerraConfig> configs = new HashMap<>();
private final Map<String, OreConfig> ores;
private final Map<String, PaletteConfig> palettes;
private final Map<String, CarverConfig> carvers;
private final Map<String, FloraConfig> flora;
private final Map<String, StructureConfig> structures;
private final Map<String, AbstractBiomeConfig> abstractBiomes;
private final Map<String, BiomeConfig> biomes;
private final Map<String, BiomeGridConfig> grids;
private final File dataFolder;
private final Map<World, TerraBiomeGrid> grid = new HashMap<>();
private final Map<World, BiomeZone> zones = new HashMap<>();
private final String id;
public List<String> biomeList;
public float zoneFreq;
public float freq1;
public float freq2;
public int blendAmp;
public boolean biomeBlend;
public float blendFreq;
public boolean perturbPaletteOnly;
public TerraConfig(JavaPlugin main, File file) throws IOException, InvalidConfigurationException {
load(new File(file, "config.yml"));
dataFolder = file;
if(!contains("id")) throw new ConfigException("No ID specified!", "null");
this.id = getString("id");
ores = ConfigLoader.load(main, new File(file, "ores").toPath(), this, OreConfig.class);
palettes = ConfigLoader.load(main, new File(file, "palettes").toPath(), this, PaletteConfig.class);
carvers = ConfigLoader.load(main, new File(file, "carvers").toPath(), this, CarverConfig.class);
flora = ConfigLoader.load(main, new File(file, "flora").toPath(), this, FloraConfig.class);
structures = ConfigLoader.load(main, new File(file, "structures").toPath(), this, StructureConfig.class);
abstractBiomes = ConfigLoader.load(main, new File(file, "abstract" + File.separator + "biomes").toPath(), this, AbstractBiomeConfig.class);
biomes = ConfigLoader.load(main, new File(file, "biomes").toPath(), this, BiomeConfig.class);
grids = ConfigLoader.load(main, new File(file, "grids").toPath(), this, BiomeGridConfig.class);
zoneFreq = 1f/getInt("frequencies.zone", 1536);
freq1 = 1f/getInt("frequencies.grid-x", 256);
freq2 = 1f/getInt("frequencies.grid-z", 512);
biomeBlend = getBoolean("blend.enable", false);
blendAmp = getInt("blend.amplitude", 8);
blendFreq = (float) getDouble("blend.frequency", 0.01);
perturbPaletteOnly = getBoolean("blend.ignore-terrain", true);
// Load BiomeGrids from BiomeZone
biomeList = getStringList("grids");
configs.put(id, this);
}
public Map<String, OreConfig> getOres() {
return ores;
}
public Map<String, PaletteConfig> getPalettes() {
return palettes;
}
public Map<String, AbstractBiomeConfig> getAbstractBiomes() {
return abstractBiomes;
}
public Map<String, BiomeConfig> getBiomes() {
return biomes;
}
public Map<String, BiomeGridConfig> getGrids() {
return grids;
}
public Map<String, CarverConfig> getCarvers() {
return carvers;
}
public Map<String, FloraConfig> getFlora() {
return flora;
}
public Map<String, StructureConfig> getStructures() {
return structures;
}
public static Map<String, TerraConfig> getConfigs() {
return configs;
}
public static void loadAll(JavaPlugin main) {
configs.clear();
List<Path> subfolder;
try {
subfolder = Files.walk(new File(main.getDataFolder(), "config").toPath(), 1)
.filter(Files::isDirectory)
.collect(Collectors.toList());
} catch(IOException e) {
e.printStackTrace();
return;
}
subfolder.remove(0);
for(Path folder : subfolder) {
TerraConfig config;
try {
config = new TerraConfig(main, folder.toFile());
configs.put(config.getID(), config);
} catch(IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
}
public File getDataFolder() {
return dataFolder;
}
public String getID() {
return id;
}
public static TerraConfig fromID(String id) {
return configs.get(id);
}
public BiomeConfig getBiome(UserDefinedBiome b) {
for(BiomeConfig biome : biomes.values()) {
if(biome.getBiome().equals(b)) return biome;
}
for(BiomeConfig biome : biomes.values()) {
Bukkit.getLogger().info(biome.getID() + ":" + biome.hashCode() + " : " + b.getID() + ":" + b.hashCode());
}
throw new IllegalArgumentException("No BiomeConfig for provided biome.");
}
public BiomeConfig getBiome(String id) {
return biomes.get(id);
}
public CarverConfig getCarver(String id) {
return carvers.get(id);
}
public CarverConfig getCarver(UserDefinedCarver c) {
for(CarverConfig co : carvers.values()) {
if(co.getCarver().equals(c)) return co;
}
throw new IllegalArgumentException("Unable to find carver!");
}
public StructureConfig getStructure(String id) {
return structures.get(id);
}
public PaletteConfig getPalette(String id) {
return palettes.get(id);
}
public OreConfig getOre(String id) {
return ores.get(id);
}
public List<String> getBiomeIDs() {
List<String> fill = new ArrayList<>();
for(BiomeConfig b : biomes.values()) {
fill.add(b.getID());
}
return fill;
}
public FloraConfig getFlora(String id) {
return flora.get(id);
}
public BiomeGridConfig getBiomeGrid(String id) {
Bukkit.getLogger().info(id + ", " + grids.get(id).getID());
return grids.get(id);
}
}

View File

@ -7,10 +7,15 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
public abstract class TerraConfigObject extends YamlConfiguration { public abstract class TerraConfigObject extends YamlConfiguration {
public TerraConfigObject(File file) throws IOException, InvalidConfigurationException { private final TerraConfig config;
super.load(file); public TerraConfigObject(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
init(); load(file);
this.config = config;
} }
public abstract void init() throws InvalidConfigurationException;
public TerraConfig getConfig() {
return config;
}
public abstract String getID(); public abstract String getID();
} }

View File

@ -3,6 +3,7 @@ package com.dfsek.terra.config.base;
import com.dfsek.terra.biome.BiomeZone; import com.dfsek.terra.biome.BiomeZone;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.config.ConfigLoader; import com.dfsek.terra.config.ConfigLoader;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.genconfig.AbstractBiomeConfig; import com.dfsek.terra.config.genconfig.AbstractBiomeConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig;
@ -27,7 +28,7 @@ import java.util.Set;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ConfigUtil { public final class ConfigUtil {
public static boolean debug; public static boolean debug;
public static long dataSave; // Period of population data saving, in ticks. public static long dataSave; // Period of population data saving, in ticks.
public static boolean masterDisableCaves; public static boolean masterDisableCaves;
@ -42,25 +43,7 @@ public class ConfigUtil {
Logger logger = main.getLogger(); Logger logger = main.getLogger();
logger.info("Loading config values"); logger.info("Loading config values");
new ConfigLoader("ores").load(main, OreConfig.class); TerraConfig.loadAll(main);
new ConfigLoader("palettes").load(main, PaletteConfig.class);
new ConfigLoader("carving").load(main, CarverConfig.class);
new ConfigLoader("flora").load(main, FloraConfig.class);
new ConfigLoader("structures" + File.separator + "single").load(main, StructureConfig.class);
new ConfigLoader("abstract" + File.separator + "biomes").load(main, AbstractBiomeConfig.class);
TerraBiomeGrid.invalidate();
BiomeZone.invalidate(); // Invalidate BiomeZone and BiomeGrid caches to prevent old instances from being accessed.
new ConfigLoader("biomes").load(main, BiomeConfig.class);
new ConfigLoader("grids").load(main, BiomeGridConfig.class);
WorldConfig.reloadAll();
} }
public static <E extends Enum<E>> List<E> getElements(List<String> st, Class<E> clazz) { public static <E extends Enum<E>> List<E> getElements(List<String> st, Class<E> clazz) {

View File

@ -0,0 +1,4 @@
package com.dfsek.terra.config.base;
public final class LangUtil {
}

View File

@ -1,8 +1,10 @@
package com.dfsek.terra.config.base; package com.dfsek.terra.config.base;
import com.dfsek.terra.Terra; import com.dfsek.terra.Terra;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.UserDefinedGrid; import com.dfsek.terra.biome.UserDefinedGrid;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.config.genconfig.BiomeGridConfig; import com.dfsek.terra.config.genconfig.BiomeGridConfig;
import com.dfsek.terra.image.ImageLoader; import com.dfsek.terra.image.ImageLoader;
@ -22,41 +24,21 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
public class WorldConfig { public class WorldConfig {
private static JavaPlugin main;
private static final Map<World, WorldConfig> configs = new HashMap<>();
public float zoneFreq;
public float freq1;
public float freq2;
public boolean fromImage; public boolean fromImage;
public UserDefinedGrid[] definedGrids; public TerraConfig config;
public ImageLoader.Channel biomeXChannel; public ImageLoader.Channel biomeXChannel;
public ImageLoader.Channel biomeZChannel; public ImageLoader.Channel biomeZChannel;
public ImageLoader.Channel zoneChannel; public ImageLoader.Channel zoneChannel;
public boolean biomeBlend;
public ImageLoader imageLoader; public ImageLoader imageLoader;
public int blendAmp;
public float blendFreq;
public boolean perturbPaletteOnly; private TerraConfig tConfig;
public WorldConfig(World w, JavaPlugin main) { public WorldConfig(World w, JavaPlugin main) {
WorldConfig.main = main;
load(w);
}
public static void reloadAll() {
for(Map.Entry<World, WorldConfig> e : configs.entrySet()) {
e.getValue().load(e.getKey());
}
}
public static WorldConfig fromWorld(World w) {
if(configs.containsKey(w)) return configs.get(w);
return new WorldConfig(w, Terra.getInstance());
}
public void load(World w) {
long start = System.nanoTime(); long start = System.nanoTime();
main.getLogger().info("Loading world configuration values for " + w + "..."); main.getLogger().info("Loading world configuration values for " + w + "...");
FileConfiguration config = new YamlConfiguration(); FileConfiguration config = new YamlConfiguration();
@ -71,16 +53,10 @@ public class WorldConfig {
// Get values from config. // Get values from config.
zoneFreq = 1f/config.getInt("frequencies.zone", 1536);
freq1 = 1f/config.getInt("frequencies.grid-x", 256);
freq2 = 1f/config.getInt("frequencies.grid-z", 512);
fromImage = config.getBoolean("image.use-image", false); fromImage = config.getBoolean("image.use-image", false);
biomeBlend = config.getBoolean("blend.enable", false);
blendAmp = config.getInt("blend.amplitude", 8);
blendFreq = (float) config.getDouble("blend.frequency", 0.01);
perturbPaletteOnly = config.getBoolean("blend.ignore-terrain", true);
tConfig = TerraConfig.fromID(config.getString("config"));
// Load image stuff // Load image stuff
try { try {
@ -103,29 +79,7 @@ public class WorldConfig {
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
throw new InvalidConfigurationException(e.getCause()); throw new InvalidConfigurationException(e.getCause());
} }
Bukkit.getLogger().info("Loaded " + tConfig.biomeList.size() + " BiomeGrids from list.");
configs.put(w, this); // WorldConfig must be included in map before Grids are loaded.
// Load BiomeGrids from BiomeZone
List<String> biomeList = config.getStringList("grids");
definedGrids = new UserDefinedGrid[biomeList.size()];
for(int i = 0; i < biomeList.size(); i++) {
String partName = biomeList.get(i);
try {
if(partName.startsWith("BIOME:")) {
UserDefinedBiome[][] temp = new UserDefinedBiome[1][1];
UserDefinedBiome b = BiomeConfig.fromID(partName.substring(6)).getBiome();
temp[0][0] = b;
definedGrids[i] = new UserDefinedGrid(w, freq1, freq2, temp);
main.getLogger().info("Loaded single-biome grid " + partName);
} else definedGrids[i] = BiomeGridConfig.getBiomeGrids().get(partName).getGrid(w);
} catch(NullPointerException e) {
Bukkit.getLogger().severe("No such BiomeGrid " + partName);
}
}
Bukkit.getLogger().info("Loaded " + biomeList.size() + " BiomeGrids from list.");
} catch(IOException | InvalidConfigurationException e) { } catch(IOException | InvalidConfigurationException e) {
e.printStackTrace(); e.printStackTrace();
@ -134,4 +88,8 @@ public class WorldConfig {
main.getLogger().info("World load complete. Time elapsed: " + ((double) (System.nanoTime() - start)) / 1000000 + "ms"); main.getLogger().info("World load complete. Time elapsed: " + ((double) (System.nanoTime() - start)) / 1000000 + "ms");
} }
public TerraConfig getConfig() {
return tConfig;
}
} }

View File

@ -1,7 +1,8 @@
package com.dfsek.terra.config.genconfig; package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.TerraConfigObject; import com.dfsek.terra.config.TerraConfigObject;
import com.dfsek.terra.config.exception.ConfigException;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
@ -9,28 +10,26 @@ import org.polydev.gaea.world.palette.Palette;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
public class AbstractBiomeConfig extends TerraConfigObject { public class AbstractBiomeConfig extends TerraConfigObject {
private static final Map<String, AbstractBiomeConfig> biomes = new HashMap<>(); private final String biomeID;
private String biomeID; private final int floraChance;
private int floraChance; private final int treeChance;
private int treeChance; private final int treeDensity;
private int treeDensity; private final String equation;
private String equation; private final int floraAttempts;
private int floraAttempts;
private double slabThreshold; private double slabThreshold;
private Map<Material, Palette<BlockData>> slabs; private Map<Material, Palette<BlockData>> slabs;
private Map<Material, Palette<BlockData>> stairs; private Map<Material, Palette<BlockData>> stairs;
private boolean useStairs; private boolean useStairs;
private boolean floraSimplex; private final boolean floraSimplex;
private int floraSeed; private final int floraSeed;
private float floraFreq; private final float floraFreq;
private String oceanPalette; private final String oceanPalette;
private int seaLevel; private final int seaLevel;
private List<Map<?, ?>> paletteData; private List<Map<?, ?>> paletteData;
private Map<String, Object> floraData; private Map<String, Object> floraData;
private Map<String, Object> oreData; private Map<String, Object> oreData;
@ -38,12 +37,9 @@ public class AbstractBiomeConfig extends TerraConfigObject {
private List<Map<?, ?>> carvingData; private List<Map<?, ?>> carvingData;
private List<String> structureConfigs; private List<String> structureConfigs;
public AbstractBiomeConfig(File file) throws IOException, InvalidConfigurationException { public AbstractBiomeConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
super(file); super(file, config);
} load(file);
@Override
public void init() throws InvalidConfigurationException {
if(!contains("id")) throw new ConfigException("Abstract Biome ID unspecified!", "null"); if(!contains("id")) throw new ConfigException("Abstract Biome ID unspecified!", "null");
this.biomeID = getString("id"); this.biomeID = getString("id");
@ -80,8 +76,6 @@ public class AbstractBiomeConfig extends TerraConfigObject {
} }
if(contains("structures")) structureConfigs = getStringList("structures"); if(contains("structures")) structureConfigs = getStringList("structures");
biomes.put(biomeID, this);
} }
@Override @Override
@ -109,10 +103,6 @@ public class AbstractBiomeConfig extends TerraConfigObject {
return equation; return equation;
} }
public static AbstractBiomeConfig fromID(String id) {
return biomes.get(id);
}
public Map<Material, Palette<BlockData>> getSlabs() { public Map<Material, Palette<BlockData>> getSlabs() {
return slabs; return slabs;
} }

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.config.genconfig; package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.exception.NotFoundException; import com.dfsek.terra.config.exception.NotFoundException;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
@ -39,13 +40,12 @@ import java.util.Random;
import java.util.TreeMap; import java.util.TreeMap;
public class BiomeConfig extends TerraConfigObject { public class BiomeConfig extends TerraConfigObject {
private static final Map<String, BiomeConfig> biomes = new HashMap<>();
private static final Palette<BlockData> oceanDefault = new RandomPalette<BlockData>(new Random(0)).add(Material.WATER.createBlockData(), 1); private static final Palette<BlockData> oceanDefault = new RandomPalette<BlockData>(new Random(0)).add(Material.WATER.createBlockData(), 1);
private UserDefinedBiome biome; private final UserDefinedBiome biome;
private String biomeID; private final String biomeID;
private Map<OreConfig, Range> ores; private Map<OreConfig, Range> ores;
private Map<OreConfig, Range> oreHeights; private Map<OreConfig, Range> oreHeights;
private Map<CarverConfig, Integer> carvers; private final Map<CarverConfig, Integer> carvers;
private Map<Flora, Range> floraHeights; private Map<Flora, Range> floraHeights;
private String eq; private String eq;
private int floraAttempts; private int floraAttempts;
@ -54,17 +54,16 @@ public class BiomeConfig extends TerraConfigObject {
private double slabThreshold; private double slabThreshold;
private boolean floraSimplex; private boolean floraSimplex;
private FastNoise floraNoise; private FastNoise floraNoise;
private Palette<BlockData> ocean; private final Palette<BlockData> ocean;
private int seaLevel; private int seaLevel;
private List<StructureConfig> structures; private final List<StructureConfig> structures;
private final TerraConfig config;
public BiomeConfig(File file) throws InvalidConfigurationException, IOException {
super(file);
}
@Override
@SuppressWarnings("unchecked, rawtypes") @SuppressWarnings("unchecked, rawtypes")
public void init() throws InvalidConfigurationException { public BiomeConfig(File file, TerraConfig config) throws InvalidConfigurationException, IOException {
super(file, config);
load(file);
this.config = config;
if(!contains("id")) throw new ConfigException("Biome ID unspecified!", "null"); if(!contains("id")) throw new ConfigException("Biome ID unspecified!", "null");
this.biomeID = getString("id"); this.biomeID = getString("id");
@ -74,7 +73,7 @@ public class BiomeConfig extends TerraConfigObject {
// Check if biome extends an abstract biome, load abstract biome if so. // Check if biome extends an abstract biome, load abstract biome if so.
if(contains("extends")) { if(contains("extends")) {
try { try {
abstractBiome = AbstractBiomeConfig.fromID(getString("extends")); abstractBiome = config.getAbstractBiomes().get(getString("extends"));
extending = true; extending = true;
Bukkit.getLogger().info("Extending biome " + getString("extends")); Bukkit.getLogger().info("Extending biome " + getString("extends"));
} catch(NullPointerException e) { } catch(NullPointerException e) {
@ -107,7 +106,7 @@ public class BiomeConfig extends TerraConfigObject {
} }
else { else {
try { try {
paletteMap.put((Integer) entry.getValue(), PaletteConfig.fromID((String) entry.getKey()).getPalette()); paletteMap.put((Integer) entry.getValue(), config.getPalette((String) entry.getKey()).getPalette());
} catch(NullPointerException ex) { } catch(NullPointerException ex) {
throw new NotFoundException("Palette", (String) entry.getKey(), getID()); throw new NotFoundException("Palette", (String) entry.getKey(), getID());
} }
@ -135,7 +134,7 @@ public class BiomeConfig extends TerraConfigObject {
for(Map<?, ?> e : carvingData) { for(Map<?, ?> e : carvingData) {
for(Map.Entry<?, ?> entry : e.entrySet()) { for(Map.Entry<?, ?> entry : e.entrySet()) {
try { try {
CarverConfig c = CarverConfig.fromID((String) entry.getKey()); CarverConfig c = getConfig().getCarver((String) entry.getKey());
Bukkit.getLogger().info("Got carver " + c + ". Adding with weight " + entry.getValue()); Bukkit.getLogger().info("Got carver " + c + ". Adding with weight " + entry.getValue());
carvers.put(c, (Integer) entry.getValue()); carvers.put(c, (Integer) entry.getValue());
} catch(ClassCastException ex) { } catch(ClassCastException ex) {
@ -207,7 +206,7 @@ public class BiomeConfig extends TerraConfigObject {
} catch(IllegalArgumentException ex) { } catch(IllegalArgumentException ex) {
try { try {
Bukkit.getLogger().info("[Terra] Is custom flora: true"); Bukkit.getLogger().info("[Terra] Is custom flora: true");
Flora floraCustom = FloraConfig.fromID(e.getKey()); Flora floraCustom = getConfig().getFlora(e.getKey());
flora.add(floraCustom, (Integer) val.get("weight")); flora.add(floraCustom, (Integer) val.get("weight"));
floraHeights.put(floraCustom, new Range((Integer) y.get("min"), (Integer) y.get("max"))); floraHeights.put(floraCustom, new Range((Integer) y.get("min"), (Integer) y.get("max")));
} catch(NullPointerException ex2) { } catch(NullPointerException ex2) {
@ -271,8 +270,8 @@ public class BiomeConfig extends TerraConfigObject {
} }
if(oreData != null) { if(oreData != null) {
for(Map.Entry<String, Object> m : oreData.entrySet()) { for(Map.Entry<String, Object> m : oreData.entrySet()) {
ores.put(OreConfig.fromID(m.getKey()), new Range(((ConfigurationSection) m.getValue()).getInt("min"), ((ConfigurationSection) m.getValue()).getInt("max"))); ores.put(config.getOre(m.getKey()), new Range(((ConfigurationSection) m.getValue()).getInt("min"), ((ConfigurationSection) m.getValue()).getInt("max")));
oreHeights.put(OreConfig.fromID(m.getKey()), new Range(((ConfigurationSection) m.getValue()).getInt("min-height"), ((ConfigurationSection) m.getValue()).getInt("max-height"))); oreHeights.put(config.getOre(m.getKey()), new Range(((ConfigurationSection) m.getValue()).getInt("min-height"), ((ConfigurationSection) m.getValue()).getInt("max-height")));
} }
} else { } else {
ores = new HashMap<>(); ores = new HashMap<>();
@ -295,7 +294,7 @@ public class BiomeConfig extends TerraConfigObject {
} }
} else { } else {
try { try {
ocean = PaletteConfig.fromID(oceanPalette).getPalette(); ocean = config.getPalette(oceanPalette).getPalette();
} catch(NullPointerException ex) { } catch(NullPointerException ex) {
throw new NotFoundException("Palette", oceanPalette, getID()); throw new NotFoundException("Palette", oceanPalette, getID());
} }
@ -342,7 +341,7 @@ public class BiomeConfig extends TerraConfigObject {
if(contains("structures")) st = getStringList("structures"); if(contains("structures")) st = getStringList("structures");
for(String s : st) { for(String s : st) {
try { try {
structures.add(Objects.requireNonNull(StructureConfig.fromID(s))); structures.add(Objects.requireNonNull(config.getStructure(s)));
} catch(NullPointerException e) { } catch(NullPointerException e) {
throw new NotFoundException("Structure", s, getID()); throw new NotFoundException("Structure", s, getID());
} }
@ -355,7 +354,6 @@ public class BiomeConfig extends TerraConfigObject {
e.printStackTrace(); e.printStackTrace();
throw new ConfigException("Unable to parse noise equation!", getID()); throw new ConfigException("Unable to parse noise equation!", getID());
} }
biomes.put(biomeID, this);
} }
public Range getOreHeight(OreConfig c) { public Range getOreHeight(OreConfig c) {
@ -382,31 +380,13 @@ public class BiomeConfig extends TerraConfigObject {
return floraHeights.computeIfAbsent(f, input -> new Range(-1, -1)); return floraHeights.computeIfAbsent(f, input -> new Range(-1, -1));
} }
public static BiomeConfig fromBiome(UserDefinedBiome b) {
for(BiomeConfig biome : biomes.values()) {
if(biome.getBiome().equals(b)) return biome;
}
for(BiomeConfig biome : biomes.values()) {
Bukkit.getLogger().info(biome.getID() + ":" + biome.hashCode() + " : " + b.getID() + ":" + b.hashCode());
}
throw new IllegalArgumentException("No BiomeConfig for provided biome.");
}
public static List<String> getBiomeIDs() {
return new ArrayList<>(biomes.keySet());
}
public static BiomeConfig fromID(String id) {
return biomes.get(id);
}
@Override @Override
public String toString() { public String toString() {
return "Biome with ID " + getID() + " and noise equation " + eq; return "Biome with ID " + getID() + " and noise equation " + eq;
} }
public int getCarverChance(UserDefinedCarver c) { public int getCarverChance(UserDefinedCarver c) {
return carvers.getOrDefault(CarverConfig.fromDefinedCarver(c), 0); return carvers.getOrDefault(config.getCarver(c), 0);
} }
public double getSlabThreshold() { public double getSlabThreshold() {

View File

@ -32,7 +32,7 @@ public class BiomeConfigUtil {
} }
} else { } else {
try { try {
Palette<BlockData> p = PaletteConfig.fromID((String) entry.getValue()).getPalette(); Palette<BlockData> p = config.getConfig().getPalette((String) entry.getValue()).getPalette();
if(p.getSize() != 1) throw new InvalidConfigurationException("Slab palette must hold only one layer. Palette " + entry.getValue() + " is too large/small"); if(p.getSize() != 1) throw new InvalidConfigurationException("Slab palette must hold only one layer. Palette " + entry.getValue() + " is too large/small");
paletteMap.put(Bukkit.createBlockData((String) entry.getKey()).getMaterial(), p); paletteMap.put(Bukkit.createBlockData((String) entry.getKey()).getMaterial(), p);
} catch(NullPointerException ex) { } catch(NullPointerException ex) {

View File

@ -2,6 +2,7 @@ package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.UserDefinedGrid; import com.dfsek.terra.biome.UserDefinedGrid;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.TerraConfigObject; import com.dfsek.terra.config.TerraConfigObject;
import com.dfsek.terra.config.base.WorldConfig; import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
@ -17,32 +18,26 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
public class BiomeGridConfig extends TerraConfigObject { public class BiomeGridConfig extends TerraConfigObject {
private static final Map<String, BiomeGridConfig> biomeGrids = new HashMap<>(); private final String gridID;
private String gridID; private final UserDefinedBiome[][] gridRaw;
private boolean isEnabled = false; private final int sizeX;
private UserDefinedBiome[][] gridRaw; private final int sizeZ;
private int sizeX;
private int sizeZ;
public BiomeGridConfig(File file) throws IOException, InvalidConfigurationException {
super(file);
}
@Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void init() throws InvalidConfigurationException { public BiomeGridConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
isEnabled = false; super(file, config);
load(file);
if(!contains("id")) throw new ConfigException("Grid ID unspecified!", "null"); if(!contains("id")) throw new ConfigException("Grid ID unspecified!", "null");
this.gridID = getString("id"); this.gridID = getString("id");
if(!contains("grid")) throw new ConfigException("Grid key not found!", getID()); if(!contains("grid")) throw new ConfigException("Grid key not found!", getID());
this.sizeX = Objects.requireNonNull(getList("grid")).size(); this.sizeX = Objects.requireNonNull(getList("grid")).size();
this.sizeZ = ((List<List<String>>) getList("grid")).get(0).size(); this.sizeZ = ((List<List<String>>) Objects.requireNonNull(getList("grid"))).get(0).size();
gridRaw = new UserDefinedBiome[sizeX][sizeZ]; gridRaw = new UserDefinedBiome[sizeX][sizeZ];
try { try {
for(int x = 0; x < sizeX; x++) { for(int x = 0; x < sizeX; x++) {
for(int z = 0; z < sizeZ; z++) { for(int z = 0; z < sizeZ; z++) {
try { try {
gridRaw[x][z] = BiomeConfig.fromID(((List<List<String>>) Objects.requireNonNull(getList("grid"))).get(x).get(z)).getBiome(); gridRaw[x][z] = config.getBiome(((List<List<String>>) Objects.requireNonNull(getList("grid"))).get(x).get(z)).getBiome();
} catch(NullPointerException e) { } catch(NullPointerException e) {
throw new NotFoundException("Biome",((List<List<String>>) Objects.requireNonNull(getList("grid"))).get(x).get(z), getID()); throw new NotFoundException("Biome",((List<List<String>>) Objects.requireNonNull(getList("grid"))).get(x).get(z), getID());
} }
@ -51,8 +46,6 @@ public class BiomeGridConfig extends TerraConfigObject {
} catch(ClassCastException |NullPointerException e) { } catch(ClassCastException |NullPointerException e) {
throw new ConfigException("Malformed grid! Ensure all dimensions are correct.", getID()); throw new ConfigException("Malformed grid! Ensure all dimensions are correct.", getID());
} }
isEnabled = true;
biomeGrids.put(gridID, this);
} }
public int getSizeX() { public int getSizeX() {
@ -67,25 +60,18 @@ public class BiomeGridConfig extends TerraConfigObject {
return gridRaw; return gridRaw;
} }
public boolean isEnabled() {
return isEnabled;
}
public String getID() { public String getID() {
return gridID; return gridID;
} }
public UserDefinedGrid getGrid(World w) { public UserDefinedGrid getGrid(World w, WorldConfig wc) {
WorldConfig c = WorldConfig.fromWorld(w); TerraConfig c = wc.getConfig();
return new UserDefinedGrid(w, c.freq1, c.freq2, gridRaw); return new UserDefinedGrid(w, c.freq1, c.freq2, gridRaw, wc);
} }
@Override @Override
public String toString() { public String toString() {
return "BiomeGrid with ID " + getID() + ", dimensions " + getSizeX() + ":" + getSizeZ(); return "BiomeGrid with ID " + getID() + ", dimensions " + getSizeX() + ":" + getSizeZ();
} }
public static Map<String, BiomeGridConfig> getBiomeGrids() {
return biomeGrids;
}
} }

View File

@ -1,59 +1,49 @@
package com.dfsek.terra.config.genconfig; package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.TerraConfigObject;
import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
import org.polydev.gaea.math.Range;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.TerraConfigObject;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.polydev.gaea.math.ProbabilityCollection; import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.math.Range;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
public class CarverConfig extends TerraConfigObject { public class CarverConfig extends TerraConfigObject {
private static final Map<String, CarverConfig> caveConfig = new HashMap<>(); private final UserDefinedCarver carver;
private UserDefinedCarver carver; private final String id;
private String id; private final Set<Material> replaceableInner;
private Set<Material> replaceableInner; private final Set<Material> replaceableOuter;
private Set<Material> replaceableOuter; private final Set<Material> replaceableTop;
private Set<Material> replaceableTop; private final Set<Material> replaceableBottom;
private Set<Material> replaceableBottom; private final Set<Material> update;
private Set<Material> update; private final Map<Material, Set<Material>> shift;
private Map<Material, Set<Material>> shift; private final Map<Integer, ProbabilityCollection<BlockData>> inner;
private Map<Integer, ProbabilityCollection<BlockData>> inner; private final Map<Integer, ProbabilityCollection<BlockData>> outer;
private Map<Integer, ProbabilityCollection<BlockData>> outer; private final Map<Integer, ProbabilityCollection<BlockData>> top;
private Map<Integer, ProbabilityCollection<BlockData>> top; private final Map<Integer, ProbabilityCollection<BlockData>> bottom;
private Map<Integer, ProbabilityCollection<BlockData>> bottom; private final boolean replaceIsBlacklistInner;
private boolean replaceIsBlacklistInner; private final boolean replaceIsBlacklistOuter;
private boolean replaceIsBlacklistOuter; private final boolean replaceIsBlacklistTop;
private boolean replaceIsBlacklistTop; private final boolean replaceIsBlacklistBottom;
private boolean replaceIsBlacklistBottom;
public CarverConfig(File file) throws IOException, InvalidConfigurationException { @SuppressWarnings("unchecked")
super(file); public CarverConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
} super(file, config);
load(file);
public String getID() {
return id;
}
public UserDefinedCarver getCarver() {
return carver;
}
@Override
public void init() throws InvalidConfigurationException {
if(!contains("id")) throw new ConfigException("No ID specified for Carver!", "null"); if(!contains("id")) throw new ConfigException("No ID specified for Carver!", "null");
id = getString("id"); id = getString("id");
@ -76,7 +66,7 @@ public class CarverConfig extends TerraConfigObject {
update = ConfigUtil.toBlockData(getStringList("update"), "update", getID()); update = ConfigUtil.toBlockData(getStringList("update"), "update", getID());
shift = new HashMap<>(); shift = new HashMap<>();
for(Map.Entry<String, Object> e : getConfigurationSection("shift").getValues(false).entrySet()) { for(Map.Entry<String, Object> e : Objects.requireNonNull(getConfigurationSection("shift")).getValues(false).entrySet()) {
Set<Material> l = new HashSet<>(); Set<Material> l = new HashSet<>();
for(String s : (List<String>) e.getValue()) { for(String s : (List<String>) e.getValue()) {
l.add(Bukkit.createBlockData(s).getMaterial()); l.add(Bukkit.createBlockData(s).getMaterial());
@ -99,9 +89,17 @@ public class CarverConfig extends TerraConfigObject {
Range height = new Range(getInt("start.height.min"), getInt("start.height.max")); Range height = new Range(getInt("start.height.min"), getInt("start.height.max"));
carver = new UserDefinedCarver(height, radius, length, start, mutate, radiusMultiplier, id.hashCode(), getInt("cut.top", 0), getInt("cut.bottom", 0)); carver = new UserDefinedCarver(height, radius, length, start, mutate, radiusMultiplier, id.hashCode(), getInt("cut.top", 0), getInt("cut.bottom", 0));
caveConfig.put(id, this);
} }
public String getID() {
return id;
}
public UserDefinedCarver getCarver() {
return carver;
}
@SuppressWarnings("unchecked")
private Map<Integer, ProbabilityCollection<BlockData>> getBlocks(String key) throws InvalidConfigurationException { private Map<Integer, ProbabilityCollection<BlockData>> getBlocks(String key) throws InvalidConfigurationException {
if(!contains(key)) throw new ConfigException("Missing Carver Palette!", getID()); if(!contains(key)) throw new ConfigException("Missing Carver Palette!", getID());
Map<Integer, ProbabilityCollection<BlockData>> result = new TreeMap<>(); Map<Integer, ProbabilityCollection<BlockData>> result = new TreeMap<>();
@ -189,18 +187,4 @@ public class CarverConfig extends TerraConfigObject {
public String toString() { public String toString() {
return "Carver with ID " + getID(); return "Carver with ID " + getID();
} }
public static List<CarverConfig> getCarvers() {
return new ArrayList<>(caveConfig.values());
}
public static CarverConfig fromID(String id) {
return caveConfig.get(id);
}
public static CarverConfig fromDefinedCarver(UserDefinedCarver c) {
for(CarverConfig co : caveConfig.values()) {
if(co.getCarver().equals(c)) return co;
}
throw new IllegalArgumentException("Unable to find carver!");
}
} }

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.config.genconfig; package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.TerraConfigObject; import com.dfsek.terra.config.TerraConfigObject;
import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
@ -26,19 +27,15 @@ import java.util.Random;
import java.util.Set; import java.util.Set;
public class FloraConfig extends TerraConfigObject implements Flora { public class FloraConfig extends TerraConfigObject implements Flora {
private static final Map<String, FloraConfig> floraConfig = new HashMap<>(); private final Palette<BlockData> floraPalette;
private Palette<BlockData> floraPalette; private final String id;
private String id;
Set<Material> spawnable; Set<Material> spawnable;
Set<Material> replaceable; Set<Material> replaceable;
public FloraConfig(File file) throws IOException, InvalidConfigurationException { public FloraConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
super(file); super(file, config);
} load(file);
@Override
public void init() throws InvalidConfigurationException {
if(!contains("id")) throw new ConfigException("Flora ID unspecified!", "null"); if(!contains("id")) throw new ConfigException("Flora ID unspecified!", "null");
this.id = getString("id"); this.id = getString("id");
if(!contains("blocks")) throw new ConfigException("No blocks defined in custom flora!", getID()); if(!contains("blocks")) throw new ConfigException("No blocks defined in custom flora!", getID());
@ -50,8 +47,6 @@ public class FloraConfig extends TerraConfigObject implements Flora {
Palette<BlockData> p = new RandomPalette<>(new Random(getInt("seed", 4))); Palette<BlockData> p = new RandomPalette<>(new Random(getInt("seed", 4)));
floraPalette = PaletteConfig.getPalette(getMapList("blocks"), p); floraPalette = PaletteConfig.getPalette(getMapList("blocks"), p);
floraConfig.put(id, this);
} }
public String getID() { public String getID() {
@ -86,8 +81,4 @@ public class FloraConfig extends TerraConfigObject implements Flora {
public String toString() { public String toString() {
return "Flora with name ID " + getID(); return "Flora with name ID " + getID();
} }
public static FloraConfig fromID(String id) {
return floraConfig.get(id);
}
} }

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.config.genconfig; package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.TerraConfigObject; import com.dfsek.terra.config.TerraConfigObject;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
@ -22,20 +23,15 @@ import java.util.Random;
import java.util.Set; import java.util.Set;
public class OreConfig extends TerraConfigObject { public class OreConfig extends TerraConfigObject {
private static final Map<String, OreConfig> ores = new HashMap<>(); private final BlockData oreData;
private BlockData oreData; private final int min;
private int min; private final int max;
private int max; private final double deform;
private double deform; private final double deformFrequency;
private double deformFrequency; private final String id;
private String id;
Set<Material> replaceable; Set<Material> replaceable;
public OreConfig(File file) throws IOException, InvalidConfigurationException { public OreConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
super(file); super(file, config);
}
@Override
public void init() throws InvalidConfigurationException {
if(!contains("id")) throw new ConfigException("Ore ID not found!", "null"); if(!contains("id")) throw new ConfigException("Ore ID not found!", "null");
this.id = getString("id"); this.id = getString("id");
if(!contains("material")) throw new ConfigException("Ore material not found!", getID()); if(!contains("material")) throw new ConfigException("Ore material not found!", getID());
@ -53,8 +49,8 @@ public class OreConfig extends TerraConfigObject {
} catch(NullPointerException | IllegalArgumentException e) { } catch(NullPointerException | IllegalArgumentException e) {
throw new ConfigException("Invalid ore material: " + getString("material"), getID()); throw new ConfigException("Invalid ore material: " + getString("material"), getID());
} }
ores.put(id, this);
} }
private int randomInRange(Random r) { private int randomInRange(Random r) {
return r.nextInt(max-min+1)+min; return r.nextInt(max-min+1)+min;
} }
@ -75,10 +71,6 @@ public class OreConfig extends TerraConfigObject {
} }
} }
public static List<String> getOreIDs() {
return new ArrayList<>(ores.keySet());
}
@Override @Override
public String toString() { public String toString() {
return "Ore with ID " + getID(); return "Ore with ID " + getID();
@ -87,8 +79,4 @@ public class OreConfig extends TerraConfigObject {
public String getID() { public String getID() {
return id; return id;
} }
public static OreConfig fromID(String id) {
return ores.get(id);
}
} }

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.config.genconfig; package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.TerraConfigObject; import com.dfsek.terra.config.TerraConfigObject;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -13,22 +14,16 @@ import org.polydev.gaea.world.palette.SimplexPalette;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
public class PaletteConfig extends TerraConfigObject { public class PaletteConfig extends TerraConfigObject {
private static final Map<String, PaletteConfig> palettes = new HashMap<>(); private final Palette<BlockData> palette;
private Palette<BlockData> palette; private final String paletteID;
private String paletteID;
private boolean useNoise = false; private boolean useNoise = false;
public PaletteConfig(File file) throws IOException, InvalidConfigurationException { public PaletteConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
super(file); super(file, config);
}
@Override
public void init() throws InvalidConfigurationException {
if(!contains("id")) throw new ConfigException("Palette ID unspecified!", "null"); if(!contains("id")) throw new ConfigException("Palette ID unspecified!", "null");
this.paletteID = getString("id"); this.paletteID = getString("id");
Palette<BlockData> pal; Palette<BlockData> pal;
@ -41,7 +36,6 @@ public class PaletteConfig extends TerraConfigObject {
pal = new SimplexPalette<>(pNoise); pal = new SimplexPalette<>(pNoise);
} else pal = new RandomPalette<>(new Random(getInt("seed", 3))); } else pal = new RandomPalette<>(new Random(getInt("seed", 3)));
palette = getPalette(getMapList("blocks"), pal); palette = getPalette(getMapList("blocks"), pal);
palettes.put(paletteID, this);
} }
public Palette<BlockData> getPalette() { public Palette<BlockData> getPalette() {
@ -84,8 +78,4 @@ public class PaletteConfig extends TerraConfigObject {
public String toString() { public String toString() {
return "Palette with ID " + getID() + " with " + getPalette().getSize() + " layers, using Simplex: " + useNoise; return "Palette with ID " + getID() + " with " + getPalette().getSize() + " layers, using Simplex: " + useNoise;
} }
public static PaletteConfig fromID(String id) {
return palettes.get(id);
}
} }

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.config.genconfig; package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.exception.NotFoundException; import com.dfsek.terra.config.exception.NotFoundException;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
@ -18,24 +19,19 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
public class StructureConfig extends TerraConfigObject { public class StructureConfig extends TerraConfigObject {
private static final Map<String, StructureConfig> configs = new HashMap<>(); private final GaeaStructure structure;
private GaeaStructure structure; private final GridSpawn spawn;
private GridSpawn spawn; private final String id;
private String id; private final Range searchStart;
private Range searchStart; private final Range bound;
private Range bound;
StructurePopulator.SearchType type; StructurePopulator.SearchType type;
public StructureConfig(File file) throws IOException, InvalidConfigurationException { public StructureConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
super(file); super(file, config);
}
@Override
public void init() throws InvalidConfigurationException {
if(!contains("id")) throw new ConfigException("No ID specified!", "null"); if(!contains("id")) throw new ConfigException("No ID specified!", "null");
id = getString("id"); id = getString("id");
try { try {
File file = new File(Terra.getInstance().getDataFolder() + File.separator + "config" + File.separator + "structures" + File.separator + "data", Objects.requireNonNull(getString("file"))); File structureFile = new File(config.getDataFolder() + File.separator + "structures" + File.separator + "data", Objects.requireNonNull(getString("file")));
structure = GaeaStructure.load(file); structure = GaeaStructure.load(structureFile);
} catch(IOException | NullPointerException e) { } catch(IOException | NullPointerException e) {
if(ConfigUtil.debug) { if(ConfigUtil.debug) {
e.printStackTrace(); e.printStackTrace();
@ -51,7 +47,6 @@ public class StructureConfig extends TerraConfigObject {
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
throw new ConfigException("Invalid search type, " + getString("spawn.search"), getID()); throw new ConfigException("Invalid search type, " + getString("spawn.search"), getID());
} }
configs.put(id, this);
} }
@Override @Override
@ -74,8 +69,4 @@ public class StructureConfig extends TerraConfigObject {
public Range getSearchStart() { public Range getSearchStart() {
return searchStart; return searchStart;
} }
public static StructureConfig fromID(String id) {
return configs.get(id);
}
} }

View File

@ -1,49 +0,0 @@
package com.dfsek.terra.generation;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.genconfig.BiomeConfig;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Slab;
import org.bukkit.block.data.type.Stairs;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.util.Vector;
import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.generation.GenerationPopulator;
import org.polydev.gaea.math.ChunkInterpolator;
import org.polydev.gaea.world.palette.Palette;
import org.polydev.gaea.world.palette.RandomPalette;
import java.util.Map;
import java.util.Random;
public class SlabGenerator extends GenerationPopulator {
private static final BlockData AIR = Material.AIR.createBlockData();
private static final BlockData WATER = Material.WATER.createBlockData();
private static final Palette<BlockData> AIRPALETTE = new RandomPalette<BlockData>(new Random(2403)).add(AIR, 1);
@Override
public ChunkGenerator.ChunkData populate(World world, ChunkGenerator.ChunkData chunk, Random random, int chunkX, int chunkZ, ChunkInterpolator interp) {
TerraBiomeGrid g = TerraBiomeGrid.fromWorld(world);
for(byte x = 0; x < 16; x++) {
for(byte z = 0; z < 16; z++) {
int xi = (chunkX << 4) + x;
int zi = (chunkZ << 4) + z;
BiomeConfig config = BiomeConfig.fromBiome((UserDefinedBiome) g.getBiome(xi, zi, GenerationPhase.PALETTE_APPLY));
if(config.getSlabs() == null) continue;
double thresh = config.getSlabThreshold();
for(int y = 0; y < world.getMaxHeight(); y++) {
}
}
}
return chunk;
}
}

View File

@ -1,8 +1,11 @@
package com.dfsek.terra.generation; package com.dfsek.terra.generation;
import com.dfsek.terra.Terra; import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.population.CavePopulator; import com.dfsek.terra.population.CavePopulator;
import com.dfsek.terra.population.FloraPopulator; import com.dfsek.terra.population.FloraPopulator;
@ -59,6 +62,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
if(needsLoad) load(world); if(needsLoad) load(world);
StructureSpawnRequirement.putNoise(world, fastNoise); // Assign noise to world to be used for structures. StructureSpawnRequirement.putNoise(world, fastNoise); // Assign noise to world to be used for structures.
ChunkData chunk = createChunkData(world); ChunkData chunk = createChunkData(world);
TerraConfig config = TerraWorld.getWorld(world).getConfig();
int xOrig = (chunkX << 4); int xOrig = (chunkX << 4);
int zOrig = (chunkZ << 4); int zOrig = (chunkZ << 4);
for(byte x = 0; x < 16; x++) { for(byte x = 0; x < 16; x++) {
@ -67,7 +71,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
int cx = xOrig + x; int cx = xOrig + x;
int cz = zOrig + z; int cz = zOrig + z;
Biome b = getBiomeGrid(world).getBiome(xOrig+x, zOrig+z, GenerationPhase.PALETTE_APPLY); Biome b = getBiomeGrid(world).getBiome(xOrig+x, zOrig+z, GenerationPhase.PALETTE_APPLY);
BiomeConfig c = BiomeConfig.fromBiome((UserDefinedBiome) b); BiomeConfig c = config.getBiome((UserDefinedBiome) b);
int sea = c.getSeaLevel(); int sea = c.getSeaLevel();
Palette<BlockData> seaPalette = c.getOceanPalette(); Palette<BlockData> seaPalette = c.getOceanPalette();
for(int y = world.getMaxHeight()-1; y >= 0; y--) { for(int y = world.getMaxHeight()-1; y >= 0; y--) {
@ -166,13 +170,13 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
@Override @Override
public List<GenerationPopulator> getGenerationPopulators(World world) { public List<GenerationPopulator> getGenerationPopulators(World world) {
return Collections.singletonList(new SlabGenerator()); return Collections.emptyList();
} }
@Override @Override
public org.polydev.gaea.biome.BiomeGrid getBiomeGrid(World world) { public org.polydev.gaea.biome.BiomeGrid getBiomeGrid(World world) {
return TerraBiomeGrid.fromWorld(world); return TerraWorld.getWorld(world).getGrid();
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.image; package com.dfsek.terra.image;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.generation.TerraChunkGenerator; import com.dfsek.terra.generation.TerraChunkGenerator;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
@ -34,12 +35,12 @@ public class DebugFrame extends JFrame implements ActionListener {
if(! (p.getWorld().getGenerator() instanceof TerraChunkGenerator)) break; if(! (p.getWorld().getGenerator() instanceof TerraChunkGenerator)) break;
int xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX() - (img.getWidth() / 2), x) / x) * getWidth()); int xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX() - (img.getWidth() / 2), x) / x) * getWidth());
int zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ() - (img.getHeight() / 2), z) / z) * getHeight()); int zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ() - (img.getHeight() / 2), z) / z) * getHeight());
ImageLoader loader = WorldConfig.fromWorld(p.getWorld()).imageLoader; ImageLoader loader = TerraWorld.getWorld(p.getWorld()).getWorldConfig().imageLoader;
if(loader != null && loader.getAlign().equals(ImageLoader.Align.NONE)) { if(loader != null && loader.getAlign().equals(ImageLoader.Align.NONE)) {
xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth()); xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight()); zp = (int) (((double) Math.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight());
} }
String str = BiomeConfig.fromBiome((UserDefinedBiome) TerraBiomeGrid.fromWorld(p.getWorld()).getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID(); String str = TerraWorld.getWorld(p.getWorld()).getConfig().getBiome((UserDefinedBiome) TerraWorld.getWorld(p.getWorld()).getGrid().getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
g.setColor(new Color(255, 255, 255, 128)); g.setColor(new Color(255, 255, 255, 128));
g.fillRect(xp + 13, zp - 13, (int) (8 + 8.25 * str.length()), 33); g.fillRect(xp + 13, zp - 13, (int) (8 + 8.25 * str.length()), 33);
g.setColor(Color.BLACK); g.setColor(Color.BLACK);

View File

@ -1,8 +1,10 @@
package com.dfsek.terra.image; package com.dfsek.terra.image;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.BiomeZone; import com.dfsek.terra.biome.BiomeZone;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.WorldConfig;
import org.bukkit.World; import org.bukkit.World;
import org.polydev.gaea.biome.NormalizationUtil; import org.polydev.gaea.biome.NormalizationUtil;
@ -45,8 +47,8 @@ public class ImageLoader {
} }
private static BufferedImage redrawStepped(BufferedImage original, World w, Align align) { private static BufferedImage redrawStepped(BufferedImage original, World w, Align align) {
BufferedImage newImg = copyImage(original); BufferedImage newImg = copyImage(original);
TerraBiomeGrid tb = TerraBiomeGrid.fromWorld(w); TerraBiomeGrid tb = TerraWorld.getWorld(w).getGrid();
BiomeZone z = BiomeZone.fromWorld(w); BiomeZone z = TerraWorld.getWorld(w).getZone();
for(int x = 0; x < newImg.getWidth(); x++) { for(int x = 0; x < newImg.getWidth(); x++) {
for(int y = 0; y < newImg.getHeight(); y++) { for(int y = 0; y < newImg.getHeight(); y++) {
float[] noise; float[] noise;

View File

@ -1,7 +1,9 @@
package com.dfsek.terra.image; package com.dfsek.terra.image;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.BiomeZone; import com.dfsek.terra.biome.BiomeZone;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.config.base.WorldConfig;
import org.bukkit.World; import org.bukkit.World;
import org.polydev.gaea.biome.NormalizationUtil; import org.polydev.gaea.biome.NormalizationUtil;
@ -19,12 +21,13 @@ public class WorldImageGenerator {
this.w = w; this.w = w;
} }
public WorldImageGenerator drawWorld(int centerX, int centerZ) { public WorldImageGenerator drawWorld(int centerX, int centerZ) {
TerraBiomeGrid tb = TerraBiomeGrid.fromWorld(w); TerraWorld tw = TerraWorld.getWorld(w);
TerraBiomeGrid tb = tw.getGrid();
int imY = 0; int imY = 0;
for(int y = centerZ - (draw.getHeight()/2); y < centerZ + (draw.getHeight()/2); y++) { for(int y = centerZ - (draw.getHeight()/2); y < centerZ + (draw.getHeight()/2); y++) {
int imX = 0; int imX = 0;
for(int x = centerX - (draw.getWidth()/2); x < centerX + (draw.getWidth()/2); x++) { for(int x = centerX - (draw.getWidth()/2); x < centerX + (draw.getWidth()/2); x++) {
int zone = NormalizationUtil.normalize(BiomeZone.fromWorld(w).getRawNoise(x, y), 256); int zone = NormalizationUtil.normalize(tw.getZone().getRawNoise(x, y), 256);
float[] noise = tb.getGrid(x, y).getRawNoise(x, y); float[] noise = tb.getGrid(x, y).getRawNoise(x, y);
Color c = new Color(NormalizationUtil.normalize(noise[0], 256), NormalizationUtil.normalize(noise[1], 256), zone); Color c = new Color(NormalizationUtil.normalize(noise[0], 256), NormalizationUtil.normalize(noise[1], 256), zone);
draw.setRGB(imX, imY, c.getRGB()); draw.setRGB(imX, imY, c.getRGB());

View File

@ -1,7 +1,10 @@
package com.dfsek.terra.population; package com.dfsek.terra.population;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.CarverConfig; import com.dfsek.terra.config.genconfig.CarverConfig;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
@ -28,7 +31,8 @@ public class CavePopulator extends BlockPopulator {
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
if(ConfigUtil.masterDisableCaves) return; if(ConfigUtil.masterDisableCaves) return;
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("CaveTime")) { try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("CaveTime")) {
for(CarverConfig c : CarverConfig.getCarvers()) { TerraConfig config = TerraWorld.getWorld(world).getConfig();
for(CarverConfig c : config.getCarvers().values()) {
Map<Location, Material> shiftCandidate = new HashMap<>(); Map<Location, Material> shiftCandidate = new HashMap<>();
Set<Block> updateNeeded = new HashSet<>(); Set<Block> updateNeeded = new HashSet<>();
Map<Vector, CarvingData.CarvingType> blocks = c.getCarver().carve(chunk.getX(), chunk.getZ(), world).getCarvedBlocks(); Map<Vector, CarvingData.CarvingType> blocks = c.getCarver().carve(chunk.getX(), chunk.getZ(), world).getCarvedBlocks();

View File

@ -1,8 +1,11 @@
package com.dfsek.terra.population; package com.dfsek.terra.population;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -26,12 +29,15 @@ public class FloraPopulator extends GaeaBlockPopulator {
@Override @Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try (ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) { try (ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
TerraWorld tw = TerraWorld.getWorld(world);
TerraBiomeGrid grid = tw.getGrid();
TerraConfig config = tw.getConfig();
for(int x = 0; x < 16; x++) { for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) { for(int z = 0; z < 16; z++) {
UserDefinedBiome biome = (UserDefinedBiome) TerraBiomeGrid.fromWorld(world).getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE); UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE);
if(biome.getDecorator().getFloraChance() <= 0) continue; if(biome.getDecorator().getFloraChance() <= 0) continue;
try { try {
BiomeConfig c = BiomeConfig.fromBiome(biome); BiomeConfig c = config.getBiome(biome);
for(int i = 0; i < c.getFloraAttempts(); i++) { for(int i = 0; i < c.getFloraAttempts(); i++) {
Flora item; Flora item;
if(c.isFloraSimplex()) item = biome.getDecorator().getFlora().get(c.getFloraNoise(), (chunk.getX() << 4) + x, (chunk.getZ() << 4) + z); if(c.isFloraSimplex()) item = biome.getDecorator().getFlora().get(c.getFloraNoise(), (chunk.getX() << 4) + x, (chunk.getZ() << 4) + z);

View File

@ -1,5 +1,8 @@
package com.dfsek.terra.population; package com.dfsek.terra.population;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.WorldConfig;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
@ -22,13 +25,14 @@ public class OrePopulator extends GaeaBlockPopulator {
@Override @Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try (ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) { try (ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) {
Biome b = TerraBiomeGrid.fromWorld(world).getBiome((chunk.getX() << 4)+8, (chunk.getZ() << 4) + 8, GenerationPhase.POPULATE); TerraConfig config = TerraWorld.getWorld(world).getConfig();
for(Map.Entry<OreConfig, Range> e : BiomeConfig.fromBiome((UserDefinedBiome) b).getOres().entrySet()) { Biome b = TerraWorld.getWorld(world).getGrid().getBiome((chunk.getX() << 4)+8, (chunk.getZ() << 4) + 8, GenerationPhase.POPULATE);
for(Map.Entry<OreConfig, Range> e : config.getBiome((UserDefinedBiome) b).getOres().entrySet()) {
int num = e.getValue().get(random); int num = e.getValue().get(random);
for(int i = 0; i < num; i++) { for(int i = 0; i < num; i++) {
int x = random.nextInt(16); int x = random.nextInt(16);
int z = random.nextInt(16); int z = random.nextInt(16);
int y = BiomeConfig.fromBiome((UserDefinedBiome) b).getOreHeight(e.getKey()).get(random); int y = config.getBiome((UserDefinedBiome) b).getOreHeight(e.getKey()).get(random);
e.getKey().doVein(chunk.getBlock(x, y, z).getLocation(), random); e.getKey().doVein(chunk.getBlock(x, y, z).getLocation(), random);
} }
} }

View File

@ -1,8 +1,11 @@
package com.dfsek.terra.population; package com.dfsek.terra.population;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.config.genconfig.StructureConfig; import com.dfsek.terra.config.genconfig.StructureConfig;
import com.dfsek.terra.structure.GaeaStructure; import com.dfsek.terra.structure.GaeaStructure;
@ -26,8 +29,11 @@ public class StructurePopulator extends BlockPopulator {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("StructureTime")) { try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("StructureTime")) {
int cx = (chunk.getX() << 4); int cx = (chunk.getX() << 4);
int cz = (chunk.getZ() << 4); int cz = (chunk.getZ() << 4);
UserDefinedBiome b = (UserDefinedBiome) TerraBiomeGrid.fromWorld(world).getBiome(cx+ 8, cz + 8, GenerationPhase.POPULATE); TerraWorld tw = TerraWorld.getWorld(world);
structure: for(StructureConfig conf : BiomeConfig.fromBiome(b).getStructures()) { TerraBiomeGrid grid = tw.getGrid();
TerraConfig config = tw.getConfig();
UserDefinedBiome b = (UserDefinedBiome) grid.getBiome(cx+ 8, cz + 8, GenerationPhase.POPULATE);
structure: for(StructureConfig conf : config.getBiome(b).getStructures()) {
GaeaStructure struc = conf.getStructure(); GaeaStructure struc = conf.getStructure();
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world); Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
Random r2 = new Random(spawn.hashCode()); Random r2 = new Random(spawn.hashCode());
@ -36,7 +42,7 @@ public class StructurePopulator extends BlockPopulator {
spawn.setY(y); spawn.setY(y);
for(StructureSpawnRequirement s : struc.getSpawns()) { for(StructureSpawnRequirement s : struc.getSpawns()) {
if(! s.isValidSpawn(spawn)) continue main; if(! s.isValidSpawn(spawn)) continue main;
if(!b.equals(TerraBiomeGrid.fromWorld(world).getBiome(spawn.clone().add(s.getX(), s.getY(), s.getZ()), GenerationPhase.POPULATE))) { if(!b.equals(grid.getBiome(spawn.clone().add(s.getX(), s.getY(), s.getZ()), GenerationPhase.POPULATE))) {
Bukkit.getLogger().info("PREVENTED invalid spawn at " + spawn); Bukkit.getLogger().info("PREVENTED invalid spawn at " + spawn);
continue structure; continue structure;
} }

View File

@ -2,7 +2,9 @@ package com.dfsek.terra.population;
import com.dfsek.terra.Terra; import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.generation.UserDefinedDecorator; import com.dfsek.terra.generation.UserDefinedDecorator;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
@ -20,10 +22,12 @@ public class TreePopulator extends GaeaBlockPopulator {
@Override @Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("TreeGenTime")) { try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("TreeGenTime")) {
TerraWorld tw = TerraWorld.getWorld(world);
TerraBiomeGrid grid = tw.getGrid();;
int x = random.nextInt(16); // Decrease chances of chunk-crossing trees int x = random.nextInt(16); // Decrease chances of chunk-crossing trees
int z = random.nextInt(16); int z = random.nextInt(16);
Location origin = chunk.getBlock(x, 0, z).getLocation(); Location origin = chunk.getBlock(x, 0, z).getLocation();
Biome b = TerraBiomeGrid.fromWorld(world).getBiome(origin, GenerationPhase.POPULATE); Biome b = grid.getBiome(origin, GenerationPhase.POPULATE);
if(((UserDefinedDecorator) b.getDecorator()).getTreeChance() < random.nextInt(100)) return; if(((UserDefinedDecorator) b.getDecorator()).getTreeChance() < random.nextInt(100)) return;
int max = 50; int max = 50;
int att = 0; int att = 0;
@ -32,7 +36,7 @@ public class TreePopulator extends GaeaBlockPopulator {
int y = WorldUtil.getHighestValidSpawnAt(chunk, x, z); int y = WorldUtil.getHighestValidSpawnAt(chunk, x, z);
if(y <= 0) continue; if(y <= 0) continue;
origin = chunk.getBlock(x, y, z).getLocation().add(0, 1, 0); origin = chunk.getBlock(x, y, z).getLocation().add(0, 1, 0);
b = TerraBiomeGrid.fromWorld(world).getBiome(origin, GenerationPhase.POPULATE); b = grid.getBiome(origin, GenerationPhase.POPULATE);
try { try {
if(b.getDecorator().getTrees().get(random).plant(origin, random, false, Terra.getInstance())) i++; if(b.getDecorator().getTrees().get(random).plant(origin, random, false, Terra.getInstance())) i++;
} catch(NullPointerException ignore) {} } catch(NullPointerException ignore) {}

View File

@ -1,7 +1,9 @@
package com.dfsek.terra.structure; package com.dfsek.terra.structure;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -50,21 +52,23 @@ public class StructureSpawnRequirement implements Serializable {
AIR { AIR {
@Override @Override
public boolean matches(World w, int x, int y, int z) { public boolean matches(World w, int x, int y, int z) {
UserDefinedBiome b = (UserDefinedBiome) TerraBiomeGrid.fromWorld(w).getBiome(x, z, GenerationPhase.POPULATE); UserDefinedBiome b = (UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(x, z, GenerationPhase.POPULATE);
if(y <= BiomeConfig.fromBiome(b).getSeaLevel()) return false; BiomeConfig c = TerraWorld.getWorld(w).getConfig().getBiome(b);
if(y <= c.getSeaLevel()) return false;
return b.getGenerator().getNoise(getNoise(w), w, x, y, z) <= 0; return b.getGenerator().getNoise(getNoise(w), w, x, y, z) <= 0;
} }
}, OCEAN { }, OCEAN {
@Override @Override
public boolean matches(World w, int x, int y, int z) { public boolean matches(World w, int x, int y, int z) {
UserDefinedBiome b = (UserDefinedBiome) TerraBiomeGrid.fromWorld(w).getBiome(x, z, GenerationPhase.POPULATE); UserDefinedBiome b = (UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(x, z, GenerationPhase.POPULATE);
if(y > BiomeConfig.fromBiome(b).getSeaLevel()) return false; BiomeConfig c = TerraWorld.getWorld(w).getConfig().getBiome(b);
if(y > c.getSeaLevel()) return false;
return b.getGenerator().getNoise(getNoise(w), w, x, y, z) <= 0; return b.getGenerator().getNoise(getNoise(w), w, x, y, z) <= 0;
} }
}, LAND { }, LAND {
@Override @Override
public boolean matches(World w, int x, int y, int z) { public boolean matches(World w, int x, int y, int z) {
UserDefinedBiome b = (UserDefinedBiome) TerraBiomeGrid.fromWorld(w).getBiome(x, z, GenerationPhase.POPULATE); UserDefinedBiome b = (UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(x, z, GenerationPhase.POPULATE);
return b.getGenerator().getNoise(getNoise(w), w, x, y, z) > 0; return b.getGenerator().getNoise(getNoise(w), w, x, y, z) > 0;
} }
}; };