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
@@ -42,12 +42,12 @@ public class AdaptorItemHandler extends InventoryAdaptor
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
{
int slots = itemHandler.getSlots();
ItemStack rv = null;
ItemStack rv = ItemStack.EMPTY;
for( int slot = 0; slot < slots && amount > 0; slot++ )
{
final ItemStack is = itemHandler.getStackInSlot( slot );
if( is == null || ( filter != null && !Platform.itemComparisons().isSameItem( is, filter ) ) )
if( is.isEmpty() || ( !filter.isEmpty() && !Platform.itemComparisons().isSameItem( is, filter ) ) )
{
continue;
}
@@ -55,7 +55,7 @@ public class AdaptorItemHandler extends InventoryAdaptor
if( destination != null )
{
ItemStack extracted = itemHandler.extractItem( slot, amount, true );
if( extracted == null )
if( extracted.isEmpty() )
{
continue;
}
@@ -69,12 +69,12 @@ public class AdaptorItemHandler extends InventoryAdaptor
// Attempt extracting it
ItemStack extracted = itemHandler.extractItem( slot, amount, false );
if( extracted == null )
if( extracted.isEmpty() )
{
continue;
}
if( rv == null )
if( rv.isEmpty() )
{
// Use the first stack as a template for the result
rv = extracted;
@@ -96,16 +96,16 @@ public class AdaptorItemHandler extends InventoryAdaptor
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
{
int slots = itemHandler.getSlots();
ItemStack rv = null;
ItemStack rv = ItemStack.EMPTY;
for( int slot = 0; slot < slots && amount > 0; slot++ )
{
final ItemStack is = itemHandler.getStackInSlot( slot );
if( is != null && ( filter == null || Platform.itemComparisons().isSameItem( is, filter ) ) )
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
{
ItemStack extracted = itemHandler.extractItem( slot, amount, true );
if( extracted == null )
if( extracted.isEmpty() )
{
continue;
}
@@ -118,7 +118,7 @@ public class AdaptorItemHandler extends InventoryAdaptor
}
}
if( rv == null )
if( rv.isEmpty() )
{
// Use the first stack as a template for the result
rv = extracted.copy();
@@ -145,12 +145,12 @@ public class AdaptorItemHandler extends InventoryAdaptor
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
int slots = itemHandler.getSlots();
ItemStack extracted = null;
ItemStack extracted = ItemStack.EMPTY;
for( int slot = 0; slot < slots && extracted == null; slot++ )
for( int slot = 0; slot < slots && extracted.isEmpty(); slot++ )
{
final ItemStack is = itemHandler.getStackInSlot( slot );
if( is == null || ( filter != null && !Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
if( is.isEmpty() || ( !filter.isEmpty() && !Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
{
continue;
}
@@ -158,7 +158,7 @@ public class AdaptorItemHandler extends InventoryAdaptor
if( destination != null )
{
ItemStack simulated = itemHandler.extractItem( slot, amount, true );
if( simulated == null )
if( simulated.isEmpty() )
{
continue;
}
@@ -180,12 +180,12 @@ public class AdaptorItemHandler extends InventoryAdaptor
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
int slots = itemHandler.getSlots();
ItemStack extracted = null;
ItemStack extracted = ItemStack.EMPTY;
for( int slot = 0; slot < slots && extracted == null; slot++ )
for( int slot = 0; slot < slots && extracted.isEmpty(); slot++ )
{
final ItemStack is = itemHandler.getStackInSlot( slot );
if( is == null || ( filter != null && !Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
if( is.isEmpty() || ( !filter.isEmpty() && !Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
{
continue;
}
@@ -193,11 +193,11 @@ public class AdaptorItemHandler extends InventoryAdaptor
// Attempt extracting it
extracted = itemHandler.extractItem( slot, amount, true );
if( extracted != null && destination != null )
if( !extracted.isEmpty() && destination != null )
{
if( !destination.canInsert( extracted ) )
{
extracted = null; // Keep on looking...
extracted = ItemStack.EMPTY; // Keep on looking...
}
}
}
@@ -219,9 +219,9 @@ public class AdaptorItemHandler extends InventoryAdaptor
private ItemStack addItems( final ItemStack itemsToAdd, final boolean simulate )
{
if( itemsToAdd == null || itemsToAdd.getCount() == 0 )
if( itemsToAdd.isEmpty() || itemsToAdd.getCount() == 0 )
{
return null;
return ItemStack.EMPTY;
}
ItemStack left = itemsToAdd.copy();
@@ -230,13 +230,13 @@ public class AdaptorItemHandler extends InventoryAdaptor
{
ItemStack is = itemHandler.getStackInSlot( slot );
if( is == null || Platform.itemComparisons().isSameItem( is, left ) )
if( is.isEmpty() || Platform.itemComparisons().isSameItem( is, left ) )
{
left = itemHandler.insertItem( slot, left, simulate );
if( left == null || left.getCount() <= 0 )
if( left.isEmpty() || left.getCount() <= 0 )
{
return null;
return ItemStack.EMPTY;
}
}
}
@@ -250,7 +250,7 @@ public class AdaptorItemHandler extends InventoryAdaptor
int slots = itemHandler.getSlots();
for( int slot = 0; slot < slots; slot++ )
{
if( itemHandler.getStackInSlot( slot ) != null )
if( !itemHandler.getStackInSlot( slot ).isEmpty() )
{
return true;
}