Merge pull request #1332 from thatsIch/b-1331-crash-on-disabled-material
Fixes #1331: Happened on deactivating features for intermediate crafting components
This commit is contained in:
@@ -21,15 +21,16 @@ package appeng.core.features;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.block.AEBaseBlock;
|
||||
|
||||
@@ -42,20 +43,22 @@ public class BlockDefinition extends ItemDefinition implements IBlockDefinition
|
||||
public BlockDefinition( Block block, ActivityState state )
|
||||
{
|
||||
super( constructItemFromBlock( block ), state );
|
||||
assert block != null;
|
||||
|
||||
Preconditions.checkNotNull( block );
|
||||
Preconditions.checkNotNull( state );
|
||||
|
||||
this.block = block;
|
||||
this.enabled = state == ActivityState.Enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Block> maybeBlock()
|
||||
public final Optional<Block> maybeBlock()
|
||||
{
|
||||
return Optional.of( this.block );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ItemBlock> maybeItemBlock()
|
||||
public final Optional<ItemBlock> maybeItemBlock()
|
||||
{
|
||||
if( this.enabled )
|
||||
{
|
||||
|
||||
@@ -19,11 +19,14 @@
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
|
||||
@@ -32,9 +35,9 @@ public final class DamagedItemDefinition implements IItemDefinition
|
||||
{
|
||||
private final IStackSrc source;
|
||||
|
||||
public DamagedItemDefinition( IStackSrc source )
|
||||
public DamagedItemDefinition( @Nonnull IStackSrc source )
|
||||
{
|
||||
this.source = source;
|
||||
this.source = Preconditions.checkNotNull( source );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -88,7 +88,7 @@ public final class DefinitionConverter
|
||||
@Override
|
||||
public boolean sameAsBlock( IBlockAccess world, int x, int y, int z )
|
||||
{
|
||||
return this.definition.isSameAs( world, x, y, z );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +137,12 @@ public final class DefinitionConverter
|
||||
{
|
||||
return this.definition.maybeBlock().orNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sameAsBlock( IBlockAccess world, int x, int y, int z )
|
||||
{
|
||||
return this.definition.isSameAs( world, x, y, z );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.util.Platform;
|
||||
@@ -36,7 +37,8 @@ public class ItemDefinition implements IItemDefinition
|
||||
|
||||
public ItemDefinition( Item item, ActivityState state )
|
||||
{
|
||||
assert item != null;
|
||||
Preconditions.checkNotNull( item );
|
||||
Preconditions.checkNotNull( state );
|
||||
|
||||
this.item = item;
|
||||
this.enabled = state == ActivityState.Enabled;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -45,6 +47,7 @@ public class ItemStackSrc implements IStackSrc
|
||||
this.damage = dmg;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack stack( int i )
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ package appeng.core.features;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import appeng.api.definitions.ITileDefinition;
|
||||
import appeng.block.AEBaseBlock;
|
||||
@@ -34,7 +35,11 @@ public final class TileDefinition extends BlockDefinition implements ITileDefini
|
||||
public TileDefinition( AEBaseBlock block, ActivityState state )
|
||||
{
|
||||
super( block, state );
|
||||
assert !block.hasBlockTileEntity() || block.getTileEntityClass() != null;
|
||||
|
||||
Preconditions.checkNotNull( block );
|
||||
Preconditions.checkNotNull( state );
|
||||
|
||||
Preconditions.checkState( !block.hasBlockTileEntity() || block.getTileEntityClass() != null );
|
||||
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
@@ -30,6 +28,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import appeng.api.definitions.ITileDefinition;
|
||||
|
||||
@@ -41,6 +40,9 @@ public final class WrappedDamageItemDefinition implements ITileDefinition
|
||||
|
||||
public WrappedDamageItemDefinition( ITileDefinition definition, int damage )
|
||||
{
|
||||
Preconditions.checkNotNull( definition );
|
||||
Preconditions.checkArgument( damage >= 0 );
|
||||
|
||||
this.definition = definition;
|
||||
this.damage = damage;
|
||||
}
|
||||
@@ -72,7 +74,7 @@ public final class WrappedDamageItemDefinition implements ITileDefinition
|
||||
@Override
|
||||
public Optional<ItemStack> maybeStack( final int stackSize )
|
||||
{
|
||||
return this.definition.maybeBlock().transform( new BlockTransformFunction( stackSize ) );
|
||||
return this.definition.maybeBlock().transform( new BlockTransformFunction( stackSize, this.damage ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,20 +94,26 @@ public final class WrappedDamageItemDefinition implements ITileDefinition
|
||||
return this.definition.isSameAs( world, x, y, z ) && world.getBlockMetadata( x, y, z ) == this.damage;
|
||||
}
|
||||
|
||||
private class BlockTransformFunction implements Function<Block, ItemStack>
|
||||
private static final class BlockTransformFunction implements Function<Block, ItemStack>
|
||||
{
|
||||
private final int stackSize;
|
||||
private final int damage;
|
||||
|
||||
public BlockTransformFunction( int stackSize )
|
||||
public BlockTransformFunction( int stackSize, int damage )
|
||||
{
|
||||
Preconditions.checkArgument( stackSize > 0 );
|
||||
Preconditions.checkArgument( damage >= 0 );
|
||||
|
||||
this.stackSize = stackSize;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack apply( Block input )
|
||||
{
|
||||
return new ItemStack( input, this.stackSize, WrappedDamageItemDefinition.this.damage );
|
||||
Preconditions.checkNotNull( input );
|
||||
|
||||
return new ItemStack( input, this.stackSize, this.damage );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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