aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/gregtech/api/util
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2017-08-23 17:56:58 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2017-08-23 17:56:58 +1000
commit7573ee56c6d8ee08319ef17ca28b46efcc5c6ed1 (patch)
tree00e7e660431f875ea4bc5f7bf542a04d502779f3 /src/Java/gtPlusPlus/xmod/gregtech/api/util
parent7e63e4fd8a705391c45e5940e00cda5964fbfd01 (diff)
parent3162fe2ce21d5a2905854b0e313d997a240944c0 (diff)
downloadGT5-Unofficial-7573ee56c6d8ee08319ef17ca28b46efcc5c6ed1.tar.gz
GT5-Unofficial-7573ee56c6d8ee08319ef17ca28b46efcc5c6ed1.tar.bz2
GT5-Unofficial-7573ee56c6d8ee08319ef17ca28b46efcc5c6ed1.zip
Merge branch 'master' of https://github.com/draknyte1/GTplusplus
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/util')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/util/GTPP_Config.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/util/GTPP_Config.java b/src/Java/gtPlusPlus/xmod/gregtech/api/util/GTPP_Config.java
new file mode 100644
index 0000000000..5a5ddd9d53
--- /dev/null
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/util/GTPP_Config.java
@@ -0,0 +1,98 @@
+package gtPlusPlus.xmod.gregtech.api.util;
+
+import gregtech.api.GregTech_API;
+import gregtech.api.util.GT_OreDictUnificator;
+import gregtech.api.util.GT_Utility;
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.common.config.Configuration;
+import net.minecraftforge.common.config.Property;
+
+import static gregtech.api.enums.GT_Values.E;
+
+public class GTPP_Config implements Runnable {
+ public static boolean troll = false;
+
+ public static Configuration sConfigFileIDs;
+ public final Configuration mConfig;
+
+ public GTPP_Config(Configuration aConfig) {
+ mConfig = aConfig;
+ mConfig.load();
+ mConfig.save();
+ }
+
+ public static int addIDConfig(Object aCategory, String aName, int aDefault) {
+ if (GT_Utility.isStringInvalid(aName)) return aDefault;
+ Property tProperty = sConfigFileIDs.get(aCategory.toString().replaceAll("\\|", "."), aName.replaceAll("\\|", "."), aDefault);
+ int rResult = tProperty.getInt(aDefault);
+ if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) sConfigFileIDs.save();
+ return rResult;
+ }
+
+ public static String getStackConfigName(ItemStack aStack) {
+ if (GT_Utility.isStackInvalid(aStack)) return E;
+ Object rName = GT_OreDictUnificator.getAssociation(aStack);
+ if (rName != null) return rName.toString();
+ try {
+ if (GT_Utility.isStringValid(rName = aStack.getUnlocalizedName())) return rName.toString();
+ } catch (Throwable e) {/*Do nothing*/}
+ String sName = aStack.getItem().toString();
+ String[] tmp = sName.split("@");
+ if (tmp.length > 0) sName = tmp[0];
+ return sName + "." + aStack.getItemDamage();
+ }
+
+ public boolean get(Object aCategory, ItemStack aStack, boolean aDefault) {
+ String aName = getStackConfigName(aStack);
+ return get(aCategory, aName, aDefault);
+ }
+
+ public boolean get(Object aCategory, String aName, boolean aDefault) {
+ if (GT_Utility.isStringInvalid(aName)) return aDefault;
+ Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName + "_" + aDefault).replaceAll("\\|", "_"), aDefault);
+ boolean rResult = tProperty.getBoolean(aDefault);
+ if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save();
+ return rResult;
+ }
+
+ public int get(Object aCategory, ItemStack aStack, int aDefault) {
+ return get(aCategory, getStackConfigName(aStack), aDefault);
+ }
+
+ public int get(Object aCategory, String aName, int aDefault) {
+ if (GT_Utility.isStringInvalid(aName)) return aDefault;
+ Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName + "_" + aDefault).replaceAll("\\|", "_"), aDefault);
+ int rResult = tProperty.getInt(aDefault);
+ if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save();
+ return rResult;
+ }
+
+ public double get(Object aCategory, ItemStack aStack, double aDefault) {
+ return get(aCategory, getStackConfigName(aStack), aDefault);
+ }
+
+ public double get(Object aCategory, String aName, double aDefault) {
+ if (GT_Utility.isStringInvalid(aName)) return aDefault;
+ Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName + "_" + aDefault).replaceAll("\\|", "_"), aDefault);
+ double rResult = tProperty.getDouble(aDefault);
+ if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save();
+ return rResult;
+ }
+
+ public String get(Object aCategory, ItemStack aStack, String aDefault) {
+ return get(aCategory, getStackConfigName(aStack), aDefault);
+ }
+
+ public String get(Object aCategory, String aName, String aDefault) {
+ if (GT_Utility.isStringInvalid(aName)) return aDefault;
+ Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName + "_" + aDefault).replaceAll("\\|", "_"), aDefault);
+ String rResult = tProperty.getString();
+ if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save();
+ return rResult;
+ }
+
+ @Override
+ public void run() {
+ mConfig.save();
+ }
+} \ No newline at end of file