Refactored AEConfig (#2633)

Added a singleton getter instead the public field.
Reduced all fields to private.
Replaced field access with getters.
Added setters where necessary (Dimension/Biome Registration)
Added config options to disable more features.
Splitted Enum name from the config key.
Changed FacadeConfig and Networkhandler similar to AEConfig.init().
This commit is contained in:
yueh
2016-11-26 14:07:34 +01:00
committed by GitHub
parent 6554e295d5
commit a665200c31
105 changed files with 1022 additions and 645 deletions
+332 -80
View File
@@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.stream.Stream;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
@@ -52,73 +53,95 @@ import appeng.util.Platform;
public final class AEConfig extends Configuration implements IConfigurableObject, IConfigManagerHost
{
public static final double TUNNEL_POWER_LOSS = 0.05;
public static final String VERSION = "@version@";
public static final String CHANNEL = "@aechannel@";
public static final String PACKET_CHANNEL = "AE";
public static AEConfig instance;
public final IConfigManager settings = new ConfigManager( this );
public final EnumSet<AEFeature> featureFlags = EnumSet.noneOf( AEFeature.class );
public final int[] craftByStacks = { 1, 10, 100, 1000 };
public final int[] priorityByStacks = { 1, 10, 100, 1000 };
public final int[] levelByStacks = { 1, 10, 100, 1000 };
private final double WirelessHighWirelessCount = 64;
private final File configFile;
public int storageBiomeID = -1;
public int storageProviderID = -1;
public int formationPlaneEntityLimit = 128;
public float spawnChargedChance = 0.92f;
public int quartzOresPerCluster = 4;
public int quartzOresClusterAmount = 15;
public final int chargedChange = 4;
public int minMeteoriteDistance = 707;
public int minMeteoriteDistanceSq = this.minMeteoriteDistance * this.minMeteoriteDistance;
public double spatialPowerExponent = 1.35;
public double spatialPowerMultiplier = 1250.0;
public String[] grinderOres = {
// Vanilla Items
"Obsidian", "Ender", "EnderPearl", "Coal", "Iron", "Gold", "Charcoal", "NetherQuartz",
// Common Mod Ores
"Copper", "Tin", "Silver", "Lead", "Bronze",
// AE
"CertusQuartz", "Wheat", "Fluix",
// Other Mod Ores
"Brass", "Platinum", "Nickel", "Invar", "Aluminium", "Electrum", "Osmium", "Zinc" };
public double oreDoublePercentage = 90.0;
public boolean enableEffects = true;
public boolean useLargeFonts = false;
public boolean useColoredCraftingStatus;
public boolean removeCrashingItemsOnLoad = false;
public int wirelessTerminalBattery = 1600000;
public int entropyManipulatorBattery = 200000;
public int matterCannonBattery = 200000;
public int portableCellBattery = 20000;
public int colorApplicatorBattery = 20000;
public int chargedStaffBattery = 8000;
public boolean disableColoredCableRecipesInJEI = true;
public boolean updatable = false;
public double meteoriteClusterChance = 0.1;
public double meteoriteSpawnChance = 0.3;
public int[] meteoriteDimensionWhitelist = { 0 };
public int craftingCalculationTimePerTick = 5;
PowerUnits selectedPowerUnit = PowerUnits.AE;
private double WirelessBaseCost = 8;
private double WirelessCostMultiplier = 1;
private double WirelessTerminalDrainMultiplier = 1;
private double WirelessBaseRange = 16;
private double WirelessBoosterRangeMultiplier = 1;
private double WirelessBoosterExp = 1.5;
public AEConfig( final File configFile )
// Config instance
private static AEConfig instance;
// Default Grindstone ores
private static final String[] ORES_VANILLA = { "Obsidian", "Ender", "EnderPearl", "Coal", "Iron", "Gold", "Charcoal", "NetherQuartz" };
private static final String[] ORES_AE = { "CertusQuartz", "Wheat", "Fluix" };
private static final String[] ORES_COMMON = { "Copper", "Tin", "Silver", "Lead", "Bronze" };
private static final String[] ORES_MISC = { "Brass", "Platinum", "Nickel", "Invar", "Aluminium", "Electrum", "Osmium", "Zinc" };
// Default Energy Conversion Rates
private static final double DEFAULT_IC2_EXCHANGE = 2.0;
private static final double DEFAULT_RF_EXCHANGE = 0.5;
private final IConfigManager settings = new ConfigManager( this );
private final EnumSet<AEFeature> featureFlags = EnumSet.noneOf( AEFeature.class );
private final File configFile;
private boolean updatable = false;
// Misc
private boolean removeCrashingItemsOnLoad = false;
private int formationPlaneEntityLimit = 128;
private boolean enableEffects = true;
private boolean useLargeFonts = false;
private boolean useColoredCraftingStatus;
private boolean disableColoredCableRecipesInJEI = true;
private int craftingCalculationTimePerTick = 5;
private PowerUnits selectedPowerUnit = PowerUnits.AE;
// GUI Buttons
private final int[] craftByStacks = { 1, 10, 100, 1000 };
private final int[] priorityByStacks = { 1, 10, 100, 1000 };
private final int[] levelByStacks = { 1, 10, 100, 1000 };
// Spatial IO/Dimension
private int storageBiomeID = -1;
private int storageProviderID = -1;
private double spatialPowerExponent = 1.35;
private double spatialPowerMultiplier = 1250.0;
// Grindstone
private String[] grinderOres = Stream.of( ORES_VANILLA, ORES_AE, ORES_COMMON, ORES_MISC ).flatMap( Stream::of ).toArray( String[]::new );
private double oreDoublePercentage = 90.0;
// Batteries
private int wirelessTerminalBattery = 1600000;
private int entropyManipulatorBattery = 200000;
private int matterCannonBattery = 200000;
private int portableCellBattery = 20000;
private int colorApplicatorBattery = 20000;
private int chargedStaffBattery = 8000;
// Certus quartz
private float spawnChargedChance = 0.92f;
private int quartzOresPerCluster = 4;
private int quartzOresClusterAmount = 15;
private int chargedChange = 4;
// Meteors
private int minMeteoriteDistance = 707;
private int minMeteoriteDistanceSq = this.minMeteoriteDistance * this.minMeteoriteDistance;
private double meteoriteClusterChance = 0.1;
private int meteoriteMaximumSpawnHeight = 180;
private int[] meteoriteDimensionWhitelist = { 0 };
// Wireless
private double wirelessBaseCost = 8;
private double wirelessCostMultiplier = 1;
private double wirelessTerminalDrainMultiplier = 1;
private double wirelessBaseRange = 16;
private double wirelessBoosterRangeMultiplier = 1;
private double wirelessBoosterExp = 1.5;
private double wirelessHighWirelessCount = 64;
// Tunnels
public static final double TUNNEL_POWER_LOSS = 0.05;
private AEConfig( final File configFile )
{
super( configFile );
this.configFile = configFile;
MinecraftForge.EVENT_BUS.register( this );
final double DEFAULT_IC2_EXCHANGE = 2.0;
PowerUnits.EU.conversionRatio = this.get( "PowerRatios", "IC2", DEFAULT_IC2_EXCHANGE ).getDouble( DEFAULT_IC2_EXCHANGE );
final double DEFAULT_RF_EXCHANGE = 0.5;
PowerUnits.RF.conversionRatio = this.get( "PowerRatios", "Forge Energy", DEFAULT_RF_EXCHANGE ).getDouble( DEFAULT_RF_EXCHANGE );
final double usageEffective = this.get( "PowerRatios", "UsageMultiplier", 1.0 ).getDouble( 1.0 );
@@ -127,7 +150,8 @@ public final class AEConfig extends Configuration implements IConfigurableObject
CondenserOutput.MATTER_BALLS.requiredPower = this.get( "Condenser", "MatterBalls", 256 ).getInt( 256 );
CondenserOutput.SINGULARITY.requiredPower = this.get( "Condenser", "Singularity", 256000 ).getInt( 256000 );
this.removeCrashingItemsOnLoad = this.get( "general", "removeCrashingItemsOnLoad", false, "Will auto-remove items that crash when being loaded from storage. This will destroy those items instead of crashing the game!" ).getBoolean();
this.removeCrashingItemsOnLoad = this.get( "general", "removeCrashingItemsOnLoad", false,
"Will auto-remove items that crash when being loaded from storage. This will destroy those items instead of crashing the game!" ).getBoolean();
this.grinderOres = this.get( "GrindStone", "grinderOres", this.grinderOres ).getStringList();
this.oreDoublePercentage = this.get( "GrindStone", "oreDoublePercentage", this.oreDoublePercentage ).getDouble( this.oreDoublePercentage );
@@ -136,10 +160,12 @@ public final class AEConfig extends Configuration implements IConfigurableObject
this.settings.registerSetting( Settings.TERMINAL_STYLE, TerminalStyle.TALL );
this.settings.registerSetting( Settings.SEARCH_MODE, SearchBoxMode.AUTOSEARCH );
this.spawnChargedChance = (float) ( 1.0 - this.get( "worldGen", "spawnChargedChance", 1.0 - this.spawnChargedChance ).getDouble( 1.0 - this.spawnChargedChance ) );
this.spawnChargedChance = (float) ( 1.0 - this.get( "worldGen", "spawnChargedChance", 1.0 - this.spawnChargedChance ).getDouble(
1.0 - this.spawnChargedChance ) );
this.minMeteoriteDistance = this.get( "worldGen", "minMeteoriteDistance", this.minMeteoriteDistance ).getInt( this.minMeteoriteDistance );
this.meteoriteClusterChance = this.get( "worldGen", "meteoriteClusterChance", this.meteoriteClusterChance ).getDouble( this.meteoriteClusterChance );
this.meteoriteSpawnChance = this.get( "worldGen", "meteoriteSpawnChance", this.meteoriteSpawnChance ).getDouble( this.meteoriteSpawnChance );
this.meteoriteMaximumSpawnHeight = this.get( "worldGen", "meteoriteMaximumSpawnHeight", this.meteoriteMaximumSpawnHeight ).getInt(
this.meteoriteMaximumSpawnHeight );
this.meteoriteDimensionWhitelist = this.get( "worldGen", "meteoriteDimensionWhitelist", this.meteoriteDimensionWhitelist ).getIntList();
this.quartzOresPerCluster = this.get( "worldGen", "quartzOresPerCluster", this.quartzOresPerCluster ).getInt( this.quartzOresPerCluster );
@@ -147,16 +173,20 @@ public final class AEConfig extends Configuration implements IConfigurableObject
this.minMeteoriteDistanceSq = this.minMeteoriteDistance * this.minMeteoriteDistance;
this.addCustomCategoryComment( "wireless", "Range= WirelessBaseRange + WirelessBoosterRangeMultiplier * Math.pow( boosters, WirelessBoosterExp )\nPowerDrain= WirelessBaseCost + WirelessCostMultiplier * Math.pow( boosters, 1 + boosters / WirelessHighWirelessCount )" );
this.addCustomCategoryComment( "wireless",
"Range= wirelessBaseRange + wirelessBoosterRangeMultiplier * Math.pow( boosters, wirelessBoosterExp )\nPowerDrain= wirelessBaseCost + wirelessCostMultiplier * Math.pow( boosters, 1 + boosters / wirelessHighWirelessCount )" );
this.WirelessBaseCost = this.get( "wireless", "WirelessBaseCost", this.WirelessBaseCost ).getDouble( this.WirelessBaseCost );
this.WirelessCostMultiplier = this.get( "wireless", "WirelessCostMultiplier", this.WirelessCostMultiplier ).getDouble( this.WirelessCostMultiplier );
this.WirelessBaseRange = this.get( "wireless", "WirelessBaseRange", this.WirelessBaseRange ).getDouble( this.WirelessBaseRange );
this.WirelessBoosterRangeMultiplier = this.get( "wireless", "WirelessBoosterRangeMultiplier", this.WirelessBoosterRangeMultiplier ).getDouble( this.WirelessBoosterRangeMultiplier );
this.WirelessBoosterExp = this.get( "wireless", "WirelessBoosterExp", this.WirelessBoosterExp ).getDouble( this.WirelessBoosterExp );
this.WirelessTerminalDrainMultiplier = this.get( "wireless", "WirelessTerminalDrainMultiplier", this.WirelessTerminalDrainMultiplier ).getDouble( this.WirelessTerminalDrainMultiplier );
this.wirelessBaseCost = this.get( "wireless", "wirelessBaseCost", this.wirelessBaseCost ).getDouble( this.wirelessBaseCost );
this.wirelessCostMultiplier = this.get( "wireless", "wirelessCostMultiplier", this.wirelessCostMultiplier ).getDouble( this.wirelessCostMultiplier );
this.wirelessBaseRange = this.get( "wireless", "wirelessBaseRange", this.wirelessBaseRange ).getDouble( this.wirelessBaseRange );
this.wirelessBoosterRangeMultiplier = this.get( "wireless", "wirelessBoosterRangeMultiplier", this.wirelessBoosterRangeMultiplier ).getDouble(
this.wirelessBoosterRangeMultiplier );
this.wirelessBoosterExp = this.get( "wireless", "wirelessBoosterExp", this.wirelessBoosterExp ).getDouble( this.wirelessBoosterExp );
this.wirelessTerminalDrainMultiplier = this.get( "wireless", "wirelessTerminalDrainMultiplier", this.wirelessTerminalDrainMultiplier ).getDouble(
this.wirelessTerminalDrainMultiplier );
this.formationPlaneEntityLimit = this.get( "automation", "formationPlaneEntityLimit", this.formationPlaneEntityLimit ).getInt( this.formationPlaneEntityLimit );
this.formationPlaneEntityLimit = this.get( "automation", "formationPlaneEntityLimit", this.formationPlaneEntityLimit ).getInt(
this.formationPlaneEntityLimit );
this.wirelessTerminalBattery = this.get( "battery", "wirelessTerminal", this.wirelessTerminalBattery ).getInt( this.wirelessTerminalBattery );
this.chargedStaffBattery = this.get( "battery", "chargedStaff", this.chargedStaffBattery ).getInt( this.chargedStaffBattery );
@@ -171,7 +201,7 @@ public final class AEConfig extends Configuration implements IConfigurableObject
{
if( feature.isVisible() )
{
if( this.get( "Features." + feature.category, feature.name(), feature.defaultValue ).getBoolean( feature.defaultValue ) )
if( this.get( "Features." + feature.category(), feature.key(), feature.isEnabled() ).getBoolean( feature.isEnabled() ) )
{
this.featureFlags.add( feature );
}
@@ -188,13 +218,14 @@ public final class AEConfig extends Configuration implements IConfigurableObject
final List<String> version = Arrays.asList( "59.0.0", "59.0.1", "59.0.2" );
if( version.contains( imb.getVersion() ) )
{
this.featureFlags.remove( AEFeature.AlphaPass );
this.featureFlags.remove( AEFeature.ALPHA_PASS );
}
}
try
{
this.selectedPowerUnit = PowerUnits.valueOf( this.get( "Client", "PowerUnit", this.selectedPowerUnit.name(), this.getListComment( this.selectedPowerUnit ) ).getString() );
this.selectedPowerUnit = PowerUnits.valueOf(
this.get( "Client", "PowerUnit", this.selectedPowerUnit.name(), this.getListComment( this.selectedPowerUnit ) ).getString() );
}
catch( final Throwable t )
{
@@ -206,22 +237,34 @@ public final class AEConfig extends Configuration implements IConfigurableObject
tr.Load( this );
}
if( this.isFeatureEnabled( AEFeature.SpatialIO ) )
if( this.isFeatureEnabled( AEFeature.SPATIAL_IO ) )
{
this.storageBiomeID = this.get( "spatialio", "storageBiomeID", this.storageBiomeID ).getInt( this.storageBiomeID );
this.storageProviderID = this.get( "spatialio", "storageProviderID", this.storageProviderID ).getInt( this.storageProviderID );
this.spatialPowerMultiplier = this.get( "spatialio", "spatialPowerMultiplier", this.spatialPowerMultiplier ).getDouble( this.spatialPowerMultiplier );
this.spatialPowerMultiplier = this.get( "spatialio", "spatialPowerMultiplier", this.spatialPowerMultiplier ).getDouble(
this.spatialPowerMultiplier );
this.spatialPowerExponent = this.get( "spatialio", "spatialPowerExponent", this.spatialPowerExponent ).getDouble( this.spatialPowerExponent );
}
if( this.isFeatureEnabled( AEFeature.CraftingCPU ) )
if( this.isFeatureEnabled( AEFeature.CRAFTING_CPU ) )
{
this.craftingCalculationTimePerTick = this.get( "craftingCPU", "craftingCalculationTimePerTick", this.craftingCalculationTimePerTick ).getInt( this.craftingCalculationTimePerTick );
this.craftingCalculationTimePerTick = this.get( "craftingCPU", "craftingCalculationTimePerTick", this.craftingCalculationTimePerTick ).getInt(
this.craftingCalculationTimePerTick );
}
this.updatable = true;
}
public static void init( final File configFile )
{
instance = new AEConfig( configFile );
}
public static AEConfig instance()
{
return instance;
}
private void clientSync()
{
this.disableColoredCableRecipesInJEI = this.get( "Client", "disableColoredCableRecipesInJEI", true ).getBoolean( true );
@@ -308,17 +351,17 @@ public final class AEConfig extends Configuration implements IConfigurableObject
public double wireless_getDrainRate( final double range )
{
return this.WirelessTerminalDrainMultiplier * range;
return this.wirelessTerminalDrainMultiplier * range;
}
public double wireless_getMaxRange( final int boosters )
{
return this.WirelessBaseRange + this.WirelessBoosterRangeMultiplier * Math.pow( boosters, this.WirelessBoosterExp );
return this.wirelessBaseRange + this.wirelessBoosterRangeMultiplier * Math.pow( boosters, this.wirelessBoosterExp );
}
public double wireless_getPowerDrain( final int boosters )
{
return this.WirelessBaseCost + this.WirelessCostMultiplier * Math.pow( boosters, 1 + boosters / this.WirelessHighWirelessCount );
return this.wirelessBaseCost + this.wirelessCostMultiplier * Math.pow( boosters, 1 + boosters / this.wirelessHighWirelessCount );
}
@Override
@@ -340,7 +383,7 @@ public final class AEConfig extends Configuration implements IConfigurableObject
@Override
public void save()
{
if( this.isFeatureEnabled( AEFeature.SpatialIO ) )
if( this.isFeatureEnabled( AEFeature.SPATIAL_IO ) )
{
this.get( "spatialio", "storageBiomeID", this.storageBiomeID ).set( this.storageBiomeID );
this.get( "spatialio", "storageProviderID", this.storageProviderID ).set( this.storageProviderID );
@@ -375,12 +418,13 @@ public final class AEConfig extends Configuration implements IConfigurableObject
public boolean useAEVersion( final MaterialType mt )
{
if( this.isFeatureEnabled( AEFeature.WebsiteRecipes ) )
if( this.isFeatureEnabled( AEFeature.WEBSITE_RECIPES ) )
{
return true;
}
this.setCategoryComment( "OreCamouflage", "AE2 Automatically uses alternative ores present in your instance of MC to blend better with its surroundings, if you prefer you can disable this selectively using these flags; Its important to note, that some if these items even if enabled may not be craftable in game because other items are overriding their recipes." );
this.setCategoryComment( "OreCamouflage",
"AE2 Automatically uses alternative ores present in your instance of MC to blend better with its surroundings, if you prefer you can disable this selectively using these flags; Its important to note, that some if these items even if enabled may not be craftable in game because other items are overriding their recipes." );
final Property p = this.get( "OreCamouflage", mt.name(), true );
p.setComment( "OreDictionary Names: " + mt.getOreName() );
@@ -506,4 +550,212 @@ public final class AEConfig extends Configuration implements IConfigurableObject
this.selectedPowerUnit = Platform.rotateEnum( this.selectedPowerUnit, backwards, Settings.POWER_UNITS.getPossibleValues() );
this.save();
}
// Getters
public boolean isRemoveCrashingItemsOnLoad()
{
return removeCrashingItemsOnLoad;
}
public int getFormationPlaneEntityLimit()
{
return formationPlaneEntityLimit;
}
public boolean isEnableEffects()
{
return enableEffects;
}
public boolean isUseLargeFonts()
{
return useLargeFonts;
}
public boolean isUseColoredCraftingStatus()
{
return useColoredCraftingStatus;
}
public boolean isDisableColoredCableRecipesInJEI()
{
return disableColoredCableRecipesInJEI;
}
public int getCraftingCalculationTimePerTick()
{
return craftingCalculationTimePerTick;
}
public PowerUnits getSelectedPowerUnit()
{
return selectedPowerUnit;
}
public int[] getCraftByStacks()
{
return craftByStacks;
}
public int[] getPriorityByStacks()
{
return priorityByStacks;
}
public int[] getLevelByStacks()
{
return levelByStacks;
}
public int getStorageBiomeID()
{
return storageBiomeID;
}
public int getStorageProviderID()
{
return storageProviderID;
}
public double getSpatialPowerExponent()
{
return spatialPowerExponent;
}
public double getSpatialPowerMultiplier()
{
return spatialPowerMultiplier;
}
public String[] getGrinderOres()
{
return grinderOres;
}
public double getOreDoublePercentage()
{
return oreDoublePercentage;
}
public int getWirelessTerminalBattery()
{
return wirelessTerminalBattery;
}
public int getEntropyManipulatorBattery()
{
return entropyManipulatorBattery;
}
public int getMatterCannonBattery()
{
return matterCannonBattery;
}
public int getPortableCellBattery()
{
return portableCellBattery;
}
public int getColorApplicatorBattery()
{
return colorApplicatorBattery;
}
public int getChargedStaffBattery()
{
return chargedStaffBattery;
}
public float getSpawnChargedChance()
{
return spawnChargedChance;
}
public int getQuartzOresPerCluster()
{
return quartzOresPerCluster;
}
public int getQuartzOresClusterAmount()
{
return quartzOresClusterAmount;
}
public int getChargedChange()
{
return chargedChange;
}
public int getMinMeteoriteDistance()
{
return minMeteoriteDistance;
}
public int getMinMeteoriteDistanceSq()
{
return minMeteoriteDistanceSq;
}
public double getMeteoriteClusterChance()
{
return meteoriteClusterChance;
}
public int getMeteoriteMaximumSpawnHeight()
{
return meteoriteMaximumSpawnHeight;
}
public int[] getMeteoriteDimensionWhitelist()
{
return meteoriteDimensionWhitelist;
}
public double getWirelessBaseCost()
{
return wirelessBaseCost;
}
public double getWirelessCostMultiplier()
{
return wirelessCostMultiplier;
}
public double getWirelessTerminalDrainMultiplier()
{
return wirelessTerminalDrainMultiplier;
}
public double getWirelessBaseRange()
{
return wirelessBaseRange;
}
public double getWirelessBoosterRangeMultiplier()
{
return wirelessBoosterRangeMultiplier;
}
public double getWirelessBoosterExp()
{
return wirelessBoosterExp;
}
public double getWirelessHighWirelessCount()
{
return wirelessHighWirelessCount;
}
// Setters keep visibility as low as possible.
void setStorageBiomeID( int id )
{
this.storageBiomeID = id;
}
void setStorageProviderID( int id )
{
this.storageProviderID = id;
}
}