Fixes #675 No disabled feature should log spam or crash anymore.

Deprecates the old usage of the AEItemDefinitions via the direct method access of

* blocks()
* parts()
* items()
* materials()

and thus use the new re-direct via definitions().

All definitions are now initialized, no matter what. But SubItems, Items and Blocks are not registered, if by chance are disabled.
This commit is contained in:
thatsIch
2015-01-03 02:53:14 +01:00
parent 3dd81433ac
commit 9986ffc458
385 changed files with 12477 additions and 8292 deletions
+73 -68
View File
@@ -18,95 +18,46 @@
package appeng.util;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Map;
import java.util.Set;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.config.LevelEmitterMode;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.util.IConfigManager;
import appeng.core.AELog;
public class ConfigManager implements IConfigManager
public final class ConfigManager implements IConfigManager
{
private final Map<Settings, Enum<?>> settings = new EnumMap<Settings, Enum<?>>( Settings.class );
private final IConfigManagerHost target;
final HashMap<Enum, Enum> Settings = new HashMap<Enum, Enum>();
final IConfigManagerHost target;
public ConfigManager(IConfigManagerHost tile) {
public ConfigManager( IConfigManagerHost tile )
{
this.target = tile;
}
/**
* read all settings using config manager.
*
* @param tagCompound to be read from compound
*/
@Override
public void readFromNBT(NBTTagCompound tagCompound)
public Set<Settings> getSettings()
{
for (Enum key : this.Settings.keySet())
{
try
{
if ( tagCompound.hasKey( key.name() ) )
{
String value = tagCompound.getString( key.name() );
// Provides an upgrade path for the rename of this value in the API between rv1 and rv2
if( value.equals( "EXTACTABLE_ONLY" ) ){
value = StorageFilter.EXTRACTABLE_ONLY.toString();
} else if( value.equals( "STOREABLE_AMOUNT" ) ) {
value = LevelEmitterMode.STORABLE_AMOUNT.toString();
}
Enum oldValue = this.Settings.get( key );
Enum newValue = Enum.valueOf( oldValue.getClass(), value );
this.putSetting( key, newValue );
}
}
catch (IllegalArgumentException e)
{
AELog.error( e );
}
}
}
/**
* save all settings using config manager.
*
* @param destination to be written to compound
*/
@Override
public void writeToNBT(NBTTagCompound destination )
{
for (Enum e : this.Settings.keySet())
{
destination.setString( e.name(), this.Settings.get( e ).toString() );
}
return this.settings.keySet();
}
@Override
public Set<Enum> getSettings()
public void registerSetting( Settings settingName, Enum defaultValue )
{
return this.Settings.keySet();
this.settings.put( settingName, defaultValue );
}
@Override
public void registerSetting(Enum settingName, Enum defaultValue)
public Enum<?> getSetting( Settings settingName )
{
this.Settings.put( settingName, defaultValue );
}
@Override
public Enum getSetting(Enum settingName)
{
Enum oldValue = this.Settings.get( settingName );
Enum<?> oldValue = this.settings.get( settingName );
if ( oldValue != null )
return oldValue;
@@ -115,12 +66,66 @@ public class ConfigManager implements IConfigManager
}
@Override
public Enum putSetting(Enum settingName, Enum newValue)
public Enum<?> putSetting( Settings settingName, Enum newValue )
{
Enum oldValue = this.getSetting( settingName );
this.Settings.put( settingName, newValue );
Enum<?> oldValue = this.getSetting( settingName );
this.settings.put( settingName, newValue );
this.target.updateSetting( this, settingName, newValue );
return oldValue;
}
/**
* save all settings using config manager.
*
* @param tagCompound to be written to compound
*/
@Override
public void writeToNBT( NBTTagCompound tagCompound )
{
for ( Settings setting : this.settings.keySet() )
{
tagCompound.setString( setting.name(), this.settings.get( setting ).toString() );
}
}
/**
* read all settings using config manager.
*
* @param tagCompound to be read from compound
*/
@Override
public void readFromNBT( NBTTagCompound tagCompound )
{
for ( Settings key : this.settings.keySet() )
{
try
{
if ( tagCompound.hasKey( key.name() ) )
{
String value = tagCompound.getString( key.name() );
// Provides an upgrade path for the rename of this value in the API between rv1 and rv2
if ( value.equals( "EXTACTABLE_ONLY" ) )
{
value = StorageFilter.EXTRACTABLE_ONLY.toString();
}
else if ( value.equals( "STOREABLE_AMOUNT" ) )
{
value = LevelEmitterMode.STORABLE_AMOUNT.toString();
}
Enum<?> oldValue = this.settings.get( key );
Enum<?> newValue = Enum.valueOf( oldValue.getClass(), value );
this.putSetting( key, newValue );
}
}
catch ( IllegalArgumentException e )
{
AELog.error( e );
}
}
}
}