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 );
}
}
}
}
+32 -16
View File
@@ -69,7 +69,6 @@ import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
@@ -95,6 +94,9 @@ import appeng.api.config.PowerUnits;
import appeng.api.config.SearchBoxMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.SortOrder;
import appeng.api.definitions.IItemDefinition;
import appeng.api.definitions.IMaterials;
import appeng.api.definitions.IParts;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.implementations.items.IAEWrench;
import appeng.api.implementations.tiles.ITileStorageMonitorable;
@@ -118,7 +120,6 @@ import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IAETagCompound;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEColor;
import appeng.api.util.AEItemDefinition;
import appeng.api.util.DimensionalCoord;
import appeng.core.AEConfig;
import appeng.core.AELog;
@@ -1007,10 +1008,7 @@ public class Platform
return null; // wtf?
}
public static boolean blockAtLocationIs(IBlockAccess w, int x, int y, int z, AEItemDefinition def)
{
return def.block() == w.getBlock( x, y, z );
}
public static ForgeDirection rotateAround(ForgeDirection forward, ForgeDirection axis)
{
@@ -1134,9 +1132,9 @@ public class Platform
return false;
}
public static boolean isSameItem(ItemStack ol, ItemStack op)
public static boolean isSameItem(ItemStack left, ItemStack right)
{
return ol != null && op != null && ol.isItemEqual( op );
return left != null && right != null && left.isItemEqual( right );
}
public static ItemStack cloneItemStack(ItemStack a)
@@ -1765,7 +1763,11 @@ public class Platform
return false;
if ( type == AEFeature.CertusQuartzTools )
return AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( b );
{
final IItemDefinition certusQuartzCrystal = AEApi.instance().definitions().materials().certusQuartzCrystal();
return certusQuartzCrystal.isSameAs( b );
}
if ( type == AEFeature.NetherQuartzTools )
return Items.quartz == b.getItem();
@@ -1775,19 +1777,29 @@ public class Platform
public static Object findPreferred(ItemStack[] is)
{
final IParts parts = AEApi.instance().definitions().parts();
for (ItemStack stack : is)
{
if ( AEApi.instance().parts().partCableGlass.sameAs( AEColor.Transparent, stack ) )
if ( parts.cableGlass().sameAs( AEColor.Transparent, stack ) )
{
return stack;
}
if ( AEApi.instance().parts().partCableCovered.sameAs( AEColor.Transparent, stack ) )
if ( parts.cableCovered().sameAs( AEColor.Transparent, stack ) )
{
return stack;
}
if ( AEApi.instance().parts().partCableSmart.sameAs( AEColor.Transparent, stack ) )
if ( parts.cableSmart().sameAs( AEColor.Transparent, stack ) )
{
return stack;
}
if ( AEApi.instance().parts().partCableDense.sameAs( AEColor.Transparent, stack ) )
if ( parts.cableDense().sameAs( AEColor.Transparent, stack ) )
{
return stack;
}
}
return is;
@@ -1875,8 +1887,12 @@ public class Platform
public static boolean isRecipePrioritized(ItemStack what)
{
return AEApi.instance().materials().materialPurifiedCertusQuartzCrystal.sameAsStack( what )
|| AEApi.instance().materials().materialPurifiedFluixCrystal.sameAsStack( what )
|| AEApi.instance().materials().materialPurifiedNetherQuartzCrystal.sameAsStack( what );
final IMaterials materials = AEApi.instance().definitions().materials();
boolean isPurified = materials.purifiedCertusQuartzCrystal().isSameAs( what );
isPurified |= materials.purifiedFluixCrystal().isSameAs( what );
isPurified |= materials.purifiedNetherQuartzCrystal().isSameAs( what );
return isPurified;
}
}
@@ -40,6 +40,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IAETagCompound;
import appeng.util.Platform;
@@ -113,13 +114,14 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
this.def.isOre = OreHelper.INSTANCE.isOre( is );
}
public static AEItemStack create(Object a)
public static AEItemStack create( ItemStack stack )
{
if ( a instanceof ItemStack )
return new AEItemStack( (ItemStack) a );
if ( a instanceof IAEItemStack )
((IAEItemStack) a).copy();
return null;
return new AEItemStack( stack );
}
public static IAEStack<IAEItemStack> create( IAEStack<IAEItemStack> stack )
{
return stack.copy();
}
@Override