Skip to content

Commit

Permalink
Couple of bugfixes and some minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
crazysnailboy committed Aug 21, 2017
1 parent cc1ff59 commit b369ff8
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 181 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -17,7 +17,7 @@ buildscript {

apply plugin: 'forge'

version = "1.4.5"
version = "1.4.6"
group = "org.jglrxavpok.mods.decraft"
archivesBaseName = "[1.7.10]UncraftingTable"

Expand Down
Expand Up @@ -3,17 +3,17 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.jglrxavpok.mods.decraft.ModUncrafting;
import org.jglrxavpok.mods.decraft.client.config.ModGuiConfigEntries;
import org.jglrxavpok.mods.decraft.common.network.message.ConfigSyncMessage;

import cpw.mods.fml.client.config.GuiConfigEntries.NumberSliderEntry;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
Expand All @@ -22,30 +22,55 @@
public class ModConfiguration
{

private static class DefaultValues
{
private static final int standardLevel = 5;
private static final int maxUsedLevel = 30;
private static final int enchantmentCost = 1;
private static final int uncraftMethod = 0;
private static final String[] excludedItems = new String[] { };

private static final boolean useNuggets = true;
private static final boolean registerNuggets = true;
private static final boolean useRabbitHide = false;
private static final boolean ensureReturn = true;

private static final boolean checkForUpdates = true;
private static final boolean promptForLatest = true;
private static final boolean promptForRecommended = true;
}

private static Configuration config = null;


public static final String CATEGORY_GENERAL = Configuration.CATEGORY_GENERAL;
public static final String CATEGORY_UPDATES = "updates";
public static final String CATEGORY_NUGGETS = "nuggets";


public static int standardLevel = 5;
public static int maxUsedLevel = 30;
public static int enchantmentCost = 1;
public static int uncraftMethod = 0;
public static String[] excludedItems = new String[] { };
public static int standardLevel = DefaultValues.standardLevel;
public static int maxUsedLevel = DefaultValues.maxUsedLevel;
public static int enchantmentCost = DefaultValues.enchantmentCost;
public static int uncraftMethod = DefaultValues.uncraftMethod;
public static String[] excludedItems = DefaultValues.excludedItems;

public static boolean useNuggets = true;
public static boolean registerNuggets = true;
public static boolean useRabbitHide = false;
public static boolean ensureReturn = true;
public static boolean useNuggets = DefaultValues.useNuggets;
public static boolean registerNuggets = DefaultValues.registerNuggets;
public static boolean useRabbitHide = DefaultValues.useRabbitHide;
public static boolean ensureReturn = DefaultValues.ensureReturn;

public static boolean checkForUpdates = true;
public static boolean promptForLatest = true;
public static boolean promptForRecommended = true;
public static boolean checkForUpdates = DefaultValues.checkForUpdates;
public static boolean promptForLatest = DefaultValues.promptForLatest;
public static boolean promptForRecommended = DefaultValues.promptForRecommended;


public static Configuration getConfig()
{
return config;
}


public static void preInit()
public static void initializeConfiguration()
{
File configFile = new File(Loader.instance().getConfigDir(), ModUncrafting.MODID + ".cfg");

Expand All @@ -57,16 +82,6 @@ public static void preInit()
FMLCommonHandler.instance().bus().register(new ConfigEventHandler());
}

public static void clientPreInit()
{
FMLCommonHandler.instance().bus().register(new ClientConfigEventHandler());
}

public static Configuration getConfig()
{
return config;
}


public static void syncFromFile()
{
Expand All @@ -78,69 +93,84 @@ public static void syncFromGUI()
syncConfig(false, true);
}

public static void syncFromFields()
{
syncConfig(false, false);
}


private static void syncConfig(boolean loadConfigFromFile, boolean readFieldsFromConfig)
{

if (loadConfigFromFile) config.load();

Property propStandardLevel = config.get(Configuration.CATEGORY_GENERAL, "standardLevel", standardLevel, "Minimum required level to uncraft an item", 0, 50);
Property propStandardLevel = config.get(CATEGORY_GENERAL, "standardLevel", DefaultValues.standardLevel, "Minimum required level to uncraft an item", 0, 50);
propStandardLevel.setLanguageKey("uncrafting.options.standardLevel");
propStandardLevel.setRequiresMcRestart(false);

Property propMaxLevel = config.get(Configuration.CATEGORY_GENERAL, "maxUsedLevel", maxUsedLevel, "Maximum required level to uncraft an item", 0, 50);
Property propMaxLevel = config.get(CATEGORY_GENERAL, "maxUsedLevel", DefaultValues.maxUsedLevel, "Maximum required level to uncraft an item", 0, 50);
propMaxLevel.setLanguageKey("uncrafting.options.maxUsedLevel");
propMaxLevel.setRequiresMcRestart(false);

Property propEnchantmentCost = config.get(Configuration.CATEGORY_GENERAL, "enchantmentCost", enchantmentCost, "Cost per enchantment when removing enchantments onto books", 0, 10);
Property propEnchantmentCost = config.get(CATEGORY_GENERAL, "enchantmentCost", DefaultValues.enchantmentCost, "Cost per enchantment when removing enchantments onto books", 0, 10);
propEnchantmentCost.setLanguageKey("uncrafting.options.enchantmentCost");
propEnchantmentCost.setRequiresMcRestart(false);

Property propUncraftMethod = config.get(Configuration.CATEGORY_GENERAL, "uncraftMethod", uncraftMethod, "ID of the used uncrafting equation.");
Property propUncraftMethod = config.get(CATEGORY_GENERAL, "uncraftMethod", DefaultValues.uncraftMethod, "ID of the used uncrafting equation.");
propUncraftMethod.setLanguageKey("uncrafting.options.method");
propUncraftMethod.setValidValues(new String[] { "jglrxavpok", "Xell75 & zenen" });
propUncraftMethod.setRequiresMcRestart(false);

Property propExcludedItems = config.get(Configuration.CATEGORY_GENERAL, "excludedItems", excludedItems, "List of items which cannot be uncrafted");
Property propExcludedItems = config.get(CATEGORY_GENERAL, "excludedItems", DefaultValues.excludedItems, "List of items which cannot be uncrafted");
propExcludedItems.setLanguageKey("uncrafting.options.excludedItems");
propExcludedItems.setRequiresMcRestart(false);


Property propUseNuggets = config.get(ModConfiguration.CATEGORY_NUGGETS, "useNuggets", useNuggets, "Use available nuggets for partial returns of damaged items");
Property propUseNuggets = config.get(CATEGORY_NUGGETS, "useNuggets", DefaultValues.useNuggets, "Use available nuggets for partial returns of damaged items");
propUseNuggets.setLanguageKey("uncrafting.options.nuggets.useNuggets");
propUseNuggets.setRequiresMcRestart(false);

Property propRegisterNuggets = config.get(ModConfiguration.CATEGORY_NUGGETS, "registerNuggets", registerNuggets, "Register additional nuggets to use for partial returns of damaged Vanilla items");
Property propRegisterNuggets = config.get(CATEGORY_NUGGETS, "registerNuggets", DefaultValues.registerNuggets, "Register additional nuggets to use for partial returns of damaged Vanilla items");
propRegisterNuggets.setLanguageKey("uncrafting.options.nuggets.registerNuggets");
propRegisterNuggets.setRequiresMcRestart(true);

Property propUseRabbitHide = config.get(ModConfiguration.CATEGORY_NUGGETS, "useRabbitHide", useRabbitHide, "Use Rabbit Hide for partial returns of damaged Leather items (Requires Et Futurum)");
Property propUseRabbitHide = config.get(CATEGORY_NUGGETS, "useRabbitHide", DefaultValues.useRabbitHide, "Use Rabbit Hide for partial returns of damaged Leather items (Requires Et Futurum)");
propUseRabbitHide.setLanguageKey("uncrafting.options.nuggets.useRabbitHide");
propUseRabbitHide.setRequiresMcRestart(false);

Property propEnsureReturn = config.get(ModConfiguration.CATEGORY_NUGGETS, "ensureReturn", ensureReturn, "Ensure that at least one nugget is returned, even for items with 0% durability");
Property propEnsureReturn = config.get(CATEGORY_NUGGETS, "ensureReturn", DefaultValues.ensureReturn, "Ensure that at least one nugget is returned, even for items with 0% durability");
propEnsureReturn.setLanguageKey("uncrafting.options.nuggets.ensureReturn");
propEnsureReturn.setRequiresMcRestart(false);


Property propCheckForUpdates = config.get(ModConfiguration.CATEGORY_UPDATES, "checkForUpdates", checkForUpdates, "Should the mod check for updates on startup");
Property propCheckForUpdates = config.get(CATEGORY_UPDATES, "checkForUpdates", DefaultValues.checkForUpdates, "Should the mod check for updates on startup");
propCheckForUpdates.setLanguageKey("uncrafting.options.updates.checkForUpdates");
propCheckForUpdates.setRequiresMcRestart(true);

Property propPromptForLatest = config.get(ModConfiguration.CATEGORY_UPDATES, "promptForLatest", promptForLatest, "Alert the user when there is a new version");
Property propPromptForLatest = config.get(CATEGORY_UPDATES, "promptForLatest", DefaultValues.promptForLatest, "Alert the user when there is a new version");
propPromptForLatest.setLanguageKey("uncrafting.options.updates.promptForLatest");
propPromptForLatest.setRequiresMcRestart(true);

Property propPromptForRecommended = config.get(ModConfiguration.CATEGORY_UPDATES, "promptForRecommended", promptForRecommended, "Alert the user when there is a new recommended version");
Property propPromptForRecommended = config.get(CATEGORY_UPDATES, "promptForRecommended", DefaultValues.promptForRecommended, "Alert the user when there is a new recommended version");
propPromptForRecommended.setLanguageKey("uncrafting.options.updates.promptForRecommended");
propPromptForRecommended.setRequiresMcRestart(true);


List<String> propOrderGeneral = new ArrayList<String>();
propOrderGeneral.add(propStandardLevel.getName());
propOrderGeneral.add(propMaxLevel.getName());
propOrderGeneral.add(propEnchantmentCost.getName());
propOrderGeneral.add(propUncraftMethod.getName());
propOrderGeneral.add(propExcludedItems.getName());
config.setCategoryPropertyOrder(CATEGORY_GENERAL, propOrderGeneral);

List<String> propOrderNuggets = new ArrayList<String>();
propOrderNuggets.add(propUseNuggets.getName());
propOrderNuggets.add(propRegisterNuggets.getName());
propOrderNuggets.add(propUseRabbitHide.getName());
propOrderNuggets.add(propEnsureReturn.getName());
config.setCategoryPropertyOrder(CATEGORY_NUGGETS, propOrderNuggets);

List<String> propOrderUpdates = new ArrayList<String>();
propOrderUpdates.add(propCheckForUpdates.getName());
propOrderUpdates.add(propPromptForLatest.getName());
propOrderUpdates.add(propPromptForRecommended.getName());
config.setCategoryPropertyOrder(CATEGORY_UPDATES, propOrderUpdates);


try
{
Expand All @@ -158,28 +188,6 @@ private static void syncConfig(boolean loadConfigFromFile, boolean readFieldsFro
propCheckForUpdates.setConfigEntryClass(ModGuiConfigEntries.BooleanEntry.class);
propPromptForLatest.setConfigEntryClass(ModGuiConfigEntries.BooleanEntry.class);
propPromptForRecommended.setConfigEntryClass(ModGuiConfigEntries.BooleanEntry.class);

List<String> propOrderGeneral = new ArrayList<String>();
propOrderGeneral.add(propStandardLevel.getName());
propOrderGeneral.add(propMaxLevel.getName());
propOrderGeneral.add(propEnchantmentCost.getName());
propOrderGeneral.add(propUncraftMethod.getName());
propOrderGeneral.add(propExcludedItems.getName());
config.setCategoryPropertyOrder(Configuration.CATEGORY_GENERAL, propOrderGeneral);

List<String> propOrderNuggets = new ArrayList<String>();
propOrderNuggets.add(propUseNuggets.getName());
propOrderNuggets.add(propRegisterNuggets.getName());
propOrderNuggets.add(propUseRabbitHide.getName());
propOrderNuggets.add(propEnsureReturn.getName());
config.setCategoryPropertyOrder(ModConfiguration.CATEGORY_NUGGETS, propOrderNuggets);

List<String> propOrderUpdates = new ArrayList<String>();
propOrderUpdates.add(propCheckForUpdates.getName());
propOrderUpdates.add(propPromptForLatest.getName());
propOrderUpdates.add(propPromptForRecommended.getName());
config.setCategoryPropertyOrder(ModConfiguration.CATEGORY_UPDATES, propOrderUpdates);

}
catch(NoClassDefFoundError e) { }

Expand Down Expand Up @@ -235,14 +243,11 @@ public void onPlayerLoggedIn(PlayerLoggedInEvent event)
}
}

}

public static class ClientConfigEventHandler
{
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event)
{
if (ModUncrafting.MODID.equals(event.modID) && !event.isWorldRunning)
if (event.modID.equals(ModUncrafting.MODID) && !event.isWorldRunning)
{
syncFromGUI();
}
Expand Down

0 comments on commit b369ff8

Please sign in to comment.