Move ore config, and use normal gson
This commit is contained in:
parent
50bb4ea7a9
commit
fed253332b
2 changed files with 8 additions and 41 deletions
|
@ -91,14 +91,13 @@ public class Core {
|
||||||
FMLCommonHandler.instance().bus().register(this);
|
FMLCommonHandler.instance().bus().register(this);
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
|
||||||
configDir = new File(event.getModConfigurationDirectory(), "techreborn");
|
configDir = new File(new File(event.getModConfigurationDirectory(), "teamreborn"), "techreborn");
|
||||||
if (!configDir.exists()) {
|
if (!configDir.exists()) {
|
||||||
configDir.mkdir();
|
configDir.mkdir();
|
||||||
}
|
}
|
||||||
config = ConfigTechReborn.initialize(new File(configDir, "main.cfg"));
|
config = ConfigTechReborn.initialize(new File(configDir, "main.cfg"));
|
||||||
worldGen = new TechRebornWorldGen();
|
worldGen = new TechRebornWorldGen();
|
||||||
worldGen.configFile = (new File(configDir, "ores.json"));
|
worldGen.configFile = (new File(configDir, "ores.json"));
|
||||||
worldGen.hConfigFile = (new File(configDir, "ores.hjson"));
|
|
||||||
//Must be done before the item classes are loaded.
|
//Must be done before the item classes are loaded.
|
||||||
ModPoweredItems.preInit();
|
ModPoweredItems.preInit();
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ package techreborn.world;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.block.state.pattern.BlockMatcher;
|
import net.minecraft.block.state.pattern.BlockMatcher;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
|
@ -39,16 +38,16 @@ import net.minecraft.world.gen.IChunkGenerator;
|
||||||
import net.minecraft.world.gen.feature.WorldGenMinable;
|
import net.minecraft.world.gen.feature.WorldGenMinable;
|
||||||
import net.minecraftforge.common.BiomeDictionary;
|
import net.minecraftforge.common.BiomeDictionary;
|
||||||
import net.minecraftforge.fml.common.IWorldGenerator;
|
import net.minecraftforge.fml.common.IWorldGenerator;
|
||||||
import org.hjson.JsonValue;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.hjson.Stringify;
|
|
||||||
import reborncore.common.misc.ChunkCoord;
|
import reborncore.common.misc.ChunkCoord;
|
||||||
import techreborn.Core;
|
import techreborn.Core;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
import techreborn.world.config.OreConfig;
|
import techreborn.world.config.OreConfig;
|
||||||
import techreborn.world.config.WorldGenConfig;
|
import techreborn.world.config.WorldGenConfig;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
import java.lang.reflect.Type;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -61,7 +60,6 @@ public class TechRebornWorldGen implements IWorldGenerator {
|
||||||
public static RubberTreeGenerator treeGenerator = new RubberTreeGenerator();
|
public static RubberTreeGenerator treeGenerator = new RubberTreeGenerator();
|
||||||
public final TechRebornRetroGen retroGen = new TechRebornRetroGen();
|
public final TechRebornRetroGen retroGen = new TechRebornRetroGen();
|
||||||
public File configFile;
|
public File configFile;
|
||||||
public File hConfigFile;
|
|
||||||
public boolean jsonInvalid = false;
|
public boolean jsonInvalid = false;
|
||||||
public WorldGenConfig config;
|
public WorldGenConfig config;
|
||||||
WorldGenConfig defaultConfig;
|
WorldGenConfig defaultConfig;
|
||||||
|
@ -94,30 +92,7 @@ public class TechRebornWorldGen implements IWorldGenerator {
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
init();
|
init();
|
||||||
//Converts the old format to the new one
|
|
||||||
if (configFile.exists()) {
|
if (configFile.exists()) {
|
||||||
if (!hConfigFile.exists()) {
|
|
||||||
try {
|
|
||||||
//Reads json
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(configFile));
|
|
||||||
//Converts to hjson
|
|
||||||
String hJson = JsonValue.readHjson(reader).toString(Stringify.HJSON);
|
|
||||||
//Saves as the new HJson file
|
|
||||||
FileWriter writer = new FileWriter(hConfigFile);
|
|
||||||
writer.write(hJson);
|
|
||||||
writer.close();
|
|
||||||
reader.close();
|
|
||||||
//Delete old json file
|
|
||||||
configFile.delete();
|
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hConfigFile.exists()) {
|
|
||||||
loadFromJson();
|
loadFromJson();
|
||||||
} else {
|
} else {
|
||||||
config = defaultConfig;
|
config = defaultConfig;
|
||||||
|
@ -152,11 +127,8 @@ public class TechRebornWorldGen implements IWorldGenerator {
|
||||||
private void loadFromJson() {
|
private void loadFromJson() {
|
||||||
try {
|
try {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(hConfigFile));
|
String jsonString = FileUtils.readFileToString(configFile, Charset.defaultCharset());
|
||||||
String jsonString = JsonValue.readHjson(reader).toString();
|
config = gson.fromJson(jsonString, WorldGenConfig.class);
|
||||||
Type typeOfHashMap = new TypeToken<WorldGenConfig>() {
|
|
||||||
}.getType();
|
|
||||||
config = gson.fromJson(jsonString, typeOfHashMap);
|
|
||||||
// ArrayUtils.addAll(config.endOres, config.neatherOres, config.overworldOres).stream().forEach(oreConfig -> {
|
// ArrayUtils.addAll(config.endOres, config.neatherOres, config.overworldOres).stream().forEach(oreConfig -> {
|
||||||
// if (oreConfig.minYHeight > oreConfig.maxYHeight) {
|
// if (oreConfig.minYHeight > oreConfig.maxYHeight) {
|
||||||
// printError(oreConfig.blockName + " ore generation value is invalid, the min y height is bigger than the max y height, this ore value will be disabled in code");
|
// printError(oreConfig.blockName + " ore generation value is invalid, the min y height is bigger than the max y height, this ore value will be disabled in code");
|
||||||
|
@ -194,13 +166,9 @@ public class TechRebornWorldGen implements IWorldGenerator {
|
||||||
private void save() {
|
private void save() {
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
String json = gson.toJson(config);
|
String json = gson.toJson(config);
|
||||||
String hJson = JsonValue.readHjson(json).toString(Stringify.HJSON);
|
|
||||||
try {
|
try {
|
||||||
FileWriter writer = new FileWriter(hConfigFile);
|
FileUtils.writeStringToFile(configFile, json, Charset.defaultCharset());
|
||||||
writer.write(hJson);
|
|
||||||
writer.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Core.logHelper.error("The ores.json file was invalid, something bad happened");
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue