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
@@ -22,6 +22,7 @@ package appeng.util.inv;
import java.util.Iterator;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import appeng.api.config.FuzzyMode;
@@ -45,12 +46,12 @@ public class AdaptorIInventory extends InventoryAdaptor
public ItemStack removeItems( int amount, ItemStack filter, final IInventoryDestination destination )
{
final int s = this.i.getSizeInventory();
ItemStack rv = null;
ItemStack rv = ItemStack.EMPTY;
for( int x = 0; x < s && amount > 0; x++ )
{
final ItemStack is = this.i.getStackInSlot( x );
if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.itemComparisons().isSameItem( is, filter ) ) )
if( !is.isEmpty() && this.canRemoveStackFromSlot( x, is ) && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
{
int boundAmounts = amount;
if( boundAmounts > is.getCount() )
@@ -64,7 +65,7 @@ public class AdaptorIInventory extends InventoryAdaptor
if( boundAmounts > 0 )
{
if( rv == null )
if( rv.isEmpty() )
{
rv = is.copy();
filter = rv;
@@ -79,7 +80,7 @@ public class AdaptorIInventory extends InventoryAdaptor
if( is.getCount() == boundAmounts )
{
this.i.setInventorySlotContents( x, null );
this.i.setInventorySlotContents( x, ItemStack.EMPTY );
this.i.markDirty();
}
else
@@ -103,12 +104,12 @@ public class AdaptorIInventory extends InventoryAdaptor
public ItemStack simulateRemove( int amount, final ItemStack filter, final IInventoryDestination destination )
{
final int s = this.i.getSizeInventory();
ItemStack rv = null;
ItemStack rv = ItemStack.EMPTY;
for( int x = 0; x < s && amount > 0; x++ )
{
final ItemStack is = this.i.getStackInSlot( x );
if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.itemComparisons().isSameItem( is, filter ) ) )
if( !is.isEmpty() && this.canRemoveStackFromSlot( x, is ) && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
{
int boundAmount = amount;
if( boundAmount > is.getCount() )
@@ -122,7 +123,7 @@ public class AdaptorIInventory extends InventoryAdaptor
if( boundAmount > 0 )
{
if( rv == null )
if( rv.isEmpty() )
{
rv = is.copy();
rv.setCount( boundAmount );
@@ -147,8 +148,8 @@ public class AdaptorIInventory extends InventoryAdaptor
for( int x = 0; x < s; x++ )
{
final ItemStack is = this.i.getStackInSlot( x );
if( is != null && this.canRemoveStackFromSlot( x,
is ) && ( filter == null || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
if( !is.isEmpty() && this.canRemoveStackFromSlot( x,
is ) && ( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
{
int newAmount = amount;
if( newAmount > is.getCount() )
@@ -160,7 +161,7 @@ public class AdaptorIInventory extends InventoryAdaptor
newAmount = 0;
}
ItemStack rv = null;
ItemStack rv = ItemStack.EMPTY;
if( newAmount > 0 )
{
rv = is.copy();
@@ -168,7 +169,7 @@ public class AdaptorIInventory extends InventoryAdaptor
if( is.getCount() == rv.getCount() )
{
this.i.setInventorySlotContents( x, null );
this.i.setInventorySlotContents( x, ItemStack.EMPTY );
this.i.markDirty();
}
else
@@ -180,14 +181,14 @@ public class AdaptorIInventory extends InventoryAdaptor
}
}
if( rv != null )
if( !rv.isEmpty() )
{
// i.markDirty();
return rv;
}
}
}
return null;
return ItemStack.EMPTY;
}
@Override
@@ -198,8 +199,8 @@ public class AdaptorIInventory extends InventoryAdaptor
{
final ItemStack is = this.i.getStackInSlot( x );
if( is != null && this.canRemoveStackFromSlot( x,
is ) && ( filter == null || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
if( !is.isEmpty() && this.canRemoveStackFromSlot( x,
is ) && ( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
{
int boundAmount = amount;
if( boundAmount > is.getCount() )
@@ -219,7 +220,7 @@ public class AdaptorIInventory extends InventoryAdaptor
}
}
}
return null;
return ItemStack.EMPTY;
}
@Override
@@ -240,7 +241,7 @@ public class AdaptorIInventory extends InventoryAdaptor
final int s = this.i.getSizeInventory();
for( int x = 0; x < s; x++ )
{
if( this.i.getStackInSlot( x ) != null )
if( !this.i.getStackInSlot( x ).isEmpty() )
{
return true;
}
@@ -262,7 +263,7 @@ public class AdaptorIInventory extends InventoryAdaptor
*/
private ItemStack addItems( final ItemStack itemsToAdd, final boolean modulate )
{
if( itemsToAdd == null || itemsToAdd.getCount() == 0 )
if( itemsToAdd.isEmpty() || itemsToAdd.getCount() == 0 )
{
return ItemStack.EMPTY;
}
@@ -280,7 +281,7 @@ public class AdaptorIInventory extends InventoryAdaptor
if( this.i.isItemValidForSlot( slot, next ) )
{
final ItemStack is = this.i.getStackInSlot( slot );
if( is == null )
if( is.isEmpty() )
{
left.grow( -next.getCount() );