Fixes #1331: Happened on deactivating features for intermediate crafting components
If a feature dependency of ItemMultiMaterial was disabled, the returned value was never assigned with the constructed. Pulling out the construction and setting it before checking it, prevents the NPE and also matches the behaviour in ItemMultiPart, where parts are constructed, but never registered.
This commit is contained in:
@@ -47,6 +47,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
@@ -68,7 +69,7 @@ import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
|
||||
public final class ItemMultiMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
|
||||
{
|
||||
public static final int KILO = 1024;
|
||||
public static ItemMultiMaterial instance;
|
||||
@@ -172,40 +173,36 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
|
||||
|
||||
public IStackSrc createMaterial( MaterialType mat )
|
||||
{
|
||||
if( !mat.isRegistered() )
|
||||
Preconditions.checkState( !mat.isRegistered(), "Cannot create the same material twice." );
|
||||
|
||||
boolean enabled = true;
|
||||
|
||||
for( AEFeature f : mat.getFeature() )
|
||||
{
|
||||
boolean enabled = true;
|
||||
for( AEFeature f : mat.getFeature() )
|
||||
{
|
||||
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
|
||||
}
|
||||
|
||||
if( enabled )
|
||||
{
|
||||
mat.itemInstance = this;
|
||||
int newMaterialNum = mat.damageValue;
|
||||
mat.markReady();
|
||||
|
||||
mat.stackSrc = new MaterialStackSrc( mat );
|
||||
|
||||
if( this.dmgToMaterial.get( newMaterialNum ) == null )
|
||||
{
|
||||
this.dmgToMaterial.put( newMaterialNum, mat );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException( "Meta Overlap detected." );
|
||||
}
|
||||
|
||||
return mat.stackSrc;
|
||||
}
|
||||
|
||||
return mat.stackSrc;
|
||||
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
|
||||
}
|
||||
else
|
||||
|
||||
mat.stackSrc = new MaterialStackSrc( mat );
|
||||
|
||||
if( enabled )
|
||||
{
|
||||
throw new IllegalStateException( "Cannot create the same material twice..." );
|
||||
mat.itemInstance = this;
|
||||
mat.markReady();
|
||||
int newMaterialNum = mat.damageValue;
|
||||
|
||||
|
||||
if( this.dmgToMaterial.get( newMaterialNum ) == null )
|
||||
{
|
||||
this.dmgToMaterial.put( newMaterialNum, mat );
|
||||
}
|
||||
else
|
||||
|
||||
{
|
||||
throw new IllegalStateException( "Meta Overlap detected." );
|
||||
}
|
||||
}
|
||||
|
||||
return mat.stackSrc;
|
||||
}
|
||||
|
||||
public void makeUnique()
|
||||
|
||||
@@ -63,6 +63,8 @@ import appeng.items.AEBaseItem;
|
||||
|
||||
public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup
|
||||
{
|
||||
private static final Comparator<Entry<Integer, PartTypeWithVariant>> REGISTERED_COMPARATOR = new RegisteredComparator();
|
||||
|
||||
public static ItemMultiPart instance;
|
||||
private final NameResolver nameResolver;
|
||||
private final Map<Integer, PartTypeWithVariant> registered;
|
||||
@@ -216,15 +218,7 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
|
||||
public void getSubItems( Item number, CreativeTabs tab, List cList )
|
||||
{
|
||||
List<Entry<Integer, PartTypeWithVariant>> types = new ArrayList<Entry<Integer, PartTypeWithVariant>>( this.registered.entrySet() );
|
||||
Collections.sort( types, new Comparator<Entry<Integer, PartTypeWithVariant>>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare( Entry<Integer, PartTypeWithVariant> o1, Entry<Integer, PartTypeWithVariant> o2 )
|
||||
{
|
||||
return o1.getValue().part.name().compareTo( o2.getValue().part.name() );
|
||||
}
|
||||
} );
|
||||
Collections.sort( types, REGISTERED_COMPARATOR );
|
||||
|
||||
for( Entry<Integer, PartTypeWithVariant> part : types )
|
||||
{
|
||||
@@ -375,4 +369,13 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
|
||||
this.variant = variant;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RegisteredComparator implements Comparator<Entry<Integer, PartTypeWithVariant>>
|
||||
{
|
||||
@Override
|
||||
public int compare( Entry<Integer, PartTypeWithVariant> o1, Entry<Integer, PartTypeWithVariant> o2 )
|
||||
{
|
||||
return o1.getValue().part.name().compareTo( o2.getValue().part.name() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user