Reverting DynamicConfig back to Forge

This commit is contained in:
TheDarkDnKTv 2021-03-11 18:55:41 +02:00
parent 8630f853ee
commit 18507677aa
3 changed files with 9 additions and 105 deletions

View file

@ -36,6 +36,7 @@ import gregtechmod.common.GT_Proxy;
import gregtechmod.common.GT_RecipeAdder;
import gregtechmod.common.GT_TickHandler;
import gregtechmod.common.GT_Worldgenerator;
import gregtechmod.common.RecipeHandler;
import gregtechmod.common.blocks.GT_BlockMetaID_Block;
import gregtechmod.common.blocks.GT_BlockMetaID_Block2;
import gregtechmod.common.blocks.GT_BlockMetaID_Machine;
@ -263,7 +264,7 @@ public class GT_Mod implements IGT_Mod {
File tFile = new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "GregTech.cfg");
Configuration tConfig1 = new Configuration(tFile);
tConfig1.load();
GregTech_API.sRecipeFile = new GT_Config.JsonWrapper(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "DynamicConfig.json"));
GregTech_API.sRecipeFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "DynamicConfig.cfg")));
GregTech_API.sMachineFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "MachineStats.cfg")));
GregTech_API.sWorldgenFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "WorldGeneration.cfg")));
GregTech_API.sMaterialProperties = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "MaterialProperties.cfg")));
@ -652,10 +653,15 @@ public class GT_Mod implements IGT_Mod {
GT_RecipeRegistrator.registerUsagesForMaterials(new ItemStack(Blocks.planks, 1), GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1L), null, false, true, false);
GT_Log.log.info("Activating OreDictionary Handler, this can take some time, as it scans the whole OreDictionary");
GT_Log.log.info("If your Log stops here, you were too impatient. Wait a bit more next time, before killing Minecraft with the Task Manager.");
GT_Log.log.info("Generating machine recipes");
GT_OreDictHandler.instance.activateHandler();
GT_Log.log.info("Activating Recipe handler");
GT_Log.log.info("If your Log stops here, you were too impatient. Wait a bit more next time, before killing Minecraft with the Task Manager.");
RecipeHandler.activateHandler();
GT_Log.log.info("Congratulations, you have been waiting long enough. Have a Cake.");
GT_Log.log.info("Adding Stone related Recipes");
GT_ModHandler.addSmeltingRecipe(new ItemStack(GregTech_API.sBlockList[5] , 1 , 0) , new ItemStack(GregTech_API.sBlockList[5] , 1 , 7 ));
GT_ModHandler.addSmeltingRecipe(new ItemStack(GregTech_API.sBlockList[5] , 1 , 1) , new ItemStack(GregTech_API.sBlockList[5] , 1 , 0 ));
@ -864,7 +870,6 @@ public class GT_Mod implements IGT_Mod {
GregTech_API.sAfterGTLoad = null;
GregTech_API.sBeforeGTPostload = null;
GregTech_API.sAfterGTPostload = null;
GregTech_API.sRecipeFile.save();
}
/*

View file

@ -77,8 +77,7 @@ public class GregTech_API {
public static boolean DEBUG_MODE = false, SECONDARY_DEBUG_MODE = false, IC_ENERGY_COMPATIBILITY = true, RF_ENERGY_COMPATIBILITY = true;
/** The Configuration Objects */
public static GT_Config sMachineFile = null, sWorldgenFile = null, sMaterialProperties = null, sUnification = null, sSpecialFile = null;
public static GT_Config.JsonWrapper sRecipeFile = null;
public static GT_Config sMachineFile = null, sWorldgenFile = null, sMaterialProperties = null, sUnification = null, sSpecialFile = null, sRecipeFile = null;
/** Because Minecraft changed it from -1 to that Value */
public static final short ITEM_WILDCARD_DAMAGE = OreDictionary.WILDCARD_VALUE;

View file

@ -1,18 +1,5 @@
package gregtechmod.api.util;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Objects;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
@ -83,91 +70,4 @@ public class GT_Config {
if (!tProperty.wasRead()) mConfig.save();
return rResult;
}
public static class JsonWrapper {
private static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
private JsonObject object;
private final File config;
public JsonWrapper(File config) {
this.config = Objects.requireNonNull(config);
this.load();
}
public boolean get(Object category, String keyName, boolean defaultValue) {
return this.get(category, keyName, gson.toJsonTree(defaultValue)).getAsBoolean();
}
public boolean get(Object category, ItemStack keyItem, boolean defaultValue) {
return this.get(category, getStackConfigName(keyItem), defaultValue);
}
public int get(Object category, String keyName, int defaultValue) {
return this.get(category, keyName, gson.toJsonTree(defaultValue)).getAsInt();
}
public int get(Object category, ItemStack keyItem, int defaultValue) {
return this.get(category, getStackConfigName(keyItem), gson.toJsonTree(defaultValue)).getAsInt();
}
public double get(Object category, String keyName, double defaultValue) {
return this.get(category, keyName, gson.toJsonTree(defaultValue)).getAsDouble();
}
public double get(Object category, ItemStack keyItem, double defaultValue) {
return this.get(category, getStackConfigName(keyItem), gson.toJsonTree(defaultValue)).getAsDouble();
}
public JsonElement get(Object category, String keyName, JsonElement defaultValue) {
JsonObject catObj = null;
if (object.has(category.toString()) && (catObj = object.get(category.toString()).getAsJsonObject()).has(keyName)) {
return catObj.get(keyName);
} else {
catObj = catObj == null ? new JsonObject() : catObj;
catObj.add(keyName, defaultValue);
object.add(category.toString(), catObj);
}
return defaultValue;
}
public void load() {
try {
if (config.exists()) {
try (FileReader reader = new FileReader(config)) {
JsonElement confFile = new JsonParser().parse(reader);
if (confFile.isJsonObject()) {
this.object = confFile.getAsJsonObject();
} else {
Files.delete(config.toPath());
this.load();
}
} catch (IOException e) {
this.object = new JsonObject();
}
} else {
if (config.createNewFile()) {
FileWriter writer = new FileWriter(config);
this.object = new JsonObject();
gson.toJson(this.object, writer);
} else throw new IllegalStateException("Cannot create config file!");
}
} catch (Throwable e) {
RuntimeException t = new IllegalStateException("Unable to load config", e);
GT_Log.log.throwing(t);
throw t;
}
}
public void save() {
try (FileWriter writer = new FileWriter(config)) {
gson.toJson(this.object, writer);
} catch (Throwable e) {
RuntimeException t = new IllegalStateException("Unable to save config file!", e);
GT_Log.log.throwing(t);
throw t;
}
}
}
}