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:
@@ -19,7 +19,6 @@
|
||||
package appeng.items.materials;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -27,12 +26,11 @@ import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -49,70 +47,45 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.implementations.items.IItemGroup;
|
||||
import appeng.api.implementations.items.IStorageComponent;
|
||||
import appeng.api.implementations.items.IUpgradeModule;
|
||||
import appeng.api.implementations.tiles.ISegmentedInventory;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.client.texture.MissingIcon;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.AEFeatureHandler;
|
||||
import appeng.core.features.IStackSrc;
|
||||
import appeng.core.features.MaterialStackSrc;
|
||||
import appeng.core.features.NameResolver;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
|
||||
{
|
||||
|
||||
final HashMap<Integer, MaterialType> dmgToMaterial = new HashMap<Integer, MaterialType>();
|
||||
|
||||
public static final int KILO = 1024;
|
||||
public static ItemMultiMaterial instance;
|
||||
|
||||
public ItemMultiMaterial() {
|
||||
super( ItemMultiMaterial.class );
|
||||
private final Map<Integer, MaterialType> dmgToMaterial = new HashMap<Integer, MaterialType>();
|
||||
private final NameResolver nameResolver;
|
||||
|
||||
public ItemMultiMaterial()
|
||||
{
|
||||
this.nameResolver = new NameResolver( this.getClass() );
|
||||
this.setFeature( EnumSet.of( AEFeature.Core ) );
|
||||
this.setHasSubtypes( true );
|
||||
instance = this;
|
||||
}
|
||||
|
||||
static class SlightlyBetterSort implements Comparator<String>
|
||||
{
|
||||
|
||||
final Pattern p;
|
||||
|
||||
public SlightlyBetterSort(Pattern p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(String o1, String o2)
|
||||
{
|
||||
try
|
||||
{
|
||||
Matcher a = this.p.matcher( o1 );
|
||||
Matcher b = this.p.matcher( o2 );
|
||||
if ( a.find() && b.find() )
|
||||
{
|
||||
int ia = Integer.parseInt( a.group( 1 ) );
|
||||
int ib = Integer.parseInt( b.group( 1 ) );
|
||||
return Integer.compare( ia, ib );
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ek!
|
||||
}
|
||||
return o1.compareTo( o2 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCheckedInformation(ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
|
||||
public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
|
||||
{
|
||||
super.addCheckedInformation( stack, player, lines, displayAdditionalInformation );
|
||||
|
||||
@@ -130,7 +103,7 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
if ( u != null )
|
||||
{
|
||||
List<String> textList = new LinkedList<String>();
|
||||
for (Entry<ItemStack, Integer> j : u.getSupported().entrySet())
|
||||
for ( Entry<ItemStack, Integer> j : u.getSupported().entrySet() )
|
||||
{
|
||||
String name = null;
|
||||
|
||||
@@ -141,11 +114,11 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
IItemGroup ig = (IItemGroup) j.getKey().getItem();
|
||||
String str = ig.getUnlocalizedGroupName( u.getSupported().keySet(), j.getKey() );
|
||||
if ( str != null )
|
||||
name = Platform.gui_localize( str ) + (limit > 1 ? " (" + limit + ')' : "");
|
||||
name = Platform.gui_localize( str ) + ( limit > 1 ? " (" + limit + ')' : "" );
|
||||
}
|
||||
|
||||
if ( name == null )
|
||||
name = j.getKey().getDisplayName() + (limit > 1 ? " (" + limit + ')' : "");
|
||||
name = j.getKey().getDisplayName() + ( limit > 1 ? " (" + limit + ')' : "" );
|
||||
|
||||
if ( !textList.contains( name ) )
|
||||
textList.add( name );
|
||||
@@ -158,12 +131,41 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
}
|
||||
}
|
||||
|
||||
public IStackSrc createMaterial(MaterialType mat)
|
||||
public MaterialType getTypeByStack( ItemStack is )
|
||||
{
|
||||
if ( this.dmgToMaterial.containsKey( is.getItemDamage() ) )
|
||||
return this.dmgToMaterial.get( is.getItemDamage() );
|
||||
return MaterialType.InvalidType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Upgrades getType( ItemStack itemstack )
|
||||
{
|
||||
switch ( this.getTypeByStack( itemstack ) )
|
||||
{
|
||||
case CardCapacity:
|
||||
return Upgrades.CAPACITY;
|
||||
case CardFuzzy:
|
||||
return Upgrades.FUZZY;
|
||||
case CardRedstone:
|
||||
return Upgrades.REDSTONE;
|
||||
case CardSpeed:
|
||||
return Upgrades.SPEED;
|
||||
case CardInverter:
|
||||
return Upgrades.INVERTER;
|
||||
case CardCrafting:
|
||||
return Upgrades.CRAFTING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IStackSrc createMaterial( MaterialType mat )
|
||||
{
|
||||
if ( !mat.isRegistered() )
|
||||
{
|
||||
boolean enabled = true;
|
||||
for (AEFeature f : mat.getFeature())
|
||||
for ( AEFeature f : mat.getFeature() )
|
||||
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
|
||||
|
||||
if ( enabled )
|
||||
@@ -172,17 +174,17 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
int newMaterialNum = mat.damageValue;
|
||||
mat.markReady();
|
||||
|
||||
IStackSrc output = mat.stackSrc = new MaterialStackSrc( mat );
|
||||
mat.stackSrc = new MaterialStackSrc( mat );
|
||||
|
||||
if ( this.dmgToMaterial.get( newMaterialNum ) == null )
|
||||
this.dmgToMaterial.put( newMaterialNum, mat );
|
||||
else
|
||||
throw new RuntimeException( "Meta Overlap detected." );
|
||||
|
||||
return output;
|
||||
return mat.stackSrc;
|
||||
}
|
||||
|
||||
return null;
|
||||
return mat.stackSrc;
|
||||
}
|
||||
else
|
||||
throw new RuntimeException( "Cannot create the same material twice..." );
|
||||
@@ -190,7 +192,7 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
|
||||
public void makeUnique()
|
||||
{
|
||||
for (MaterialType mt : ImmutableSet.copyOf( this.dmgToMaterial.values() ))
|
||||
for ( MaterialType mt : ImmutableSet.copyOf( this.dmgToMaterial.values() ) )
|
||||
{
|
||||
if ( mt.getOreName() != null )
|
||||
{
|
||||
@@ -198,15 +200,15 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
|
||||
String[] names = mt.getOreName().split( "," );
|
||||
|
||||
for (String name : names)
|
||||
for ( String name : names )
|
||||
{
|
||||
if ( replacement != null )
|
||||
break;
|
||||
|
||||
ArrayList<ItemStack> options = OreDictionary.getOres( name );
|
||||
List<ItemStack> options = OreDictionary.getOres( name );
|
||||
if ( options != null && options.size() > 0 )
|
||||
{
|
||||
for (ItemStack is : options)
|
||||
for ( ItemStack is : options )
|
||||
{
|
||||
if ( is != null && is.getItem() != null )
|
||||
{
|
||||
@@ -220,7 +222,7 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
if ( replacement == null || AEConfig.instance.useAEVersion( mt ) )
|
||||
{
|
||||
// continue using the AE2 item.
|
||||
for (String name : names)
|
||||
for ( String name : names )
|
||||
OreDictionary.registerOre( name, mt.stack( 1 ) );
|
||||
}
|
||||
else
|
||||
@@ -231,27 +233,25 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
mt.itemInstance = replacement.getItem();
|
||||
mt.damageValue = replacement.getItemDamage();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MaterialType getTypeByStack(ItemStack is)
|
||||
{
|
||||
if ( this.dmgToMaterial.containsKey( is.getItemDamage() ) )
|
||||
return this.dmgToMaterial.get( is.getItemDamage() );
|
||||
return MaterialType.InvalidType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconFromDamage(int dmg)
|
||||
public IIcon getIconFromDamage( int dmg )
|
||||
{
|
||||
if ( this.dmgToMaterial.containsKey( dmg ) )
|
||||
return this.dmgToMaterial.get( dmg ).IIcon;
|
||||
return new MissingIcon( this );
|
||||
}
|
||||
|
||||
private String nameOf(ItemStack is)
|
||||
@Override
|
||||
public String getUnlocalizedName( ItemStack is )
|
||||
{
|
||||
return "item.appliedenergistics2." + this.nameOf( is );
|
||||
}
|
||||
|
||||
private String nameOf( ItemStack is )
|
||||
{
|
||||
if ( is == null )
|
||||
return "null";
|
||||
@@ -260,19 +260,34 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
if ( mt == null )
|
||||
return "null";
|
||||
|
||||
return AEFeatureHandler.getName( ItemMultiMaterial.class, mt.name() );
|
||||
return this.nameResolver.getName( mt.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack is)
|
||||
public void getSubItems( Item par1, CreativeTabs par2CreativeTabs, List cList )
|
||||
{
|
||||
return "item.appliedenergistics2." + this.nameOf( is );
|
||||
List<MaterialType> types = Arrays.asList( MaterialType.values() );
|
||||
Collections.sort( types, new Comparator<MaterialType>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare( MaterialType o1, MaterialType o2 )
|
||||
{
|
||||
return o1.name().compareTo( o2.name() );
|
||||
}
|
||||
} );
|
||||
|
||||
for ( MaterialType mat : types )
|
||||
{
|
||||
if ( mat.damageValue >= 0 && mat.isRegistered() && mat.itemInstance == this )
|
||||
cList.add( new ItemStack( this, 1, mat.damageValue ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister icoRegister)
|
||||
public void registerIcons( IIconRegister icoRegister )
|
||||
{
|
||||
for (MaterialType mat : MaterialType.values())
|
||||
for ( MaterialType mat : MaterialType.values() )
|
||||
{
|
||||
if ( mat.damageValue != -1 )
|
||||
{
|
||||
@@ -287,94 +302,7 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomEntity(ItemStack is)
|
||||
{
|
||||
return this.getTypeByStack( is ).hasCustomEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity createEntity(World w, Entity location, ItemStack itemstack)
|
||||
{
|
||||
Class<? extends Entity> droppedEntity = this.getTypeByStack( itemstack ).getCustomEntityClass();
|
||||
Entity eqi;
|
||||
|
||||
try
|
||||
{
|
||||
eqi = droppedEntity.getConstructor( World.class, double.class, double.class, double.class, ItemStack.class ).newInstance( w, location.posX,
|
||||
location.posY, location.posZ, itemstack );
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
throw new RuntimeException( t );
|
||||
}
|
||||
|
||||
eqi.motionX = location.motionX;
|
||||
eqi.motionY = location.motionY;
|
||||
eqi.motionZ = location.motionZ;
|
||||
|
||||
if ( location instanceof EntityItem && eqi instanceof EntityItem )
|
||||
((EntityItem) eqi).delayBeforeCanPickup = ((EntityItem) location).delayBeforeCanPickup;
|
||||
|
||||
return eqi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes(ItemStack is)
|
||||
{
|
||||
switch (this.getTypeByStack( is ))
|
||||
{
|
||||
case Cell1kPart:
|
||||
return 1024;
|
||||
case Cell4kPart:
|
||||
return 1024 * 4;
|
||||
case Cell16kPart:
|
||||
return 1024 * 16;
|
||||
case Cell64kPart:
|
||||
return 1024 * 64;
|
||||
default:
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageComponent(ItemStack is)
|
||||
{
|
||||
switch (this.getTypeByStack( is ))
|
||||
{
|
||||
case Cell1kPart:
|
||||
case Cell4kPart:
|
||||
case Cell16kPart:
|
||||
case Cell64kPart:
|
||||
return true;
|
||||
default:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Upgrades getType(ItemStack itemstack)
|
||||
{
|
||||
switch (this.getTypeByStack( itemstack ))
|
||||
{
|
||||
case CardCapacity:
|
||||
return Upgrades.CAPACITY;
|
||||
case CardFuzzy:
|
||||
return Upgrades.FUZZY;
|
||||
case CardRedstone:
|
||||
return Upgrades.REDSTONE;
|
||||
case CardSpeed:
|
||||
return Upgrades.SPEED;
|
||||
case CardInverter:
|
||||
return Upgrades.INVERTER;
|
||||
case CardCrafting:
|
||||
return Upgrades.CRAFTING;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
public boolean onItemUseFirst( ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
if ( player.isSneaking() )
|
||||
{
|
||||
@@ -383,12 +311,12 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
|
||||
if ( te instanceof IPartHost )
|
||||
{
|
||||
SelectedPart sp = ((IPartHost) te).selectPart( Vec3.createVectorHelper( hitX, hitY, hitZ ) );
|
||||
SelectedPart sp = ( (IPartHost) te ).selectPart( Vec3.createVectorHelper( hitX, hitY, hitZ ) );
|
||||
if ( sp.part instanceof IUpgradeableHost )
|
||||
upgrades = ((IUpgradeableHost) sp.part).getInventoryByName( "upgrades" );
|
||||
upgrades = ( (ISegmentedInventory) sp.part ).getInventoryByName( "upgrades" );
|
||||
}
|
||||
else if ( te instanceof IUpgradeableHost )
|
||||
upgrades = ((IUpgradeableHost) te).getInventoryByName( "upgrades" );
|
||||
upgrades = ( (ISegmentedInventory) te ).getInventoryByName( "upgrades" );
|
||||
|
||||
if ( upgrades != null && is != null && is.getItem() instanceof IUpgradeModule )
|
||||
{
|
||||
@@ -414,23 +342,97 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List cList)
|
||||
public boolean hasCustomEntity( ItemStack is )
|
||||
{
|
||||
List<MaterialType> types = Arrays.asList( MaterialType.values() );
|
||||
Collections.sort( types, new Comparator<MaterialType>() {
|
||||
return this.getTypeByStack( is ).hasCustomEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(MaterialType o1, MaterialType o2)
|
||||
{
|
||||
return o1.name().compareTo( o2.name() );
|
||||
}
|
||||
@Override
|
||||
public Entity createEntity( World w, Entity location, ItemStack itemstack )
|
||||
{
|
||||
Class<? extends Entity> droppedEntity = this.getTypeByStack( itemstack ).getCustomEntityClass();
|
||||
Entity eqi;
|
||||
|
||||
} );
|
||||
|
||||
for (MaterialType mat : types)
|
||||
try
|
||||
{
|
||||
if ( mat.damageValue >= 0 && mat.isRegistered() && mat.itemInstance == this )
|
||||
cList.add( new ItemStack( this, 1, mat.damageValue ) );
|
||||
eqi = droppedEntity.getConstructor( World.class, double.class, double.class, double.class, ItemStack.class ).newInstance( w, location.posX, location.posY, location.posZ, itemstack );
|
||||
}
|
||||
catch ( Throwable t )
|
||||
{
|
||||
throw new RuntimeException( t );
|
||||
}
|
||||
|
||||
eqi.motionX = location.motionX;
|
||||
eqi.motionY = location.motionY;
|
||||
eqi.motionZ = location.motionZ;
|
||||
|
||||
if ( location instanceof EntityItem && eqi instanceof EntityItem )
|
||||
( (EntityItem) eqi ).delayBeforeCanPickup = ( (EntityItem) location ).delayBeforeCanPickup;
|
||||
|
||||
return eqi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes( ItemStack is )
|
||||
{
|
||||
switch ( this.getTypeByStack( is ) )
|
||||
{
|
||||
case Cell1kPart:
|
||||
return KILO;
|
||||
case Cell4kPart:
|
||||
return KILO * 4;
|
||||
case Cell16kPart:
|
||||
return KILO * 16;
|
||||
case Cell64kPart:
|
||||
return KILO * 64;
|
||||
default:
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageComponent( ItemStack is )
|
||||
{
|
||||
switch ( this.getTypeByStack( is ) )
|
||||
{
|
||||
case Cell1kPart:
|
||||
case Cell4kPart:
|
||||
case Cell16kPart:
|
||||
case Cell64kPart:
|
||||
return true;
|
||||
default:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class SlightlyBetterSort implements Comparator<String>
|
||||
{
|
||||
private final Pattern pattern;
|
||||
|
||||
public SlightlyBetterSort( Pattern pattern )
|
||||
{
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare( String o1, String o2 )
|
||||
{
|
||||
try
|
||||
{
|
||||
Matcher a = this.pattern.matcher( o1 );
|
||||
Matcher b = this.pattern.matcher( o2 );
|
||||
if ( a.find() && b.find() )
|
||||
{
|
||||
int ia = Integer.parseInt( a.group( 1 ) );
|
||||
int ib = Integer.parseInt( b.group( 1 ) );
|
||||
return Integer.compare( ia, ib );
|
||||
}
|
||||
}
|
||||
catch ( Throwable t )
|
||||
{
|
||||
// ek!
|
||||
}
|
||||
return o1.compareTo( o2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user