Replaced all instances of Guava's Optional type with Java 8's Optional type, as discussed in #81. (#90)

This commit is contained in:
shartte
2016-08-24 19:06:10 +02:00
committed by Sebastian Hartte
parent c2a239a12f
commit e276aa682f
65 changed files with 306 additions and 468 deletions
@@ -20,6 +20,7 @@ package appeng.items.misc;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
@@ -66,16 +67,16 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
@Nullable
public static ResolverResult getResolver( final int certus2 )
{
ResolverResult resolver = null;
for( ItemStack crystalSeedStack : AEApi.instance().definitions().items().crystalSeed().maybeStack( 1 ).asSet() )
{
crystalSeedStack.setItemDamage( certus2 );
crystalSeedStack = newStyle( crystalSeedStack );
resolver = new ResolverResult( "ItemCrystalSeed", crystalSeedStack.getItemDamage(), crystalSeedStack.getTagCompound() );
}
return AEApi.instance().definitions().items().crystalSeed().maybeStack( 1 )
.map( crystalSeedStack ->
{
crystalSeedStack.setItemDamage( certus2 );
crystalSeedStack = newStyle( crystalSeedStack );
return new ResolverResult( "ItemCrystalSeed", crystalSeedStack.getItemDamage(), crystalSeedStack.getTagCompound() );
} )
.orElse( null );
return resolver;
}
private static ItemStack newStyle( final ItemStack itemStack )
@@ -110,23 +111,26 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
if( newDamage == CERTUS + SINGLE_OFFSET )
{
for( final ItemStack quartzStack : materials.purifiedCertusQuartzCrystal().maybeStack( size ).asSet() )
Optional<ItemStack> quartzStack = materials.purifiedCertusQuartzCrystal().maybeStack( size );
if( quartzStack.isPresent() )
{
return quartzStack;
return quartzStack.get();
}
}
if( newDamage == NETHER + SINGLE_OFFSET )
{
for( final ItemStack quartzStack : materials.purifiedNetherQuartzCrystal().maybeStack( size ).asSet() )
Optional<ItemStack> quartzStack = materials.purifiedNetherQuartzCrystal().maybeStack( size );
if( quartzStack.isPresent() )
{
return quartzStack;
return quartzStack.get();
}
}
if( newDamage == FLUIX + SINGLE_OFFSET )
{
for( final ItemStack quartzStack : materials.purifiedFluixCrystal().maybeStack( size ).asSet() )
Optional<ItemStack> quartzStack = materials.purifiedFluixCrystal().maybeStack( size );
if( quartzStack.isPresent() )
{
return quartzStack;
return quartzStack.get();
}
}
if( newDamage > FINAL_STAGE )
@@ -80,16 +80,16 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
final InventoryPlayer inv = player.inventory;
for( int s = 0; s < player.inventory.getSizeInventory(); s++ )
ItemStack is = AEApi.instance().definitions().materials().blankPattern().maybeStack( stack.stackSize ).orElse( null );
if( is != null )
{
if( inv.getStackInSlot( s ) == stack )
for( int s = 0; s < player.inventory.getSizeInventory(); s++ )
{
for( final ItemStack blankPattern : AEApi.instance().definitions().materials().blankPattern().maybeStack( stack.stackSize ).asSet() )
if( inv.getStackInSlot( s ) == stack )
{
inv.setInventorySlotContents( s, blankPattern );
inv.setInventorySlotContents( s, is );
return true;
}
return true;
}
}
}
@@ -250,16 +250,14 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
public ItemStack createFromIDs( final int[] ids )
{
for( final ItemStack facadeStack : AEApi.instance().definitions().items().facade().maybeStack( 1 ).asSet() )
{
final NBTTagCompound facadeTag = new NBTTagCompound();
facadeTag.setIntArray( "x", ids.clone() );
facadeStack.setTagCompound( facadeTag );
ItemStack facadeStack = AEApi.instance().definitions().items().facade().maybeStack( 1 )
.orElseThrow( () -> new MissingDefinition( "Tried to create a facade, while facades are being deactivated." ) );
return facadeStack;
}
final NBTTagCompound facadeTag = new NBTTagCompound();
facadeTag.setIntArray( "x", ids.clone() );
facadeStack.setTagCompound( facadeTag );
throw new MissingDefinition( "Tried to create a facade, while facades are being deactivated." );
return facadeStack;
}
@Override
@@ -259,14 +259,14 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe
}
// drop empty storage cell case
for( final ItemStack storageCellStack : AEApi.instance().definitions().materials().emptyStorageCell().maybeStack( 1 ).asSet() )
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack( 1 ).ifPresent( is ->
{
final ItemStack extraA = ia.addItems( storageCellStack );
final ItemStack extraA = ia.addItems( is );
if( extraA != null )
{
player.dropItem( extraA, false );
}
}
} );
if( player.inventoryContainer != null )
{
@@ -289,12 +289,8 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe
@Override
public ItemStack getContainerItem( final ItemStack itemStack )
{
for( final ItemStack stack : AEApi.instance().definitions().materials().emptyStorageCell().maybeStack( 1 ).asSet() )
{
return stack;
}
throw new MissingDefinition( "Tried to use empty storage cells while basic storage cells are defined." );
return AEApi.instance().definitions().materials().emptyStorageCell().maybeStack( 1 )
.orElseThrow( () -> new MissingDefinition( "Tried to use empty storage cells while basic storage cells are defined." ) );
}
@Override
@@ -293,10 +293,10 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
final Block whatsThere = w.getBlockState( hitPos ).getBlock();
if( whatsThere.isReplaceable( w, hitPos ) && w.isAirBlock( hitPos ) )
{
for( final Block paintBlock : AEApi.instance().definitions().blocks().paint().maybeBlock().asSet() )
AEApi.instance().definitions().blocks().paint().maybeBlock().ifPresent( paintBlock ->
{
w.setBlockState( hitPos, paintBlock.getDefaultState(), 3 );
}
} );
}
final TileEntity te = w.getTileEntity( hitPos );
@@ -19,7 +19,7 @@
package appeng.items.tools.powered.powersink;
//import com.google.common.base.Optional;
//import java.util.Optional;
//
//import net.minecraft.entity.EntityLivingBase;
//import net.minecraft.item.Item;
@@ -19,7 +19,7 @@
package appeng.items.tools.powered.powersink;
//import com.google.common.base.Optional;
//import java.util.Optional;
//
//import net.minecraft.item.ItemStack;
//