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
@@ -72,7 +72,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
}
final ItemStack is = this.cell.getStackInSlot( 0 );
if( is == null )
if( is.isEmpty() )
{
return null;
}
@@ -90,7 +90,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
public ICellWorkbenchItem getCell()
{
if( this.cell.getStackInSlot( 0 ) == null )
if( this.cell.getStackInSlot( 0 ).isEmpty() )
{
return null;
}
@@ -157,7 +157,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
boolean cellHasConfig = false;
for( int x = 0; x < configInventory.getSizeInventory(); x++ )
{
if( configInventory.getStackInSlot( x ) != null )
if( !configInventory.getStackInSlot( x ).isEmpty() )
{
cellHasConfig = true;
break;
@@ -185,7 +185,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
{
for( int x = 0; x < this.config.getSizeInventory(); x++ )
{
this.config.setInventorySlotContents( x, null );
this.config.setInventorySlotContents( x, ItemStack.EMPTY );
}
this.markDirty();
@@ -219,7 +219,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
}
final ItemStack is = this.cell.getStackInSlot( 0 );
if( is == null )
if( is.isEmpty() )
{
return null;
}
@@ -93,7 +93,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
}
catch( final Throwable t )
{
this.inv.setInventorySlotContents( 0, null );
this.inv.setInventorySlotContents( 0, ItemStack.EMPTY );
}
return false; // TESR doesn't need updates!
}
@@ -217,7 +217,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
}
final ItemStack myItem = this.getStackInSlot( 0 );
if( myItem == null )
if( myItem.isEmpty() )
{
ItemStack held = player.inventory.getCurrentItem();
@@ -231,7 +231,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
{
final List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add( myItem );
this.setInventorySlotContents( 0, null );
this.setInventorySlotContents( 0, ItemStack.EMPTY );
Platform.spawnDrops( this.world, this.pos.offset( this.getForward() ), drops );
}
}
@@ -267,7 +267,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
return true;
}
if( myItem == null )
if( myItem.isEmpty() )
{
return false;
}
@@ -97,7 +97,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
public double getStorage()
{
final ItemStack is = this.inv.getStackInSlot( 2 );
if( is != null )
if( !is.isEmpty() )
{
if( is.getItem() instanceof IStorageComponent )
{
@@ -118,7 +118,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
final double requiredPower = this.getRequiredPower();
final ItemStack output = this.getOutput();
while( requiredPower <= this.getStoredPower() && output != null && requiredPower > 0 )
while( requiredPower <= this.getStoredPower() && !output.isEmpty() && requiredPower > 0 )
{
if( this.canAddOutput( output ) )
{
@@ -135,7 +135,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
private boolean canAddOutput( final ItemStack output )
{
final ItemStack outputStack = this.getStackInSlot( 1 );
return outputStack == null || ( Platform.itemComparisons().isEqualItem( outputStack,
return outputStack.isEmpty() || ( Platform.itemComparisons().isEqualItem( outputStack,
output ) && outputStack.getCount() < outputStack.getMaxStackSize() );
}
@@ -147,7 +147,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
private void addOutput( final ItemStack output )
{
final ItemStack outputStack = this.getStackInSlot( 1 );
if( outputStack == null )
if( outputStack.isEmpty() )
{
this.setInventorySlotContents( 1, output.copy() );
}
@@ -165,10 +165,10 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
switch( (CondenserOutput) this.cm.getSetting( Settings.CONDENSER_OUTPUT ) )
{
case MATTER_BALLS:
return materials.matterBall().maybeStack( 1 ).orElse( null );
return materials.matterBall().maybeStack( 1 ).orElse( ItemStack.EMPTY );
case SINGULARITY:
return materials.singularity().maybeStack( 1 ).orElse( null );
return materials.singularity().maybeStack( 1 ).orElse( ItemStack.EMPTY );
case TRASH:
default:
@@ -192,7 +192,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
{
if( i == 0 )
{
if( itemstack != null )
if( !itemstack.isEmpty() )
{
this.addPower( itemstack.getCount() );
}
@@ -215,10 +215,10 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
if( slot == 0 )
{
final ItemStack is = inv.getStackInSlot( 0 );
if( is != null )
if( !is.isEmpty() )
{
this.addPower( is.getCount() );
inv.setInventorySlotContents( 0, null );
inv.setInventorySlotContents( 0, ItemStack.EMPTY );
}
}
}
@@ -324,7 +324,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
{
return stack;
}
if( !simulate && stack != null )
if( !simulate && !stack.isEmpty() )
{
addPower( stack.getCount() );
}
@@ -168,7 +168,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
else
{
this.inv.setInventorySlotContents( num, null );
this.inv.setInventorySlotContents( num, ItemStack.EMPTY );
}
}
@@ -215,7 +215,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
for( int h = 0; h < this.upgrades.getSizeInventory(); h++ )
{
final ItemStack is = this.upgrades.getStackInSlot( h );
if( is != null )
if( !is.isEmpty() )
{
drops.add( is );
}
@@ -344,17 +344,17 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
final ItemStack plateB = this.getStackInSlot( 1 );
ItemStack renamedItem = this.getStackInSlot( 2 );
if( plateA != null && plateA.getCount() > 1 )
if( !plateA.isEmpty() && plateA.getCount() > 1 )
{
return null;
}
if( plateB != null && plateB.getCount() > 1 )
if( !plateB.isEmpty() && plateB.getCount() > 1 )
{
return null;
}
if( renamedItem != null && renamedItem.getCount() > 1 )
if( !renamedItem.isEmpty() && renamedItem.getCount() > 1 )
{
return null;
}
@@ -363,19 +363,19 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
final boolean isNameA = namePress.isSameAs( plateA );
final boolean isNameB = namePress.isSameAs( plateB );
if( ( isNameA || isNameB ) && ( isNameA || plateA == null ) && ( isNameB || plateB == null ) )
if( ( isNameA || isNameB ) && ( isNameA || plateA.isEmpty() ) && ( isNameB || plateB.isEmpty() ) )
{
if( renamedItem != null )
if( !renamedItem.isEmpty() )
{
String name = "";
if( plateA != null )
if( !plateA.isEmpty() )
{
final NBTTagCompound tag = Platform.openNbtData( plateA );
name += tag.getString( "InscribeName" );
}
if( plateB != null )
if( !plateB.isEmpty() )
{
final NBTTagCompound tag = Platform.openNbtData( plateB );
if( name.length() > 0 )
@@ -417,15 +417,15 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
for( final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes() )
{
final boolean matchA = ( plateA == null && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( plateA,
recipe.getTopOptional().orElse( null ) ) ) && // and...
( plateB == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( plateB,
recipe.getBottomOptional().orElse( null ) ) );
final boolean matchA = ( plateA.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( plateA,
recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and...
( plateB.isEmpty() && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( plateB,
recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) );
final boolean matchB = ( plateB == null && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( plateB,
recipe.getTopOptional().orElse( null ) ) ) && // and...
( plateA == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( plateA,
recipe.getBottomOptional().orElse( null ) ) );
final boolean matchB = ( plateB.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( plateB,
recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and...
( plateA.isEmpty() && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( plateA,
recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) );
if( matchA || matchB )
{
@@ -455,15 +455,15 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
final ItemStack outputCopy = out.getOutput().copy();
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( this.inv, SLOT_OUT, 1, true ), EnumFacing.UP );
if( ad.addItems( outputCopy ) == null )
if( ad.addItems( outputCopy ).isEmpty() )
{
this.setProcessingTime( 0 );
if( out.getProcessType() == InscriberProcessType.PRESS )
{
this.setInventorySlotContents( SLOT_TOP, null );
this.setInventorySlotContents( SLOT_BOTTOM, null );
this.setInventorySlotContents( SLOT_TOP, ItemStack.EMPTY );
this.setInventorySlotContents( SLOT_BOTTOM, ItemStack.EMPTY );
}
this.setInventorySlotContents( SLOT_MIDDLE, null );
this.setInventorySlotContents( SLOT_MIDDLE, ItemStack.EMPTY );
}
}
@@ -522,7 +522,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
{
final ItemStack outputCopy = out.getOutput().copy();
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( this.inv, SLOT_OUT, 1, true ), EnumFacing.UP );
if( ad.simulateAdd( outputCopy ) == null )
if( ad.simulateAdd( outputCopy ).isEmpty() )
{
this.setSmash( true );
this.finalStep = 0;
@@ -678,13 +678,13 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
@Override
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
{
if( slot != 0 || stack == null )
if( slot != 0 || stack.isEmpty() )
{
return stack;
}
// If there's already an item stack in the slot, we don't allow insertion and don't do any other checks
if( inv.getStackInSlot( insertSlot ) != null )
if( !inv.getStackInSlot( insertSlot ).isEmpty() )
{
return stack;
}
@@ -715,11 +715,11 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
if( simulate )
{
return adapter.simulateRemove( amount, null, null );
return adapter.simulateRemove( amount, ItemStack.EMPTY, null );
}
else
{
return adapter.removeItems( amount, null, null );
return adapter.removeItems( amount, ItemStack.EMPTY, null );
}
}
@@ -157,7 +157,7 @@ public class TileVibrationChamber extends AENetworkInvTile implements IGridTicka
private boolean canEatFuel()
{
final ItemStack is = this.getStackInSlot( FUEL_SLOT_INDEX );
if( is != null )
if( !is.isEmpty() )
{
final int newBurnTime = TileEntityFurnace.getItemBurnTime( is );
if( newBurnTime > 0 && is.getCount() > 0 )
@@ -244,7 +244,7 @@ public class TileVibrationChamber extends AENetworkInvTile implements IGridTicka
private void eatFuel()
{
final ItemStack is = this.getStackInSlot( FUEL_SLOT_INDEX );
if( is != null )
if( !is.isEmpty() )
{
final int newBurnTime = TileEntityFurnace.getItemBurnTime( is );
if( newBurnTime > 0 && is.getCount() > 0 )