First batch of null -> isEmpty() checks.

I most likely still missed a ton of checks...
This commit is contained in:
Gunther De Wachter
2017-06-26 05:15:25 +02:00
parent 370fc49357
commit da5879b667
117 changed files with 594 additions and 570 deletions
@@ -1052,12 +1052,12 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
{
IPart p = this.getPart( side );
final ItemStack iss = new ItemStack( def );
if( iss == null )
if( iss.isEmpty() )
{
continue;
}
final ItemStack current = p == null ? null : p.getItemStack( PartItemStack.WORLD );
final ItemStack current = p == null ? ItemStack.EMPTY : p.getItemStack( PartItemStack.WORLD );
if( Platform.itemComparisons().isEqualItemType( iss, current ) )
{
@@ -88,7 +88,7 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin
@Override
public boolean canInsert( final ItemStack stack )
{
if( stack == null || stack.getItem() == null )
if( stack.isEmpty() || stack.getItem() == null )
{
return false;
}
@@ -217,14 +217,14 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{
newItems = myAdaptor.removeSimilarItems( toSend, whatToImport == null ? null : whatToImport.getItemStack(), fzMode, this.configDestination( inv ) );
newItems = myAdaptor.removeSimilarItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getItemStack(), fzMode, this.configDestination( inv ) );
}
else
{
newItems = myAdaptor.removeItems( toSend, whatToImport == null ? null : whatToImport.getItemStack(), this.configDestination( inv ) );
newItems = myAdaptor.removeItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getItemStack(), this.configDestination( inv ) );
}
if( newItems != null )
if( !newItems.isEmpty() )
{
newItems.setCount( (int) ( Math.min( newItems.getCount(),
energy.extractAEPower( newItems.getCount(), Actionable.SIMULATE, PowerMultiplier.CONFIG ) ) + 0.01 ) );
@@ -266,7 +266,7 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin
if( whatToImport == null )
{
itemStackToImport = null;
itemStackToImport = ItemStack.EMPTY;
}
else
{
@@ -141,7 +141,7 @@ public abstract class PartUpgradeable extends PartBasicState implements IAEAppEn
{
for( final ItemStack is : this.upgrades )
{
if( is != null )
if( !is.isEmpty() )
{
drops.add( is );
}
@@ -66,7 +66,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
if( itemstack == null )
if( itemstack.isEmpty() )
{
return false;
}
@@ -75,7 +75,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
boolean simulate = ( type == Actionable.SIMULATE );
// This uses a brute force approach and tries to jam it in every slot the inventory exposes.
for( int i = 0; i < slotCount && remaining != null; i++ )
for( int i = 0; i < slotCount && !remaining.isEmpty(); i++ )
{
remaining = itemHandler.insertItem( i, remaining, simulate );
}
@@ -103,7 +103,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
int remainingSize = requestedItemStack.getCount();
// Use this to gather the requested items
ItemStack gathered = null;
ItemStack gathered = ItemStack.EMPTY;
final boolean simulate = ( mode == Actionable.SIMULATE );
@@ -125,7 +125,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
do
{
extracted = itemHandler.extractItem( i, remainingCurrentSlot, simulate );
if( extracted != null )
if( !extracted.isEmpty() )
{
if( extracted.getCount() > remainingCurrentSlot )
{
@@ -137,7 +137,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
}
// We're just gonna use the first stack we get our hands on as the template for the rest
if( gathered == null )
if( gathered.isEmpty() )
{
gathered = extracted;
}
@@ -148,7 +148,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
remainingCurrentSlot -= extracted.getCount();
}
}
while( extracted != null && remainingCurrentSlot > 0 );
while( !extracted.isEmpty() && remainingCurrentSlot > 0 );
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;
@@ -159,7 +159,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
}
}
if( gathered != null )
if( !gathered.isEmpty() )
{
if( mode == Actionable.MODULATE )
{
@@ -172,6 +172,17 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
return null;
}
private ItemStack getItemStackInCachedSlot ( int pos ) {
if( pos > cachedStacks.length )
return ItemStack.EMPTY;
if( cachedStacks[pos] == null )
return ItemStack.EMPTY;
return cachedStacks[pos];
}
@Override
public TickRateModulation onTick()
{
@@ -189,7 +200,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
for( int slot = 0; slot < slots; slot++ )
{
// Save the old stuff
ItemStack oldIS = cachedStacks[slot];
ItemStack oldIS = getItemStackInCachedSlot(slot);
IAEItemStack oldAeIS = cachedAeStacks[slot];
ItemStack newIS = itemHandler.getStackInSlot( slot );
@@ -198,7 +209,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
{
addItemChange( slot, oldAeIS, newIS, changes );
}
else if( newIS != null && oldIS != null )
else if( !newIS.isEmpty() && !oldIS.isEmpty() )
{
addPossibleStackSizeChange( slot, oldAeIS, newIS, changes );
}
@@ -275,12 +286,12 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
private boolean isDifferent( final ItemStack a, final ItemStack b )
{
if( a == b && b == null )
if( a == b && b.isEmpty() )
{
return false;
}
return a == null || b == null || !Platform.itemComparisons().isSameItem( a, b );
return a.isEmpty() || b.isEmpty() || !Platform.itemComparisons().isSameItem( a, b );
}
private void postDifference( Iterable<IAEItemStack> a )
@@ -60,7 +60,7 @@ public class PartCableAnchor implements IPart
@PartModels
public static final PartModel FACADE_MODELS = new PartModel( false, new ResourceLocation( AppEng.MOD_ID, "part/cable_anchor_short" ) );
private ItemStack is = null;
private ItemStack is = ItemStack.EMPTY;
private IPartHost host = null;
private AEPartLocation mySide = AEPartLocation.UP;
@@ -166,7 +166,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
// AELog.info( "ID:" + id.toString() + " : " + is.getItemDamage() );
final TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem( is );
if( is != null && is.getItem() instanceof IMemoryCard )
if( !is.isEmpty() && is.getItem() instanceof IMemoryCard )
{
final IMemoryCard mc = (IMemoryCard) is.getItem();
final NBTTagCompound data = mc.getData( is );
@@ -174,7 +174,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
final ItemStack newType = new ItemStack( data );
final long freq = data.getLong( "freq" );
if( newType != null )
if( !newType.isEmpty() )
{
if( newType.getItem() instanceof IPartItem )
{
@@ -219,7 +219,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
switch( tt )
{
case LIGHT:
newType = parts.p2PTunnelLight().maybeStack( 1 ).orElse( null );
newType = parts.p2PTunnelLight().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
/*
@@ -232,23 +232,23 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
*/
//case FLUID:
// newType = parts.p2PTunnelLiquids().maybeStack( 1 ).orElse( null );
// newType = parts.p2PTunnelLiquids().maybeStack( 1 ).orElse( ItemStack.EMPTY );
// break;
//case IC2_POWER:
// newType = parts.p2PTunnelEU().maybeStack( 1 ).orElse( null );
// newType = parts.p2PTunnelEU().maybeStack( 1 ).orElse( ItemStack.EMPTY );
// break;
case ITEM:
newType = parts.p2PTunnelItems().maybeStack( 1 ).orElse( null );
newType = parts.p2PTunnelItems().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case ME:
newType = parts.p2PTunnelME().maybeStack( 1 ).orElse( null );
newType = parts.p2PTunnelME().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case REDSTONE:
newType = parts.p2PTunnelRedstone().maybeStack( 1 ).orElse( null );
newType = parts.p2PTunnelRedstone().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
/*
@@ -303,7 +303,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
public boolean onPartShiftActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
{
final ItemStack is = player.inventory.getCurrentItem();
if( is != null && is.getItem() instanceof IMemoryCard )
if( !is.isEmpty() && is.getItem() instanceof IMemoryCard )
{
final IMemoryCard mc = (IMemoryCard) is.getItem();
final NBTTagCompound data = new NBTTagCompound();
@@ -81,7 +81,7 @@ public abstract class AbstractPartTerminal extends AbstractPartDisplay implement
for( final ItemStack is : this.viewCell )
{
if( is != null )
if( !is.isEmpty() )
{
drops.add( is );
}
@@ -120,14 +120,14 @@ public class PartConversionMonitor extends AbstractPartMonitor
final IAEItemStack insertItem = input.copy();
insertItem.setStackSize( targetStack.getCount() );
final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, insertItem, new PlayerSource( player, this ) );
player.inventory.setInventorySlotContents( x, failedToInsert == null ? null : failedToInsert.getItemStack() );
player.inventory.setInventorySlotContents( x, failedToInsert == null ? ItemStack.EMPTY : failedToInsert.getItemStack() );
}
}
}
else
{
final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, input, new PlayerSource( player, this ) );
player.inventory.setInventorySlotContents( player.inventory.currentItem, failedToInsert == null ? null : failedToInsert.getItemStack() );
player.inventory.setInventorySlotContents( player.inventory.currentItem, failedToInsert == null ? ItemStack.EMPTY : failedToInsert.getItemStack() );
}
}
catch( final GridAccessException e )
@@ -163,7 +163,7 @@ public class PartConversionMonitor extends AbstractPartMonitor
ItemStack newItems = retrieved.getItemStack();
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( player, EnumFacing.UP );
newItems = adaptor.addItems( newItems );
if( newItems != null )
if( !newItems.isEmpty() )
{
final TileEntity te = this.getTile();
final List<ItemStack> list = Collections.singletonList( newItems );
@@ -63,7 +63,7 @@ public class PartCraftingTerminal extends AbstractPartTerminal
for( final ItemStack is : this.craftingGrid )
{
if( is != null )
if( !is.isEmpty() )
{
drops.add( is );
}
@@ -70,7 +70,7 @@ public class PartPatternTerminal extends AbstractPartTerminal
{
for( final ItemStack is : this.pattern )
{
if( is != null )
if( !is.isEmpty() )
{
drops.add( is );
}
@@ -125,7 +125,7 @@ public class PartPatternTerminal extends AbstractPartTerminal
if( inv == this.pattern && slot == 1 )
{
final ItemStack is = this.pattern.getStackInSlot( 1 );
if( is != null && is.getItem() instanceof ICraftingPatternItem )
if( !is.isEmpty() && is.getItem() instanceof ICraftingPatternItem )
{
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = pattern.getPatternForItem( is, this.getHost().getTile().getWorld() );
@@ -137,13 +137,13 @@ public class PartPatternTerminal extends AbstractPartTerminal
for( int x = 0; x < this.crafting.getSizeInventory() && x < details.getInputs().length; x++ )
{
final IAEItemStack item = details.getInputs()[x];
this.crafting.setInventorySlotContents( x, item == null ? null : item.getItemStack() );
this.crafting.setInventorySlotContents( x, item == null ? ItemStack.EMPTY : item.getItemStack() );
}
for( int x = 0; x < this.output.getSizeInventory() && x < details.getOutputs().length; x++ )
{
final IAEItemStack item = details.getOutputs()[x];
this.output.setInventorySlotContents( x, item == null ? null : item.getItemStack() );
this.output.setInventorySlotContents( x, item == null ? ItemStack.EMPTY : item.getItemStack() );
}
}
}
@@ -163,7 +163,7 @@ public class PartPatternTerminal extends AbstractPartTerminal
for( int x = 0; x < this.crafting.getSizeInventory(); x++ )
{
final ItemStack is = this.crafting.getStackInSlot( x );
if( is != null )
if( !is.isEmpty() )
{
is.setCount( 1 );
}