From 5bdc326a6c984d74e8cd5c303047e39025b817dc Mon Sep 17 00:00:00 2001 From: OneEyeMaker Date: Wed, 8 Jun 2016 08:22:20 +0300 Subject: [PATCH] Now count of upgrades for capacitors is configurable --- .../common/handler/BalanceConfigHandler.java | 82 ++++++++++++++----- .../common/handler/ConfigHandler.java | 7 +- .../items/tools/DraconiumFluxCapacitor.java | 8 +- 3 files changed, 69 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/brandon3055/draconicevolution/common/handler/BalanceConfigHandler.java b/src/main/java/com/brandon3055/draconicevolution/common/handler/BalanceConfigHandler.java index 797c09f3..8973b884 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/handler/BalanceConfigHandler.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/handler/BalanceConfigHandler.java @@ -62,6 +62,9 @@ public class BalanceConfigHandler public static int grinderExternalEnergyBufferSize = 100000; public static int grinderMaxReceive = 32000; public static int grinderEnergyPerKill = 1000; + public static int wyvernCapacitorMaxUpgrades = 3; + public static int draconicCapacitorMaxUpgrades = 6; + public static int fluxCapacitorMaxUpgradePoints = 50; public static Block energyStorageStructureBlock = null; public static int energyStorageStructureBlockMetadata = 0; public static boolean grinderShouldUseLooting = false; @@ -76,26 +79,6 @@ public class BalanceConfigHandler syncConfig(); } } - // This method should be loaded after all mods add blocks => after pre-init - public static void finishLoading() - { - if (config == null) - { - return; - } - energyStorageStructureBlock = - getBlock("tweaks.machines", "Multiblock Energy Storage: Main block of structure", Blocks.redstone_block, - "WARNING! Changing of this value will replace blocks of all existing Energy Storage Multiblocks!"); - energyStorageStructureBlockMetadata = - getInteger("tweaks.machines", "Multiblock Energy Storage: Metadata of main block of structure", - energyStorageStructureBlockMetadata, - "WARNING! Changing of this value will replace blocks of all existing Energy Storage " + - "Multiblocks!"); - if (config.hasChanged()) - { - config.save(); - } - } private static void syncConfig() { wyvernArmorBaseStorage = @@ -230,6 +213,24 @@ public class BalanceConfigHandler grinderEnergyPerKill = getInteger("energy.machines", "Mob Grinder: Amount of energy required to kill entity (RF)", grinderEnergyPerKill); + int wyvernCapacitorUpgradesLimit = + (int) Math.floor(((double) Integer.MAX_VALUE - (double) wyvernCapacitorBaseStorage) / + (double) Math.max(wyvernCapacitorStoragePerUpgrade, 1) / 2D); + wyvernCapacitorMaxUpgrades = + getInteger("tweaks.tools", "Wyvern Flux Capacitor: Maximum amount of upgrades", wyvernCapacitorMaxUpgrades, + "Value may be replaced automatically to prevent problems", 0, wyvernCapacitorUpgradesLimit); + int draconicCapacitorUpgradesLimit = + (int) Math.floor(((double) Integer.MAX_VALUE - (double) draconicCapacitorBaseStorage) / + (double) Math.max(draconicCapacitorStoragePerUpgrade, 1) / 4D); + draconicCapacitorMaxUpgrades = getInteger("tweaks.tools", "Draconic Flux Capacitor: Maximum amount of upgrades", + draconicCapacitorMaxUpgrades, + "Value may be replaced automatically to prevent problems", 0, + draconicCapacitorUpgradesLimit); + int fluxCapacitorUpgradePointsLimit = Math.max(wyvernCapacitorMaxUpgrades, draconicCapacitorMaxUpgrades) * 4; + fluxCapacitorMaxUpgradePoints = getInteger("tweaks.tools", "Flux Capacitor: Maximum amount of upgrade points", + fluxCapacitorMaxUpgradePoints, + "Value may be replaced automatically to prevent problems", + fluxCapacitorUpgradePointsLimit, Integer.MAX_VALUE); grinderShouldUseLooting = getBoolean("tweaks.machines", "Mob Grinder: Use Looting enchantment", grinderShouldUseLooting); if (config.hasChanged()) @@ -237,6 +238,26 @@ public class BalanceConfigHandler config.save(); } } + // This method should be loaded after all mods add blocks => after pre-init + public static void finishLoading() + { + if (config == null) + { + return; + } + energyStorageStructureBlock = + getBlock("tweaks.machines", "Multiblock Energy Storage: Main block of structure", Blocks.redstone_block, + "WARNING! Changing of this value will replace blocks of all existing Energy Storage Multiblocks!"); + energyStorageStructureBlockMetadata = + getInteger("tweaks.machines", "Multiblock Energy Storage: Metadata of main block of structure", + energyStorageStructureBlockMetadata, + "WARNING! Changing of this value will replace blocks of all existing Energy Storage " + + "Multiblocks!"); + if (config.hasChanged()) + { + config.save(); + } + } private static Block getBlock(String category, String propertyName, Block defaultValue, String comment) { String defaultName = Block.blockRegistry.getNameForObject(defaultValue); @@ -247,8 +268,8 @@ public class BalanceConfigHandler property.set(defaultName); return defaultValue; } - String modId = value.split(":")[0]; - String name = value.split(":")[1]; + String modId = value.substring(0, value.indexOf(":")); + String name = value.substring(value.indexOf(":") + 1); Block block = GameRegistry.findBlock(modId, name); if (block == null || block instanceof ITileEntityProvider) { @@ -269,6 +290,23 @@ public class BalanceConfigHandler { return config.get(categoty, propertyName, defaultValue, comment).getInt(defaultValue); } + private static int getInteger(String category, String propertyName, int defaultValue, String comment, int minValue, + int maxValue) + { + Property property = config.get(category, propertyName, defaultValue, comment, minValue, maxValue); + int value = property.getInt(defaultValue); + if (value < minValue) + { + property.set(minValue); + return minValue; + } + if (value > maxValue) + { + property.set(maxValue); + return maxValue; + } + return value; + } private static long getLong(String category, String propertyName, long defaultValue) { return (long) config.get(category, propertyName, (double) defaultValue, "", 0D, (double) Long.MAX_VALUE) diff --git a/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java b/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java index f5e0a5fe..e13e1559 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java @@ -1,14 +1,14 @@ package com.brandon3055.draconicevolution.common.handler; -import com.brandon3055.draconicevolution.common.utills.LogHelper; -import net.minecraftforge.common.config.Configuration; - import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import com.brandon3055.draconicevolution.common.utills.LogHelper; +import net.minecraftforge.common.config.Configuration; + public class ConfigHandler { public static Configuration config; @@ -77,6 +77,7 @@ public class ConfigHandler { public static void init(File confFile) { if (config == null) { config = new Configuration(confFile); + config.load(); syncConfig(); } } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/items/tools/DraconiumFluxCapacitor.java b/src/main/java/com/brandon3055/draconicevolution/common/items/tools/DraconiumFluxCapacitor.java index 544542f5..5410788c 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/items/tools/DraconiumFluxCapacitor.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/items/tools/DraconiumFluxCapacitor.java @@ -12,7 +12,6 @@ import com.brandon3055.draconicevolution.common.ModItems; import com.brandon3055.draconicevolution.common.handler.BalanceConfigHandler; import com.brandon3055.draconicevolution.common.items.tools.baseclasses.RFItemBase; import com.brandon3055.draconicevolution.common.items.tools.baseclasses.ToolBase; -import com.brandon3055.draconicevolution.common.lib.References; import com.brandon3055.draconicevolution.common.lib.Strings; import com.brandon3055.draconicevolution.common.utills.IUpgradableItem; import cpw.mods.fml.relauncher.Side; @@ -178,7 +177,10 @@ public class DraconiumFluxCapacitor extends RFItemBase implements IUpgradableIte @Override public int getUpgradeCap(ItemStack stack) { - return stack.getItemDamage() == 0 ? References.MAX_WYVERN_UPGRADES : References.MAX_DRACONIC_UPGRADES; + return stack.getItemDamage() == 0 ? + BalanceConfigHandler.wyvernCapacitorMaxUpgrades : + stack.getItemDamage() == 1 ? + BalanceConfigHandler.draconicCapacitorMaxUpgrades : 0; } @Override @@ -188,7 +190,7 @@ public class DraconiumFluxCapacitor extends RFItemBase implements IUpgradableIte @Override public int getMaxUpgradePoints(int upgradeIndex) { - return 50; + return BalanceConfigHandler.fluxCapacitorMaxUpgradePoints; } @Override