Replaced all instances of Guava's Optional type with Java 8's Optional type, as discussed in #81. (#90)
This commit is contained in:
committed by
Sebastian Hartte
parent
c2a239a12f
commit
e276aa682f
@@ -68,7 +68,7 @@ public class AEBaseTile extends TileEntity implements ITickable, IOrientable, IC
|
||||
|
||||
private static final ThreadLocal<WeakReference<AEBaseTile>> DROP_NO_ITEMS = new ThreadLocal<WeakReference<AEBaseTile>>();
|
||||
private static final Map<Class<? extends AEBaseTile>, Map<TileEventType, List<AETileEventHandler>>> HANDLERS = new HashMap<Class<? extends AEBaseTile>, Map<TileEventType, List<AETileEventHandler>>>();
|
||||
private static final Map<Class<? extends TileEntity>, IStackSrc> ITEM_STACKS = new HashMap<Class<? extends TileEntity>, IStackSrc>();
|
||||
private static final Map<Class<? extends TileEntity>, IStackSrc> ITEM_STACKS = new HashMap<>();
|
||||
private int renderFragment = 0;
|
||||
@Nullable
|
||||
private String customName;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
package appeng.tile.crafting;
|
||||
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -36,29 +38,25 @@ public class TileCraftingStorageTile extends TileCraftingTile
|
||||
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
||||
final int storage = ( (TileCraftingTile) obj ).getStorageBytes() / KILO_SCALAR;
|
||||
|
||||
Optional<ItemStack> is;
|
||||
|
||||
switch( storage )
|
||||
{
|
||||
case 4:
|
||||
for( final ItemStack stack : blocks.craftingStorage4k().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
is = blocks.craftingStorage4k().maybeStack( 1 );
|
||||
break;
|
||||
case 16:
|
||||
for( final ItemStack stack : blocks.craftingStorage16k().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
is = blocks.craftingStorage16k().maybeStack( 1 );
|
||||
break;
|
||||
case 64:
|
||||
for( final ItemStack stack : blocks.craftingStorage64k().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
is = blocks.craftingStorage64k().maybeStack( 1 );
|
||||
break;
|
||||
default:
|
||||
is = Optional.empty();
|
||||
break;
|
||||
}
|
||||
|
||||
return super.getItemFromTile( obj );
|
||||
return is.orElseGet( () -> super.getItemFromTile( obj ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -79,15 +80,14 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
@Override
|
||||
protected ItemStack getItemFromTile( final Object obj )
|
||||
{
|
||||
Optional<ItemStack> is = Optional.empty();
|
||||
|
||||
if( ( (TileCraftingTile) obj ).isAccelerator() )
|
||||
{
|
||||
for( final ItemStack accelerator : AEApi.instance().definitions().blocks().craftingAccelerator().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return accelerator;
|
||||
}
|
||||
is = AEApi.instance().definitions().blocks().craftingAccelerator().maybeStack( 1 );
|
||||
}
|
||||
|
||||
return super.getItemFromTile( obj );
|
||||
return is.orElseGet( () -> super.getItemFromTile( obj ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -167,10 +167,8 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, ITick
|
||||
{
|
||||
this.extractAEPower( this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
|
||||
|
||||
for( final ItemStack charged : materials.certusQuartzCrystalCharged().maybeStack( myItem.stackSize ).asSet() )
|
||||
{
|
||||
this.setInventorySlotContents( 0, charged );
|
||||
}
|
||||
materials.certusQuartzCrystalCharged().maybeStack( myItem.stackSize ).ifPresent( charged ->
|
||||
this.setInventorySlotContents( 0, charged ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,10 +207,8 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, ITick
|
||||
{
|
||||
this.extractAEPower( this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
|
||||
|
||||
for( final ItemStack charged : materials.certusQuartzCrystalCharged().maybeStack( myItem.stackSize ).asSet() )
|
||||
{
|
||||
this.setInventorySlotContents( 0, charged );
|
||||
}
|
||||
materials.certusQuartzCrystalCharged().maybeStack( myItem.stackSize ).ifPresent( charged ->
|
||||
this.setInventorySlotContents( 0, charged ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,21 +144,15 @@ public class TileCondenser extends AEBaseInvTile implements IFluidHandler, IConf
|
||||
switch( (CondenserOutput) this.cm.getSetting( Settings.CONDENSER_OUTPUT ) )
|
||||
{
|
||||
case MATTER_BALLS:
|
||||
for( final ItemStack matterBallStack : materials.matterBall().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return matterBallStack;
|
||||
}
|
||||
return materials.matterBall().maybeStack( 1 ).orElse( null );
|
||||
|
||||
case SINGULARITY:
|
||||
for( final ItemStack singularityStack : materials.singularity().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return singularityStack;
|
||||
}
|
||||
return materials.singularity().maybeStack( 1 ).orElse( null );
|
||||
|
||||
case TRASH:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getRequiredPower()
|
||||
|
||||
@@ -399,11 +399,11 @@ 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.isSameItemPrecise( plateA, recipe.getTopOptional().orNull() ) ) && // and...
|
||||
( plateB == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.isSameItemPrecise( plateB, recipe.getBottomOptional().orNull() ) );
|
||||
final boolean matchA = ( plateA == null && !recipe.getTopOptional().isPresent() ) || ( Platform.isSameItemPrecise( plateA, recipe.getTopOptional().orElse( null ) ) ) && // and...
|
||||
( plateB == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.isSameItemPrecise( plateB, recipe.getBottomOptional().orElse( null ) ) );
|
||||
|
||||
final boolean matchB = ( plateB == null && !recipe.getTopOptional().isPresent() ) || ( Platform.isSameItemPrecise( plateB, recipe.getTopOptional().orNull() ) ) && // and...
|
||||
( plateA == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.isSameItemPrecise( plateA, recipe.getBottomOptional().orNull() ) );
|
||||
final boolean matchB = ( plateB == null && !recipe.getTopOptional().isPresent() ) || ( Platform.isSameItemPrecise( plateB, recipe.getTopOptional().orElse( null ) ) ) && // and...
|
||||
( plateA == null && !recipe.getBottomOptional().isPresent() ) | ( Platform.isSameItemPrecise( plateA, recipe.getBottomOptional().orElse( null ) ) );
|
||||
|
||||
if( matchA || matchB )
|
||||
{
|
||||
|
||||
@@ -20,8 +20,7 @@ package appeng.tile.qnb;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import java.util.Optional;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@@ -143,12 +142,9 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
|
||||
private boolean isCenter()
|
||||
{
|
||||
for( final Block link : AEApi.instance().definitions().blocks().quantumLink().maybeBlock().asSet() )
|
||||
{
|
||||
return this.getBlockType() == link;
|
||||
}
|
||||
|
||||
return false;
|
||||
return AEApi.instance().definitions().blocks().quantumLink().maybeBlock()
|
||||
.map( link -> getBlockType() == link )
|
||||
.orElse( false );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
|
||||
Reference in New Issue
Block a user