Refactoring Configs to exploit the runtime config changing options in Forge.

This commit is contained in:
MysteriousAges committed 2015-04-25 11:33:46 -07:00
1 parent b1a3223fbe
commit 0a28b3fe63
6 files changed
+83 -74

No files matched your search

@@ -1,21 +1,38 @@
package magicbees.client.gui;
import cpw.mods.fml.client.config.GuiConfig;
import java.util.ArrayList;
import java.util.List;
import magicbees.main.Config;
import magicbees.main.utils.VersionInfo;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.client.config.DummyConfigElement;
import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.IConfigElement;
public class ModGuiConfig extends GuiConfig
{
public ModGuiConfig(GuiScreen guiScreen)
{
super(guiScreen,
new ConfigElement(Config.configuration.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
VersionInfo.ModName,
false,
false,
super(guiScreen, configElements(), VersionInfo.ModName, false, false,
GuiConfig.getAbridgedConfigPath(Config.configuration.toString()));
}
private static List<IConfigElement> configElements() {
List<IConfigElement> list = new ArrayList<IConfigElement>();
list.add(categoryElement(Config.CATEGORY_GENERAL, "General", "magicbees.config.category.general"));
list.add(categoryElement(Config.CATEGORY_DEBUG, "Debug", "magicbees.config.category.debug"));
list.add(categoryElement(Config.CATEGORY_MODULES, "Modules", "magicbees.config.category.modules"));
list.add(categoryElement(Config.CATEGORY_BOTANIA, "Botania Plugin", "magicbees.config.category.botania"));
return list;
}
private static IConfigElement categoryElement(String category, String name, String tooltip_key) {
return new DummyConfigElement.DummyCategoryElement(name, tooltip_key,
new ConfigElement(Config.configuration.getCategory(category)).getChildElements());
}
}
@@ -6,6 +6,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import magicbees.main.CommonProxy;
import magicbees.main.Config;
import magicbees.main.utils.LocalizationManager;
import magicbees.main.utils.TabMagicBees;
import net.minecraft.client.renderer.texture.IIconRegister;
@@ -26,42 +27,16 @@ public class ItemMysteriousMagnet extends Item
@SideOnly(Side.CLIENT)
private IIcon activeIcon;
private float rangeBase;
private float multiplier;
private int maxLevel;
private final float fudgeFactor = 0.2f;
private final float FUDGE_FACTOR = 0.2f;
public ItemMysteriousMagnet()
{
super();
this.setNoRepair();
this.setHasSubtypes(true);
this.rangeBase = 3f;
this.multiplier = 0.75f;
this.maxLevel = 8;
this.setUnlocalizedName(CommonProxy.DOMAIN + ":mysteriousMagnet");
this.setCreativeTab(TabMagicBees.tabMagicBees);
}
public void setBaseRange(float value)
{
this.rangeBase = value;
}
public void setLevelMultiplier(float value)
{
this.multiplier = value;
}
public void setMaximumLevel(int value)
{
this.maxLevel = value;
}
public int getMaximumLevel()
{
return this.maxLevel;
}
@Override
@SideOnly(Side.CLIENT)
@@ -84,7 +59,7 @@ public class ItemMysteriousMagnet extends Item
@SuppressWarnings({ "unchecked", "rawtypes" })
public void getSubItems(Item item, CreativeTabs tabs, List list)
{
for (int i = 0; i <= this.maxLevel; i++)
for (int i = 0; i <= getMaximumLevel(); i++)
{
list.add(new ItemStack(this, 1, i * 2));
}
@@ -129,12 +104,12 @@ public class ItemMysteriousMagnet extends Item
if (isMagnetActive(itemStack) && entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer)entity;
float radius = getRadius(itemStack.getItemDamage()) - fudgeFactor;
float radius = getRadius(itemStack.getItemDamage()) - FUDGE_FACTOR;
AxisAlignedBB bounds = player.boundingBox.expand(radius, radius, radius);
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
bounds.expand(fudgeFactor, fudgeFactor, fudgeFactor);
bounds.expand(FUDGE_FACTOR, FUDGE_FACTOR, FUDGE_FACTOR);
if ((itemStack.getItemDamage() >> 1) >= 7)
{
@@ -198,10 +173,15 @@ public class ItemMysteriousMagnet extends Item
{
return (damage & 0x01) == 1;
}
public int getMaximumLevel()
{
return Config.magnetMaxLevel;
}
private float getRadius(int damageValue)
{
return this.rangeBase + (multiplier * (damageValue >> 1));
return Config.magnetBaseRange + (Config.magnetLevelMultiplier * (damageValue >> 1));
}
}
+34 -29
View File
@@ -68,6 +68,11 @@ import forestry.api.storage.EnumBackpackType;
*/
public class Config
{
public static final String CATEGORY_GENERAL = "general";
public static final String CATEGORY_DEBUG = "debug";
public static final String CATEGORY_MODULES = "modules";
public static final String CATEGORY_BOTANIA = "botaniaPlugin";
public static boolean drawParticleEffects;
public static boolean beeInfusionsAdded;
public static boolean thaumaturgeBackpackActive;
@@ -245,6 +250,7 @@ public class Config
{
configuration.save();
}
syncConfigs();
}
}
@@ -302,6 +308,10 @@ public class Config
LogHelper.debug(e);
}
syncConfigs();
}
private void syncConfigs() {
doGeneralConfigs();
doModuleConfigs();
doDebugConfigs();
@@ -309,7 +319,7 @@ public class Config
private void doDebugConfigs() {
Property p;
p = configuration.get("debug", "logHiveSpawns", false);
p = configuration.get(CATEGORY_DEBUG, "logHiveSpawns", false);
p.comment = "Enable to see exact locations of MagicBees hive spawns.";
logHiveSpawns = p.getBoolean();
}
@@ -317,90 +327,89 @@ public class Config
private void doModuleConfigs() {
Property p;
//Modules
p = configuration.get("modules", "ArsMagica", true);
p = configuration.get(CATEGORY_MODULES, "ArsMagica", true);
arsMagicaActive = p.getBoolean();
p = configuration.get("modules", "BloodMagic", true);
p = configuration.get(CATEGORY_MODULES, "BloodMagic", true);
bloodMagicActive = p.getBoolean();
p = configuration.get("modules", "EquivalentExchange", true);
p = configuration.get(CATEGORY_MODULES, "EquivalentExchange", true);
equivalentExchangeActive = p.getBoolean();
p = configuration.get("modules", "ExtraBees", true);
p = configuration.get(CATEGORY_MODULES, "ExtraBees", true);
extraBeesActive = p.getBoolean();
p = configuration.get("modules", "RedstoneArsenal", true);
p = configuration.get(CATEGORY_MODULES, "RedstoneArsenal", true);
redstoneArsenalActive = p.getBoolean();
p = configuration.get("modules", "Thaumcraft", true);
p = configuration.get(CATEGORY_MODULES, "Thaumcraft", true);
thaumcraftActive = p.getBoolean();
p = configuration.get("modules", "ThermalExpansion", true);
p = configuration.get(CATEGORY_MODULES, "ThermalExpansion", true);
thermalExpansionActive = p.getBoolean();
p = configuration.get("modules", "Botania", true);
p = configuration.get(CATEGORY_MODULES, "Botania", true);
botaniaActive = p.getBoolean();
BotaniaHelper.doBotaniaModuleConfigs(configuration);
}
private void doGeneralConfigs() {
Property p;
final String section = "general";
p = configuration.get(section, "backpack.thaumaturge.active", true);
p = configuration.get(CATEGORY_GENERAL, "backpack.thaumaturge.active", true);
p.comment = "Set to false to disable the Thaumaturge backpack";
thaumaturgeBackpackActive = p.getBoolean(true);
p = configuration.get(section, "backpack.thaumaturge.additionalItems", "");
p = configuration.get(CATEGORY_GENERAL, "backpack.thaumaturge.additionalItems", "");
p.comment = "Add additional items to the Thaumaturge's Backpack." +
"\n Format is the same as Forestry's: id:meta;id;id:meta (etc)";
thaumaturgeExtraItems = p.getString();
p = configuration.get(section, "backpack.forestry.addThaumcraftItems", true);
p = configuration.get(CATEGORY_GENERAL, "backpack.forestry.addThaumcraftItems", true);
p.comment = "Set to true if you want MagicBees to add several Thaumcraft blocks & items to Forestry backpacks." +
"\n Set to false to disable.";
addThaumcraftItemsToBackpacks = p.getBoolean(true);
p = configuration.get(section, "capsuleStackSize", 64);
p = configuration.get(CATEGORY_GENERAL, "capsuleStackSize", 64);
p.comment = "Allows you to edit the stack size of the capsules in MagicBees if using GregTech, \n" +
"or the reduced capsule size in Forestry & Railcraft. Default: 64";
capsuleStackSizeMax = p.getInt();
p = configuration.get(section, "disableVersionNotification", false);
p = configuration.get(CATEGORY_GENERAL, "disableVersionNotification", false);
p.comment = "Set to true to stop Magic Bees from notifying you when new updates are available. (Does not supress critical updates)";
disableUpdateNotification = p.getBoolean(false);
p = configuration.get(section, "areMagicPlanksFlammable", false);
p = configuration.get(CATEGORY_GENERAL, "areMagicPlanksFlammable", false);
p.comment = "Set to true to allow Greatwood & Silverwood planks to burn in a fire.";
areMagicPlanksFlammable = p.getBoolean(false);
p = configuration.get(section, "useImpregnatedStickInTools", false);
p = configuration.get(CATEGORY_GENERAL, "useImpregnatedStickInTools", false);
p.comment = "Set to true to make Thaumium Grafter & Scoop require impregnated sticks in the recipe.";
useImpregnatedStickInTools = p.getBoolean(false);
p = configuration.get(section, "thaumCraftSaplingDroprate", 0.1, "The chance for thaumcraft saplings using the thaumium grafter", 0.0, 1.0);
p = configuration.get(CATEGORY_GENERAL, "thaumCraftSaplingDroprate", 0.1, "The chance for thaumcraft saplings using the thaumium grafter", 0.0, 1.0);
thaumcraftSaplingDroprate = p.getDouble(0.1);
p = configuration.get(section, "moonDialShowText", false);
p = configuration.get(CATEGORY_GENERAL, "moonDialShowText", false);
p.comment = "set to true to show the current moon phase in mouse-over text.";
moonDialShowsPhaseInText = p.getBoolean(false);
p = configuration.get(section, "doSpecialHiveGen", true);
p = configuration.get(CATEGORY_GENERAL, "doSpecialHiveGen", true);
p.comment = "Set to false if you hate fun and do not want special hives generating in Magic biomes.";
doSpecialHiveGen = p.getBoolean(true);
p = configuration.get(section, "magnetRangeBase", 3.0);
p = configuration.get(CATEGORY_GENERAL, "magnetRangeBase", 3.0);
p.comment = "Base range (in blocks) of the Mysterious Magnet";
magnetBaseRange = (float)p.getDouble(3.0);
p = configuration.get(section, "magnetRangeMultiplier", 0.75);
p = configuration.get(CATEGORY_GENERAL, "magnetRangeMultiplier", 0.75);
p.comment = "Range multiplier per level of the Mysterious Magnet. Total range = base range + level * multiplier";
magnetLevelMultiplier = (float)p.getDouble(0.75);
p = configuration.get(section, "magnetMaximumLevel", 8);
p = configuration.get(CATEGORY_GENERAL, "magnetMaximumLevel", 8);
p.comment = "Maximum level of the magnets.";
magnetMaxLevel = p.getInt();
p = configuration.get(section, "aromaticLumpSwarmerRate", 95);
p = configuration.get(CATEGORY_GENERAL, "aromaticLumpSwarmerRate", 95);
p.comment = "Aromatic lump swarmer rate. Final value is X/1000. 0 will disable, values outside of [0,1000] will be clamped to range. Default: 95";
aromaticLumpSwarmerRate = p.getInt();
}
@@ -442,15 +451,11 @@ public class Config
private void setupMysteriousMagnet() {
magnet = new ItemMysteriousMagnet();
magnet.setBaseRange(magnetBaseRange);
magnet.setLevelMultiplier(magnetLevelMultiplier);
magnet.setMaximumLevel(magnetMaxLevel);
GameRegistry.registerItem(magnet, "magnet", CommonProxy.DOMAIN);
}
private void setupJellyBaby() {
jellyBaby = new ItemFood(1, false).setAlwaysEdible()
.setPotionEffect(Potion.moveSpeed.id, 5, 1, 1f);
jellyBaby = new ItemFood(1, false).setAlwaysEdible().setPotionEffect(Potion.moveSpeed.id, 5, 1, 1f);
jellyBaby.setUnlocalizedName(CommonProxy.DOMAIN + ":jellyBabies").setTextureName(CommonProxy.DOMAIN + ":jellyBabies");
GameRegistry.registerItem(jellyBaby, "jellyBabies");
}
@@ -158,25 +158,24 @@ public class BotaniaHelper {
public static void doBotaniaModuleConfigs(Configuration configuration) {
Property p;
String section = "botaniaPlugin";
p = configuration.get(section, "beegoniaManaMultiplier", 1.0);
p = configuration.get(Config.CATEGORY_BOTANIA, "beegoniaManaMultiplier", 1.0);
p.comment = "Multiplier for the Beegonia's mana generation. Default: 1.0 (Affects duration, not throughput)";
beegoniaManaMultiplier = p.getDouble();
p = configuration.get(section, "hiveacynthManaMultiplier", 1.0);
p = configuration.get(Config.CATEGORY_BOTANIA, "hiveacynthManaMultiplier", 1.0);
p.comment = "Multiplier for the Hiveacynth's mana consumption. Default: 1.0";
hiveacynthManaMultiplier = p.getDouble();
p = configuration.get(section, "hiveacynthRainResistRate", 0.1);
p = configuration.get(Config.CATEGORY_BOTANIA, "hiveacynthRainResistRate", 0.1);
p.comment = "Rate at which the Hiveacynth applies rain resist to spawned bees. Default: 0.1 Setting to 0 will disable.";
hiveacynthRainResistRate = p.getDouble();
p = configuration.get(section, "hiveacynthPrincessSpawnRate", 0.09);
p = configuration.get(Config.CATEGORY_BOTANIA, "hiveacynthPrincessSpawnRate", 0.09);
p.comment = "Rate at which the Hiveacynth will spawn a Princess instead of a Drone. Default: 0.09. Setting to 0 will disable.";
hiveacynthPrincessSpawnRate = p.getDouble();
p = configuration.get(section, "hiveacynthPristineRate", 0.15);
p = configuration.get(Config.CATEGORY_BOTANIA, "hiveacynthPristineRate", 0.15);
p.comment = "Rate at which the Hiveacynth will produce a Pristine Princess, when it produces a princess. Default: 0.15. Setting to 0 will disable.";
hiveacynthPristineRate = p.getDouble();
}