Add resistance to MultiItems to prevent crashes from invalid stacks.

This commit is contained in:
AlgorithmX2
2014-06-04 00:07:36 -05:00
parent 286baaa0a5
commit f894d48328
4 changed files with 39 additions and 25 deletions
+34 -24
View File
@@ -209,12 +209,17 @@ public class Registration
{
try
{
Field f = materialClass.getField( "material" + mat.name() );
ItemStackSrc is = ((ItemMultiMaterial) materialItem.item()).createMaterial( mat );
if ( is != null )
f.set( materials, new DamagedItemDefinition( is ) );
if ( mat == MaterialType.InvalidType )
((ItemMultiMaterial) materialItem.item()).createMaterial( mat );
else
f.set( materials, new NullItemDefinition() );
{
Field f = materialClass.getField( "material" + mat.name() );
ItemStackSrc is = ((ItemMultiMaterial) materialItem.item()).createMaterial( mat );
if ( is != null )
f.set( materials, new DamagedItemDefinition( is ) );
else
f.set( materials, new NullItemDefinition() );
}
}
catch (Throwable err)
{
@@ -230,30 +235,35 @@ public class Registration
{
try
{
Field f = partClass.getField( "part" + type.name() );
Enum varients[] = type.getVarients();
if ( varients == null )
{
ItemStackSrc is = ((ItemMultiPart) partItem.item()).createPart( type, null );
if ( is != null )
f.set( parts, new DamagedItemDefinition( is ) );
else
f.set( parts, new NullItemDefinition() );
}
if ( type == PartType.InvalidType )
((ItemMultiPart) partItem.item()).createPart( type, null );
else
{
if ( varients[0] instanceof AEColor )
Field f = partClass.getField( "part" + type.name() );
Enum varients[] = type.getVarients();
if ( varients == null )
{
ColoredItemDefinition def = new ColoredItemDefinition();
for (Enum v : varients)
ItemStackSrc is = ((ItemMultiPart) partItem.item()).createPart( type, null );
if ( is != null )
f.set( parts, new DamagedItemDefinition( is ) );
else
f.set( parts, new NullItemDefinition() );
}
else
{
if ( varients[0] instanceof AEColor )
{
ItemStackSrc is = ((ItemMultiPart) partItem.item()).createPart( type, v );
if ( is != null )
def.add( (AEColor) v, is );
}
ColoredItemDefinition def = new ColoredItemDefinition();
f.set( parts, def );
for (Enum v : varients)
{
ItemStackSrc is = ((ItemMultiPart) partItem.item()).createPart( type, v );
if ( is != null )
def.add( (AEColor) v, is );
}
f.set( parts, def );
}
}
}
}
+1 -1
View File
@@ -166,7 +166,7 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
{
if ( dmgToMaterial.containsKey( is.getItemDamage() ) )
return dmgToMaterial.get( is.getItemDamage() );
return null;
return MaterialType.InvalidType;
}
@Override
+2
View File
@@ -17,6 +17,8 @@ import cpw.mods.fml.relauncher.SideOnly;
public enum MaterialType
{
InvalidType(-1, AEFeature.Core),
CertusQuartzCrystal(0, AEFeature.Core, "crystalCertusQuartz"), CertusQuartzCrystalCharged(1, AEFeature.Core, EntityChargedQuartz.class),
CertusQuartzDust(2, AEFeature.Core, "dustCertusQuartz"), NetherQuartzDust(3, AEFeature.Core, "dustNetherQuartz"), Flour(4, AEFeature.Flour, "dustWheat"), GoldDust(
+2
View File
@@ -39,6 +39,8 @@ import appeng.parts.reporting.PartTerminal;
public enum PartType
{
InvalidType(-1, AEFeature.Core, null),
CableGlass(0, AEFeature.Core, PartCableGlass.class),
CableCovered(20, AEFeature.Core, PartCableCovered.class),