mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 18:42:30 +00:00
Completely redo config
This commit is contained in:
parent
a5c85a7e5d
commit
6f11222a88
73
src/main/java/com/dfsek/terra/TerraWorld.java
Normal file
73
src/main/java/com/dfsek/terra/TerraWorld.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -1,5 +1,8 @@
|
||||
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 com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
@ -44,7 +47,8 @@ public class UserDefinedCarver extends Carver {
|
||||
|
||||
@Override
|
||||
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 {
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.command.type.PlayerCommand;
|
||||
import com.dfsek.terra.config.genconfig.BiomeConfig;
|
||||
import com.dfsek.terra.command.type.WorldCommand;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -12,16 +14,12 @@ import org.polydev.gaea.generation.GenerationPhase;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BiomeCommand extends PlayerCommand {
|
||||
public class BiomeCommand extends WorldCommand {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
TerraBiomeGrid grid = TerraBiomeGrid.fromWorld(sender.getWorld());
|
||||
if(grid == null) {
|
||||
sender.sendMessage("Not a Terra world!");
|
||||
return true;
|
||||
}
|
||||
public boolean onCommand(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
|
||||
TerraBiomeGrid grid = TerraWorld.getWorld(sender.getWorld()).getGrid();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
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 org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,12 +15,12 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class OreCommand extends PlayerCommand {
|
||||
public class OreCommand extends WorldCommand {
|
||||
@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);
|
||||
if(args.length > 0) {
|
||||
OreConfig ore = OreConfig.fromID(args[0]);
|
||||
OreConfig ore = TerraWorld.getWorld(w).getConfig().getOre(args[0]);
|
||||
if(ore == null) {
|
||||
sender.sendMessage("Unable to find Ore");
|
||||
return true;
|
||||
|
@ -45,8 +45,8 @@ public class TerraCommand implements CommandExecutor, TabExecutor {
|
||||
}
|
||||
@Override
|
||||
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 return Collections.emptyList();
|
||||
else*/ return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.command.type.WorldCommand;
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
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!");
|
||||
return true;
|
||||
}
|
||||
ImageLoader loader = WorldConfig.fromWorld(world).imageLoader;
|
||||
ImageLoader loader = TerraWorld.getWorld(world).getWorldConfig().imageLoader;
|
||||
if(loader != null) loader.debug(false, sender.getWorld());
|
||||
else ImageLoader.debugWorld(false, world);
|
||||
return true;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.command.type.WorldCommand;
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
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!");
|
||||
return true;
|
||||
}
|
||||
ImageLoader loader = WorldConfig.fromWorld(world).imageLoader;
|
||||
ImageLoader loader = TerraWorld.getWorld(world).getWorldConfig().imageLoader;
|
||||
if(loader != null) loader.debug(true, sender.getWorld());
|
||||
else ImageLoader.debugWorld(true, world);
|
||||
return true;
|
||||
|
@ -12,28 +12,26 @@ import java.lang.reflect.InvocationTargetException;
|
||||
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.Stream;
|
||||
|
||||
public class ConfigLoader {
|
||||
private final String path;
|
||||
public ConfigLoader(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
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();
|
||||
public static <T extends TerraConfigObject> Map<String, T> load(JavaPlugin main, Path file, TerraConfig config, Class<T> clazz) {
|
||||
Map<String, T> configs = new HashMap<>();
|
||||
file.toFile().mkdirs();
|
||||
List<String> ids = new ArrayList<>();
|
||||
try (Stream<Path> paths = Files.walk(folder.toPath())) {
|
||||
try (Stream<Path> paths = Files.walk(file)) {
|
||||
paths
|
||||
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
|
||||
.forEach(path -> {
|
||||
try {
|
||||
Constructor<T> c = clazz.getConstructor(File.class);
|
||||
T o = c.newInstance(path.toFile());
|
||||
Constructor<T> c = clazz.getConstructor(File.class, TerraConfig.class);
|
||||
T o = c.newInstance(path.toFile(), config);
|
||||
if(ids.contains(o.getID())) Bukkit.getLogger().severe("Duplicate ID found in file: " + path.toString());
|
||||
ids.add(o.getID());
|
||||
configs.put(o.getID(), o);
|
||||
main.getLogger().info("Loaded " + o.toString() + " from file " + path.toString());
|
||||
} catch(IllegalAccessException | InstantiationException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
@ -47,5 +45,6 @@ public class ConfigLoader {
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return configs;
|
||||
}
|
||||
}
|
||||
|
228
src/main/java/com/dfsek/terra/config/TerraConfig.java
Normal file
228
src/main/java/com/dfsek/terra/config/TerraConfig.java
Normal 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);
|
||||
}
|
||||
}
|
@ -7,10 +7,15 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class TerraConfigObject extends YamlConfiguration {
|
||||
public TerraConfigObject(File file) throws IOException, InvalidConfigurationException {
|
||||
super.load(file);
|
||||
init();
|
||||
private final TerraConfig config;
|
||||
public TerraConfigObject(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
|
||||
load(file);
|
||||
this.config = config;
|
||||
}
|
||||
public abstract void init() throws InvalidConfigurationException;
|
||||
|
||||
public TerraConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public abstract String getID();
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.dfsek.terra.config.base;
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.ConfigLoader;
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
import com.dfsek.terra.config.genconfig.AbstractBiomeConfig;
|
||||
import com.dfsek.terra.config.genconfig.BiomeConfig;
|
||||
@ -27,7 +28,7 @@ import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ConfigUtil {
|
||||
public final class ConfigUtil {
|
||||
public static boolean debug;
|
||||
public static long dataSave; // Period of population data saving, in ticks.
|
||||
public static boolean masterDisableCaves;
|
||||
@ -42,25 +43,7 @@ public class ConfigUtil {
|
||||
Logger logger = main.getLogger();
|
||||
logger.info("Loading config values");
|
||||
|
||||
new ConfigLoader("ores").load(main, OreConfig.class);
|
||||
|
||||
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();
|
||||
TerraConfig.loadAll(main);
|
||||
}
|
||||
|
||||
public static <E extends Enum<E>> List<E> getElements(List<String> st, Class<E> clazz) {
|
||||
|
4
src/main/java/com/dfsek/terra/config/base/LangUtil.java
Normal file
4
src/main/java/com/dfsek/terra/config/base/LangUtil.java
Normal file
@ -0,0 +1,4 @@
|
||||
package com.dfsek.terra.config.base;
|
||||
|
||||
public final class LangUtil {
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package com.dfsek.terra.config.base;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
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.genconfig.BiomeConfig;
|
||||
import com.dfsek.terra.config.genconfig.BiomeGridConfig;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
@ -22,41 +24,21 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
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 UserDefinedGrid[] definedGrids;
|
||||
public TerraConfig config;
|
||||
public ImageLoader.Channel biomeXChannel;
|
||||
public ImageLoader.Channel biomeZChannel;
|
||||
public ImageLoader.Channel zoneChannel;
|
||||
public boolean biomeBlend;
|
||||
|
||||
public ImageLoader imageLoader;
|
||||
public int blendAmp;
|
||||
public float blendFreq;
|
||||
public boolean perturbPaletteOnly;
|
||||
|
||||
|
||||
private TerraConfig tConfig;
|
||||
|
||||
|
||||
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();
|
||||
main.getLogger().info("Loading world configuration values for " + w + "...");
|
||||
FileConfiguration config = new YamlConfiguration();
|
||||
@ -71,16 +53,10 @@ public class WorldConfig {
|
||||
|
||||
|
||||
// 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);
|
||||
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
|
||||
try {
|
||||
@ -103,29 +79,7 @@ public class WorldConfig {
|
||||
} catch(IllegalArgumentException e) {
|
||||
throw new InvalidConfigurationException(e.getCause());
|
||||
}
|
||||
|
||||
|
||||
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.");
|
||||
Bukkit.getLogger().info("Loaded " + tConfig.biomeList.size() + " BiomeGrids from list.");
|
||||
|
||||
} catch(IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
@ -134,4 +88,8 @@ public class WorldConfig {
|
||||
|
||||
main.getLogger().info("World load complete. Time elapsed: " + ((double) (System.nanoTime() - start)) / 1000000 + "ms");
|
||||
}
|
||||
|
||||
public TerraConfig getConfig() {
|
||||
return tConfig;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
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.exception.ConfigException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@ -9,28 +10,26 @@ import org.polydev.gaea.world.palette.Palette;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AbstractBiomeConfig extends TerraConfigObject {
|
||||
private static final Map<String, AbstractBiomeConfig> biomes = new HashMap<>();
|
||||
private String biomeID;
|
||||
private int floraChance;
|
||||
private int treeChance;
|
||||
private int treeDensity;
|
||||
private String equation;
|
||||
private int floraAttempts;
|
||||
private final String biomeID;
|
||||
private final int floraChance;
|
||||
private final int treeChance;
|
||||
private final int treeDensity;
|
||||
private final String equation;
|
||||
private final int floraAttempts;
|
||||
private double slabThreshold;
|
||||
private Map<Material, Palette<BlockData>> slabs;
|
||||
private Map<Material, Palette<BlockData>> stairs;
|
||||
private boolean useStairs;
|
||||
private boolean floraSimplex;
|
||||
private int floraSeed;
|
||||
private float floraFreq;
|
||||
private String oceanPalette;
|
||||
private int seaLevel;
|
||||
private final boolean floraSimplex;
|
||||
private final int floraSeed;
|
||||
private final float floraFreq;
|
||||
private final String oceanPalette;
|
||||
private final int seaLevel;
|
||||
private List<Map<?, ?>> paletteData;
|
||||
private Map<String, Object> floraData;
|
||||
private Map<String, Object> oreData;
|
||||
@ -38,12 +37,9 @@ public class AbstractBiomeConfig extends TerraConfigObject {
|
||||
private List<Map<?, ?>> carvingData;
|
||||
private List<String> structureConfigs;
|
||||
|
||||
public AbstractBiomeConfig(File file) throws IOException, InvalidConfigurationException {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws InvalidConfigurationException {
|
||||
public AbstractBiomeConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
load(file);
|
||||
if(!contains("id")) throw new ConfigException("Abstract Biome ID unspecified!", "null");
|
||||
this.biomeID = getString("id");
|
||||
|
||||
@ -80,8 +76,6 @@ public class AbstractBiomeConfig extends TerraConfigObject {
|
||||
}
|
||||
|
||||
if(contains("structures")) structureConfigs = getStringList("structures");
|
||||
|
||||
biomes.put(biomeID, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -109,10 +103,6 @@ public class AbstractBiomeConfig extends TerraConfigObject {
|
||||
return equation;
|
||||
}
|
||||
|
||||
public static AbstractBiomeConfig fromID(String id) {
|
||||
return biomes.get(id);
|
||||
}
|
||||
|
||||
public Map<Material, Palette<BlockData>> getSlabs() {
|
||||
return slabs;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
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.NotFoundException;
|
||||
import org.polydev.gaea.math.Range;
|
||||
@ -39,13 +40,12 @@ import java.util.Random;
|
||||
import java.util.TreeMap;
|
||||
|
||||
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 UserDefinedBiome biome;
|
||||
private String biomeID;
|
||||
private final UserDefinedBiome biome;
|
||||
private final String biomeID;
|
||||
private Map<OreConfig, Range> ores;
|
||||
private Map<OreConfig, Range> oreHeights;
|
||||
private Map<CarverConfig, Integer> carvers;
|
||||
private final Map<CarverConfig, Integer> carvers;
|
||||
private Map<Flora, Range> floraHeights;
|
||||
private String eq;
|
||||
private int floraAttempts;
|
||||
@ -54,17 +54,16 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
private double slabThreshold;
|
||||
private boolean floraSimplex;
|
||||
private FastNoise floraNoise;
|
||||
private Palette<BlockData> ocean;
|
||||
private final Palette<BlockData> ocean;
|
||||
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")
|
||||
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");
|
||||
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.
|
||||
if(contains("extends")) {
|
||||
try {
|
||||
abstractBiome = AbstractBiomeConfig.fromID(getString("extends"));
|
||||
abstractBiome = config.getAbstractBiomes().get(getString("extends"));
|
||||
extending = true;
|
||||
Bukkit.getLogger().info("Extending biome " + getString("extends"));
|
||||
} catch(NullPointerException e) {
|
||||
@ -107,7 +106,7 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
}
|
||||
else {
|
||||
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) {
|
||||
throw new NotFoundException("Palette", (String) entry.getKey(), getID());
|
||||
}
|
||||
@ -135,7 +134,7 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
for(Map<?, ?> e : carvingData) {
|
||||
for(Map.Entry<?, ?> entry : e.entrySet()) {
|
||||
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());
|
||||
carvers.put(c, (Integer) entry.getValue());
|
||||
} catch(ClassCastException ex) {
|
||||
@ -207,7 +206,7 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
} catch(IllegalArgumentException ex) {
|
||||
try {
|
||||
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"));
|
||||
floraHeights.put(floraCustom, new Range((Integer) y.get("min"), (Integer) y.get("max")));
|
||||
} catch(NullPointerException ex2) {
|
||||
@ -271,8 +270,8 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
}
|
||||
if(oreData != null) {
|
||||
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")));
|
||||
oreHeights.put(OreConfig.fromID(m.getKey()), new Range(((ConfigurationSection) m.getValue()).getInt("min-height"), ((ConfigurationSection) m.getValue()).getInt("max-height")));
|
||||
ores.put(config.getOre(m.getKey()), new Range(((ConfigurationSection) m.getValue()).getInt("min"), ((ConfigurationSection) m.getValue()).getInt("max")));
|
||||
oreHeights.put(config.getOre(m.getKey()), new Range(((ConfigurationSection) m.getValue()).getInt("min-height"), ((ConfigurationSection) m.getValue()).getInt("max-height")));
|
||||
}
|
||||
} else {
|
||||
ores = new HashMap<>();
|
||||
@ -295,7 +294,7 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
ocean = PaletteConfig.fromID(oceanPalette).getPalette();
|
||||
ocean = config.getPalette(oceanPalette).getPalette();
|
||||
} catch(NullPointerException ex) {
|
||||
throw new NotFoundException("Palette", oceanPalette, getID());
|
||||
}
|
||||
@ -342,7 +341,7 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
if(contains("structures")) st = getStringList("structures");
|
||||
for(String s : st) {
|
||||
try {
|
||||
structures.add(Objects.requireNonNull(StructureConfig.fromID(s)));
|
||||
structures.add(Objects.requireNonNull(config.getStructure(s)));
|
||||
} catch(NullPointerException e) {
|
||||
throw new NotFoundException("Structure", s, getID());
|
||||
}
|
||||
@ -355,7 +354,6 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
e.printStackTrace();
|
||||
throw new ConfigException("Unable to parse noise equation!", getID());
|
||||
}
|
||||
biomes.put(biomeID, this);
|
||||
}
|
||||
|
||||
public Range getOreHeight(OreConfig c) {
|
||||
@ -382,31 +380,13 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
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
|
||||
public String toString() {
|
||||
return "Biome with ID " + getID() + " and noise equation " + eq;
|
||||
}
|
||||
|
||||
public int getCarverChance(UserDefinedCarver c) {
|
||||
return carvers.getOrDefault(CarverConfig.fromDefinedCarver(c), 0);
|
||||
return carvers.getOrDefault(config.getCarver(c), 0);
|
||||
}
|
||||
|
||||
public double getSlabThreshold() {
|
||||
|
@ -32,7 +32,7 @@ public class BiomeConfigUtil {
|
||||
}
|
||||
} else {
|
||||
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");
|
||||
paletteMap.put(Bukkit.createBlockData((String) entry.getKey()).getMaterial(), p);
|
||||
} catch(NullPointerException ex) {
|
||||
|
@ -2,6 +2,7 @@ package com.dfsek.terra.config.genconfig;
|
||||
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.UserDefinedGrid;
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.TerraConfigObject;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
@ -17,32 +18,26 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BiomeGridConfig extends TerraConfigObject {
|
||||
private static final Map<String, BiomeGridConfig> biomeGrids = new HashMap<>();
|
||||
private String gridID;
|
||||
private boolean isEnabled = false;
|
||||
private UserDefinedBiome[][] gridRaw;
|
||||
private int sizeX;
|
||||
private int sizeZ;
|
||||
private final String gridID;
|
||||
private final UserDefinedBiome[][] gridRaw;
|
||||
private final int sizeX;
|
||||
private final int sizeZ;
|
||||
|
||||
public BiomeGridConfig(File file) throws IOException, InvalidConfigurationException {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void init() throws InvalidConfigurationException {
|
||||
isEnabled = false;
|
||||
public BiomeGridConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
load(file);
|
||||
if(!contains("id")) throw new ConfigException("Grid ID unspecified!", "null");
|
||||
this.gridID = getString("id");
|
||||
if(!contains("grid")) throw new ConfigException("Grid key not found!", getID());
|
||||
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];
|
||||
try {
|
||||
for(int x = 0; x < sizeX; x++) {
|
||||
for(int z = 0; z < sizeZ; z++) {
|
||||
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) {
|
||||
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) {
|
||||
throw new ConfigException("Malformed grid! Ensure all dimensions are correct.", getID());
|
||||
}
|
||||
isEnabled = true;
|
||||
biomeGrids.put(gridID, this);
|
||||
}
|
||||
|
||||
public int getSizeX() {
|
||||
@ -67,25 +60,18 @@ public class BiomeGridConfig extends TerraConfigObject {
|
||||
return gridRaw;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return gridID;
|
||||
}
|
||||
|
||||
public UserDefinedGrid getGrid(World w) {
|
||||
WorldConfig c = WorldConfig.fromWorld(w);
|
||||
return new UserDefinedGrid(w, c.freq1, c.freq2, gridRaw);
|
||||
public UserDefinedGrid getGrid(World w, WorldConfig wc) {
|
||||
TerraConfig c = wc.getConfig();
|
||||
return new UserDefinedGrid(w, c.freq1, c.freq2, gridRaw, wc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BiomeGrid with ID " + getID() + ", dimensions " + getSizeX() + ":" + getSizeZ();
|
||||
}
|
||||
|
||||
public static Map<String, BiomeGridConfig> getBiomeGrids() {
|
||||
return biomeGrids;
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +1,49 @@
|
||||
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.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.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class CarverConfig extends TerraConfigObject {
|
||||
private static final Map<String, CarverConfig> caveConfig = new HashMap<>();
|
||||
private UserDefinedCarver carver;
|
||||
private String id;
|
||||
private Set<Material> replaceableInner;
|
||||
private Set<Material> replaceableOuter;
|
||||
private Set<Material> replaceableTop;
|
||||
private Set<Material> replaceableBottom;
|
||||
private Set<Material> update;
|
||||
private Map<Material, Set<Material>> shift;
|
||||
private Map<Integer, ProbabilityCollection<BlockData>> inner;
|
||||
private Map<Integer, ProbabilityCollection<BlockData>> outer;
|
||||
private Map<Integer, ProbabilityCollection<BlockData>> top;
|
||||
private Map<Integer, ProbabilityCollection<BlockData>> bottom;
|
||||
private boolean replaceIsBlacklistInner;
|
||||
private boolean replaceIsBlacklistOuter;
|
||||
private boolean replaceIsBlacklistTop;
|
||||
private boolean replaceIsBlacklistBottom;
|
||||
private final UserDefinedCarver carver;
|
||||
private final String id;
|
||||
private final Set<Material> replaceableInner;
|
||||
private final Set<Material> replaceableOuter;
|
||||
private final Set<Material> replaceableTop;
|
||||
private final Set<Material> replaceableBottom;
|
||||
private final Set<Material> update;
|
||||
private final Map<Material, Set<Material>> shift;
|
||||
private final Map<Integer, ProbabilityCollection<BlockData>> inner;
|
||||
private final Map<Integer, ProbabilityCollection<BlockData>> outer;
|
||||
private final Map<Integer, ProbabilityCollection<BlockData>> top;
|
||||
private final Map<Integer, ProbabilityCollection<BlockData>> bottom;
|
||||
private final boolean replaceIsBlacklistInner;
|
||||
private final boolean replaceIsBlacklistOuter;
|
||||
private final boolean replaceIsBlacklistTop;
|
||||
private final boolean replaceIsBlacklistBottom;
|
||||
|
||||
public CarverConfig(File file) throws IOException, InvalidConfigurationException {
|
||||
super(file);
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public UserDefinedCarver getCarver() {
|
||||
return carver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws InvalidConfigurationException {
|
||||
@SuppressWarnings("unchecked")
|
||||
public CarverConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
load(file);
|
||||
if(!contains("id")) throw new ConfigException("No ID specified for Carver!", "null");
|
||||
id = getString("id");
|
||||
|
||||
@ -76,7 +66,7 @@ public class CarverConfig extends TerraConfigObject {
|
||||
update = ConfigUtil.toBlockData(getStringList("update"), "update", getID());
|
||||
|
||||
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<>();
|
||||
for(String s : (List<String>) e.getValue()) {
|
||||
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"));
|
||||
|
||||
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 {
|
||||
if(!contains(key)) throw new ConfigException("Missing Carver Palette!", getID());
|
||||
Map<Integer, ProbabilityCollection<BlockData>> result = new TreeMap<>();
|
||||
@ -189,18 +187,4 @@ public class CarverConfig extends TerraConfigObject {
|
||||
public String toString() {
|
||||
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!");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.genconfig;
|
||||
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.TerraConfigObject;
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
@ -26,19 +27,15 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class FloraConfig extends TerraConfigObject implements Flora {
|
||||
private static final Map<String, FloraConfig> floraConfig = new HashMap<>();
|
||||
private Palette<BlockData> floraPalette;
|
||||
private String id;
|
||||
private final Palette<BlockData> floraPalette;
|
||||
private final String id;
|
||||
|
||||
Set<Material> spawnable;
|
||||
Set<Material> replaceable;
|
||||
|
||||
public FloraConfig(File file) throws IOException, InvalidConfigurationException {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws InvalidConfigurationException {
|
||||
public FloraConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
load(file);
|
||||
if(!contains("id")) throw new ConfigException("Flora ID unspecified!", "null");
|
||||
this.id = getString("id");
|
||||
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)));
|
||||
|
||||
floraPalette = PaletteConfig.getPalette(getMapList("blocks"), p);
|
||||
|
||||
floraConfig.put(id, this);
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
@ -86,8 +81,4 @@ public class FloraConfig extends TerraConfigObject implements Flora {
|
||||
public String toString() {
|
||||
return "Flora with name ID " + getID();
|
||||
}
|
||||
|
||||
public static FloraConfig fromID(String id) {
|
||||
return floraConfig.get(id);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.genconfig;
|
||||
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import com.dfsek.terra.config.TerraConfigObject;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
@ -22,20 +23,15 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class OreConfig extends TerraConfigObject {
|
||||
private static final Map<String, OreConfig> ores = new HashMap<>();
|
||||
private BlockData oreData;
|
||||
private int min;
|
||||
private int max;
|
||||
private double deform;
|
||||
private double deformFrequency;
|
||||
private String id;
|
||||
private final BlockData oreData;
|
||||
private final int min;
|
||||
private final int max;
|
||||
private final double deform;
|
||||
private final double deformFrequency;
|
||||
private final String id;
|
||||
Set<Material> replaceable;
|
||||
public OreConfig(File file) throws IOException, InvalidConfigurationException {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws InvalidConfigurationException {
|
||||
public OreConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
if(!contains("id")) throw new ConfigException("Ore ID not found!", "null");
|
||||
this.id = getString("id");
|
||||
if(!contains("material")) throw new ConfigException("Ore material not found!", getID());
|
||||
@ -53,8 +49,8 @@ public class OreConfig extends TerraConfigObject {
|
||||
} catch(NullPointerException | IllegalArgumentException e) {
|
||||
throw new ConfigException("Invalid ore material: " + getString("material"), getID());
|
||||
}
|
||||
ores.put(id, this);
|
||||
}
|
||||
|
||||
private int randomInRange(Random r) {
|
||||
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
|
||||
public String toString() {
|
||||
return "Ore with ID " + getID();
|
||||
@ -87,8 +79,4 @@ public class OreConfig extends TerraConfigObject {
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static OreConfig fromID(String id) {
|
||||
return ores.get(id);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.genconfig;
|
||||
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.TerraConfigObject;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -13,22 +14,16 @@ import org.polydev.gaea.world.palette.SimplexPalette;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class PaletteConfig extends TerraConfigObject {
|
||||
private static final Map<String, PaletteConfig> palettes = new HashMap<>();
|
||||
private Palette<BlockData> palette;
|
||||
private String paletteID;
|
||||
private final Palette<BlockData> palette;
|
||||
private final String paletteID;
|
||||
private boolean useNoise = false;
|
||||
public PaletteConfig(File file) throws IOException, InvalidConfigurationException {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws InvalidConfigurationException {
|
||||
public PaletteConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
if(!contains("id")) throw new ConfigException("Palette ID unspecified!", "null");
|
||||
this.paletteID = getString("id");
|
||||
Palette<BlockData> pal;
|
||||
@ -41,7 +36,6 @@ public class PaletteConfig extends TerraConfigObject {
|
||||
pal = new SimplexPalette<>(pNoise);
|
||||
} else pal = new RandomPalette<>(new Random(getInt("seed", 3)));
|
||||
palette = getPalette(getMapList("blocks"), pal);
|
||||
palettes.put(paletteID, this);
|
||||
}
|
||||
|
||||
public Palette<BlockData> getPalette() {
|
||||
@ -84,8 +78,4 @@ public class PaletteConfig extends TerraConfigObject {
|
||||
public String toString() {
|
||||
return "Palette with ID " + getID() + " with " + getPalette().getSize() + " layers, using Simplex: " + useNoise;
|
||||
}
|
||||
|
||||
public static PaletteConfig fromID(String id) {
|
||||
return palettes.get(id);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
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.NotFoundException;
|
||||
import org.polydev.gaea.math.Range;
|
||||
@ -18,24 +19,19 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class StructureConfig extends TerraConfigObject {
|
||||
private static final Map<String, StructureConfig> configs = new HashMap<>();
|
||||
private GaeaStructure structure;
|
||||
private GridSpawn spawn;
|
||||
private String id;
|
||||
private Range searchStart;
|
||||
private Range bound;
|
||||
private final GaeaStructure structure;
|
||||
private final GridSpawn spawn;
|
||||
private final String id;
|
||||
private final Range searchStart;
|
||||
private final Range bound;
|
||||
StructurePopulator.SearchType type;
|
||||
public StructureConfig(File file) throws IOException, InvalidConfigurationException {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws InvalidConfigurationException {
|
||||
public StructureConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
if(!contains("id")) throw new ConfigException("No ID specified!", "null");
|
||||
id = getString("id");
|
||||
try {
|
||||
File file = new File(Terra.getInstance().getDataFolder() + File.separator + "config" + File.separator + "structures" + File.separator + "data", Objects.requireNonNull(getString("file")));
|
||||
structure = GaeaStructure.load(file);
|
||||
File structureFile = new File(config.getDataFolder() + File.separator + "structures" + File.separator + "data", Objects.requireNonNull(getString("file")));
|
||||
structure = GaeaStructure.load(structureFile);
|
||||
} catch(IOException | NullPointerException e) {
|
||||
if(ConfigUtil.debug) {
|
||||
e.printStackTrace();
|
||||
@ -51,7 +47,6 @@ public class StructureConfig extends TerraConfigObject {
|
||||
} catch(IllegalArgumentException e) {
|
||||
throw new ConfigException("Invalid search type, " + getString("spawn.search"), getID());
|
||||
}
|
||||
configs.put(id, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,8 +69,4 @@ public class StructureConfig extends TerraConfigObject {
|
||||
public Range getSearchStart() {
|
||||
return searchStart;
|
||||
}
|
||||
|
||||
public static StructureConfig fromID(String id) {
|
||||
return configs.get(id);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
package com.dfsek.terra.generation;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
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.population.CavePopulator;
|
||||
import com.dfsek.terra.population.FloraPopulator;
|
||||
@ -59,6 +62,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
if(needsLoad) load(world);
|
||||
StructureSpawnRequirement.putNoise(world, fastNoise); // Assign noise to world to be used for structures.
|
||||
ChunkData chunk = createChunkData(world);
|
||||
TerraConfig config = TerraWorld.getWorld(world).getConfig();
|
||||
int xOrig = (chunkX << 4);
|
||||
int zOrig = (chunkZ << 4);
|
||||
for(byte x = 0; x < 16; x++) {
|
||||
@ -67,7 +71,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
int cx = xOrig + x;
|
||||
int cz = zOrig + z;
|
||||
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();
|
||||
Palette<BlockData> seaPalette = c.getOceanPalette();
|
||||
for(int y = world.getMaxHeight()-1; y >= 0; y--) {
|
||||
@ -166,13 +170,13 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
|
||||
@Override
|
||||
public List<GenerationPopulator> getGenerationPopulators(World world) {
|
||||
return Collections.singletonList(new SlabGenerator());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public org.polydev.gaea.biome.BiomeGrid getBiomeGrid(World world) {
|
||||
return TerraBiomeGrid.fromWorld(world);
|
||||
return TerraWorld.getWorld(world).getGrid();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.image;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
@ -34,12 +35,12 @@ public class DebugFrame extends JFrame implements ActionListener {
|
||||
if(! (p.getWorld().getGenerator() instanceof TerraChunkGenerator)) break;
|
||||
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());
|
||||
ImageLoader loader = WorldConfig.fromWorld(p.getWorld()).imageLoader;
|
||||
ImageLoader loader = TerraWorld.getWorld(p.getWorld()).getWorldConfig().imageLoader;
|
||||
if(loader != null && loader.getAlign().equals(ImageLoader.Align.NONE)) {
|
||||
xp = (int) (((double) Math.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
|
||||
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.fillRect(xp + 13, zp - 13, (int) (8 + 8.25 * str.length()), 33);
|
||||
g.setColor(Color.BLACK);
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.dfsek.terra.image;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.NormalizationUtil;
|
||||
|
||||
@ -45,8 +47,8 @@ public class ImageLoader {
|
||||
}
|
||||
private static BufferedImage redrawStepped(BufferedImage original, World w, Align align) {
|
||||
BufferedImage newImg = copyImage(original);
|
||||
TerraBiomeGrid tb = TerraBiomeGrid.fromWorld(w);
|
||||
BiomeZone z = BiomeZone.fromWorld(w);
|
||||
TerraBiomeGrid tb = TerraWorld.getWorld(w).getGrid();
|
||||
BiomeZone z = TerraWorld.getWorld(w).getZone();
|
||||
for(int x = 0; x < newImg.getWidth(); x++) {
|
||||
for(int y = 0; y < newImg.getHeight(); y++) {
|
||||
float[] noise;
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.dfsek.terra.image;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.NormalizationUtil;
|
||||
|
||||
@ -19,12 +21,13 @@ public class WorldImageGenerator {
|
||||
this.w = w;
|
||||
}
|
||||
public WorldImageGenerator drawWorld(int centerX, int centerZ) {
|
||||
TerraBiomeGrid tb = TerraBiomeGrid.fromWorld(w);
|
||||
TerraWorld tw = TerraWorld.getWorld(w);
|
||||
TerraBiomeGrid tb = tw.getGrid();
|
||||
int imY = 0;
|
||||
for(int y = centerZ - (draw.getHeight()/2); y < centerZ + (draw.getHeight()/2); y++) {
|
||||
int imX = 0;
|
||||
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);
|
||||
Color c = new Color(NormalizationUtil.normalize(noise[0], 256), NormalizationUtil.normalize(noise[1], 256), zone);
|
||||
draw.setRGB(imX, imY, c.getRGB());
|
||||
|
@ -1,7 +1,10 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
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.WorldConfig;
|
||||
import com.dfsek.terra.config.genconfig.CarverConfig;
|
||||
import org.bukkit.Chunk;
|
||||
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) {
|
||||
if(ConfigUtil.masterDisableCaves) return;
|
||||
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<>();
|
||||
Set<Block> updateNeeded = new HashSet<>();
|
||||
Map<Vector, CarvingData.CarvingType> blocks = c.getCarver().carve(chunk.getX(), chunk.getZ(), world).getCarvedBlocks();
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
@ -26,12 +29,15 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
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 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;
|
||||
try {
|
||||
BiomeConfig c = BiomeConfig.fromBiome(biome);
|
||||
BiomeConfig c = config.getBiome(biome);
|
||||
for(int i = 0; i < c.getFloraAttempts(); i++) {
|
||||
Flora item;
|
||||
if(c.isFloraSimplex()) item = biome.getDecorator().getFlora().get(c.getFloraNoise(), (chunk.getX() << 4) + x, (chunk.getZ() << 4) + z);
|
||||
|
@ -1,5 +1,8 @@
|
||||
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 com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
@ -22,13 +25,14 @@ public class OrePopulator extends GaeaBlockPopulator {
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try (ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) {
|
||||
Biome b = TerraBiomeGrid.fromWorld(world).getBiome((chunk.getX() << 4)+8, (chunk.getZ() << 4) + 8, GenerationPhase.POPULATE);
|
||||
for(Map.Entry<OreConfig, Range> e : BiomeConfig.fromBiome((UserDefinedBiome) b).getOres().entrySet()) {
|
||||
TerraConfig config = TerraWorld.getWorld(world).getConfig();
|
||||
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);
|
||||
for(int i = 0; i < num; i++) {
|
||||
int x = 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);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
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.StructureConfig;
|
||||
import com.dfsek.terra.structure.GaeaStructure;
|
||||
@ -26,8 +29,11 @@ public class StructurePopulator extends BlockPopulator {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("StructureTime")) {
|
||||
int cx = (chunk.getX() << 4);
|
||||
int cz = (chunk.getZ() << 4);
|
||||
UserDefinedBiome b = (UserDefinedBiome) TerraBiomeGrid.fromWorld(world).getBiome(cx+ 8, cz + 8, GenerationPhase.POPULATE);
|
||||
structure: for(StructureConfig conf : BiomeConfig.fromBiome(b).getStructures()) {
|
||||
TerraWorld tw = TerraWorld.getWorld(world);
|
||||
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();
|
||||
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
|
||||
Random r2 = new Random(spawn.hashCode());
|
||||
@ -36,7 +42,7 @@ public class StructurePopulator extends BlockPopulator {
|
||||
spawn.setY(y);
|
||||
for(StructureSpawnRequirement s : struc.getSpawns()) {
|
||||
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);
|
||||
continue structure;
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import com.dfsek.terra.generation.UserDefinedDecorator;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
@ -20,10 +22,12 @@ public class TreePopulator extends GaeaBlockPopulator {
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
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 z = random.nextInt(16);
|
||||
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;
|
||||
int max = 50;
|
||||
int att = 0;
|
||||
@ -32,7 +36,7 @@ public class TreePopulator extends GaeaBlockPopulator {
|
||||
int y = WorldUtil.getHighestValidSpawnAt(chunk, x, z);
|
||||
if(y <= 0) continue;
|
||||
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 {
|
||||
if(b.getDecorator().getTrees().get(random).plant(origin, random, false, Terra.getInstance())) i++;
|
||||
} catch(NullPointerException ignore) {}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.dfsek.terra.structure;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import com.dfsek.terra.config.genconfig.BiomeConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -50,21 +52,23 @@ public class StructureSpawnRequirement implements Serializable {
|
||||
AIR {
|
||||
@Override
|
||||
public boolean matches(World w, int x, int y, int z) {
|
||||
UserDefinedBiome b = (UserDefinedBiome) TerraBiomeGrid.fromWorld(w).getBiome(x, z, GenerationPhase.POPULATE);
|
||||
if(y <= BiomeConfig.fromBiome(b).getSeaLevel()) return false;
|
||||
UserDefinedBiome b = (UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
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;
|
||||
}
|
||||
}, OCEAN {
|
||||
@Override
|
||||
public boolean matches(World w, int x, int y, int z) {
|
||||
UserDefinedBiome b = (UserDefinedBiome) TerraBiomeGrid.fromWorld(w).getBiome(x, z, GenerationPhase.POPULATE);
|
||||
if(y > BiomeConfig.fromBiome(b).getSeaLevel()) return false;
|
||||
UserDefinedBiome b = (UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
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;
|
||||
}
|
||||
}, LAND {
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user