Changed configuration to remove redundant code

This commit is contained in:
OneEyeMaker 2017-09-23 12:00:56 +03:00
parent 37ab0f0dfb
commit 925812b7e1
4 changed files with 28 additions and 54 deletions

View file

@ -28,7 +28,7 @@ public final class ConfigValues{
currConf.initializeValue(config); currConf.initializeValue(config);
} }
for(ConfigDoubleValues currConf : ConfigDoubleValues.values()){ for(ConfigFloatValues currConf : ConfigFloatValues.values()){
currConf.initializeValue(config); currConf.initializeValue(config);
} }

View file

@ -2,29 +2,28 @@ package de.ellpeck.actuallyadditions.mod.config.values;
import de.ellpeck.actuallyadditions.mod.config.ConfigCategories; import de.ellpeck.actuallyadditions.mod.config.ConfigCategories;
import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
public enum ConfigDoubleValues public enum ConfigFloatValues
{ {
DRILL_SPEED_I_COST_MULTIPLIER("Drill: Speed I cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.5D, 1.0D, 10.0D, "Energy consumption multiplier for Speed I upgrade"), DRILL_SPEED_I_COST_MULTIPLIER("Drill: Speed I cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.5F, 1.0F, 10.0F, "Energy consumption multiplier for Speed I upgrade"),
DRILL_SPEED_II_COST_MULTIPLIER("Drill: Speed II cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.5D, 1.0D, 10.0D, "Energy consumption multiplier for Speed II upgrade; total cost for this upgrade is multiplied on Speed I cost"), DRILL_SPEED_II_COST_MULTIPLIER("Drill: Speed II cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.5F, 1.0F, 10.0F, "Energy consumption multiplier for Speed II upgrade; total cost for this upgrade is multiplied on Speed I cost"),
DRILL_SPEED_III_COST_MULTIPLIER("Drill: Speed III cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.5D, 1.0D, 10.0D, "Energy consumption multiplier for Speed III upgrade; total cost for this upgrade is multiplied on Speed I and Speed II costs"), DRILL_SPEED_III_COST_MULTIPLIER("Drill: Speed III cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.5F, 1.0F, 10.0F, "Energy consumption multiplier for Speed III upgrade; total cost for this upgrade is multiplied on Speed I and Speed II costs"),
DRILL_SILK_TOUCH_COST_MULTIPLIER("Drill: Silk Touch cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 2.0D, 1.0D, 10.0D, "Energy consumption multiplier for Silk Touch upgrade"), DRILL_SILK_TOUCH_COST_MULTIPLIER("Drill: Silk Touch cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 2.0F, 1.0F, 10.0F, "Energy consumption multiplier for Silk Touch upgrade"),
DRILL_FORTUNE_I_COST_MULTIPLIER("Drill: Fortune I cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.5D, 1.0D, 10.0D, "Energy consumption multiplier for Fortune I upgrade"), DRILL_FORTUNE_I_COST_MULTIPLIER("Drill: Fortune I cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.5F, 1.0F, 10.0F, "Energy consumption multiplier for Fortune I upgrade"),
DRILL_FORTUNE_II_COST_MULTIPLIER("Drill: Fortune II cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.5D, 1.0D, 10.0D, "Energy consumption multiplier for Fortune II upgrade; total cost for this upgrade is multiplied on Fortune I cost"), DRILL_FORTUNE_II_COST_MULTIPLIER("Drill: Fortune II cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.5F, 1.0F, 10.0F, "Energy consumption multiplier for Fortune II upgrade; total cost for this upgrade is multiplied on Fortune I cost"),
DRILL_SIZE_3_COST_MULTIPLIER("Drill: 3x3 Upgrade cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.25D, 1.0D, 10.0D, "Energy consumption multiplier for 3x3 digging upgrade"), DRILL_SIZE_3_COST_MULTIPLIER("Drill: 3x3 Upgrade cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.25F, 1.0F, 10.0F, "Energy consumption multiplier for 3x3 digging upgrade"),
DRILL_SIZE_5_COST_MULTIPLIER("Drill: 5x5 Upgrade cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.25D, 1.0D, 10.0D, "Energy consumption multiplier for 5x5 digging upgrade; total cost for this upgrade is multiplied on 3x3 digging upgrade cost"); DRILL_SIZE_5_COST_MULTIPLIER("Drill: 5x5 Upgrade cost multiplier", ConfigCategories.TOOL_ENERGY_VALUES, 1.25F, 1.0F, 10.0F, "Energy consumption multiplier for 5x5 digging upgrade; total cost for this upgrade is multiplied on 3x3 digging upgrade cost");
public final String name; public final String name;
public final String category; public final String category;
public final double defaultValue; public final float defaultValue;
public final double min; public final float min;
public final double max; public final float max;
public final String desc; public final String desc;
public double currentValue; public float currentValue;
ConfigDoubleValues(String name, ConfigCategories category, double defaultValue, double min, double max, String desc){ ConfigFloatValues(String name, ConfigCategories category, float defaultValue, float min, float max, String desc){
this.name = name; this.name = name;
this.category = category.name; this.category = category.name;
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
@ -34,22 +33,10 @@ public enum ConfigDoubleValues
} }
public void initializeValue(Configuration config){ public void initializeValue(Configuration config){
Property property = config.get(this.category, this.name, this.defaultValue, this.desc, this.min, this.max); this.currentValue = config.getFloat(this.name, this.category, this.defaultValue, this.min, this.max, this.desc);
double value = property.getDouble();
if (value < this.min)
{
value = this.min;
property.set(this.min);
}
if (value > this.max)
{
value = this.max;
property.set(this.max);
}
this.currentValue = value;
} }
public double getValue(){ public float getValue(){
return this.currentValue; return this.currentValue;
} }
} }

View file

@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.config.values;
import de.ellpeck.actuallyadditions.mod.config.ConfigCategories; import de.ellpeck.actuallyadditions.mod.config.ConfigCategories;
import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
public enum ConfigIntValues{ public enum ConfigIntValues{
@ -150,19 +149,7 @@ public enum ConfigIntValues{
} }
public void initializeValue(Configuration config){ public void initializeValue(Configuration config){
Property property = config.get(this.category, this.name, this.defaultValue, this.desc, this.min, this.max); this.currentValue = config.getInt(this.name, this.category, this.defaultValue, this.min, this.max, this.desc);
int value = property.getInt();
if (value < this.min)
{
value = this.min;
property.set(this.min);
}
if (value > this.max)
{
value = this.max;
property.set(this.max);
}
this.currentValue = value;
} }
public int getValue(){ public int getValue(){

View file

@ -13,7 +13,7 @@ package de.ellpeck.actuallyadditions.mod.items;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheColoredLampColors; import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheColoredLampColors;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigDoubleValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigFloatValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerDrill; import de.ellpeck.actuallyadditions.mod.inventory.ContainerDrill;
@ -271,37 +271,37 @@ public class ItemDrill extends ItemEnergy{
* @return The Energy use per Block * @return The Energy use per Block
*/ */
public int getEnergyUsePerBlock(ItemStack stack){ public int getEnergyUsePerBlock(ItemStack stack){
double energyToUse = ConfigIntValues.DRILL_ENERGY_USE.getValue(); float energyToUse = ConfigIntValues.DRILL_ENERGY_USE.getValue();
//Speed //Speed
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED)){ if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED)){
energyToUse *= ConfigDoubleValues.DRILL_SPEED_I_COST_MULTIPLIER.getValue(); energyToUse *= ConfigFloatValues.DRILL_SPEED_I_COST_MULTIPLIER.getValue();
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED_II)){ if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED_II)){
energyToUse *= ConfigDoubleValues.DRILL_SPEED_II_COST_MULTIPLIER.getValue(); energyToUse *= ConfigFloatValues.DRILL_SPEED_II_COST_MULTIPLIER.getValue();
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED_III)){ if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED_III)){
energyToUse *= ConfigDoubleValues.DRILL_SPEED_III_COST_MULTIPLIER.getValue(); energyToUse *= ConfigFloatValues.DRILL_SPEED_III_COST_MULTIPLIER.getValue();
} }
} }
} }
//Silk Touch //Silk Touch
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)){ if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)){
energyToUse *= ConfigDoubleValues.DRILL_SILK_TOUCH_COST_MULTIPLIER.getValue(); energyToUse *= ConfigFloatValues.DRILL_SILK_TOUCH_COST_MULTIPLIER.getValue();
} }
//Fortune //Fortune
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE)){ if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE)){
energyToUse *= ConfigDoubleValues.DRILL_FORTUNE_I_COST_MULTIPLIER.getValue(); energyToUse *= ConfigFloatValues.DRILL_FORTUNE_I_COST_MULTIPLIER.getValue();
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II)){ if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II)){
energyToUse *= ConfigDoubleValues.DRILL_FORTUNE_II_COST_MULTIPLIER.getValue(); energyToUse *= ConfigFloatValues.DRILL_FORTUNE_II_COST_MULTIPLIER.getValue();
} }
} }
//Size //Size
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){ if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){
energyToUse *= ConfigDoubleValues.DRILL_SIZE_3_COST_MULTIPLIER.getValue(); energyToUse *= ConfigFloatValues.DRILL_SIZE_3_COST_MULTIPLIER.getValue();
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){ if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){
energyToUse *= ConfigDoubleValues.DRILL_SIZE_5_COST_MULTIPLIER.getValue(); energyToUse *= ConfigFloatValues.DRILL_SIZE_5_COST_MULTIPLIER.getValue();
} }
} }