Refactored StorageChannel enum into an interface (#3138)

This replaces the static enum with a more dynamic interface providing
factory methods for handling network storage.
This commit is contained in:
yueh
2017-10-08 17:59:30 +02:00
committed by GitHub
parent 8ad8ce68b5
commit 6e81f698c0
115 changed files with 1255 additions and 943 deletions
@@ -56,6 +56,7 @@ import appeng.api.networking.security.IActionSource;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.me.InternalSlotME;
import appeng.client.me.SlotME;
@@ -204,7 +205,7 @@ public abstract class AEBaseContainer extends Container
final NBTTagCompound data = CompressedStreamTools.readCompressed( new ByteArrayInputStream( buffer ) );
if( data != null )
{
this.setTargetStack( AEApi.instance().storage().createItemStack( new ItemStack( data ) ) );
this.setTargetStack( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( new ItemStack( data ) ) );
}
}
catch( final IOException e )
@@ -893,7 +894,7 @@ public abstract class AEBaseContainer extends Container
if( !isg.isEmpty() && releaseQty > 0 )
{
IAEItemStack ais = AEApi.instance().storage().createItemStack( isg );
IAEItemStack ais = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( isg );
ais.setStackSize( 1 );
final IAEItemStack extracted = ais.copy();
@@ -983,7 +984,7 @@ public abstract class AEBaseContainer extends Container
}
else
{
IAEItemStack ais = AEApi.instance().storage().createItemStack( player.inventory.getItemStack() );
IAEItemStack ais = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( player.inventory.getItemStack() );
ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() );
if( ais != null )
{
@@ -1032,7 +1033,7 @@ public abstract class AEBaseContainer extends Container
}
else
{
IAEItemStack ais = AEApi.instance().storage().createItemStack( player.inventory.getItemStack() );
IAEItemStack ais = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( player.inventory.getItemStack() );
ais.setStackSize( 1 );
ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() );
if( ais == null )
@@ -1107,7 +1108,7 @@ public abstract class AEBaseContainer extends Container
{
try
{
NetworkHandler.instance().sendTo( new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.create( p.inventory.getItemStack() ) ),
NetworkHandler.instance().sendTo( new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.fromItemStack( p.inventory.getItemStack() ) ),
p );
}
catch( final IOException e )
@@ -1123,7 +1124,8 @@ public abstract class AEBaseContainer extends Container
{
return input;
}
final IAEItemStack ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(), AEApi.instance().storage().createItemStack( input ),
final IAEItemStack ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(),
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( input ),
this.getActionSource() );
if( ais == null )
{
@@ -35,7 +35,7 @@ import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
import appeng.api.storage.ICellWorkbenchItem;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.guisync.GuiSync;
@@ -227,12 +227,14 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
final IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell().getCellInventory(
this.getUpgradeable().getInventoryByName( "cell" ).getStackInSlot( 0 ), null, StorageChannel.ITEMS );
this.getUpgradeable().getInventoryByName( "cell" ).getStackInSlot( 0 ), null,
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
Iterator<IAEItemStack> i = new NullIterator<>();
if( cellInv != null )
{
final IItemList<IAEItemStack> list = cellInv.getAvailableItems( AEApi.instance().storage().createItemList() );
final IItemList<IAEItemStack> list = cellInv
.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
i = list.iterator();
}
@@ -49,6 +49,7 @@ import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
@@ -208,7 +209,7 @@ public class ContainerCraftConfirm extends AEBaseContainer
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
final PacketMEInventoryUpdate c = this.result.isSimulation() ? new PacketMEInventoryUpdate( (byte) 2 ) : null;
final IItemList<IAEItemStack> plan = AEApi.instance().storage().createItemList();
final IItemList<IAEItemStack> plan = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
this.result.populatePlan( plan );
this.setUsedBytes( this.result.getByteTotal() );
@@ -225,7 +226,7 @@ public class ContainerCraftConfirm extends AEBaseContainer
p.setStackSize( out.getCountRequestable() );
final IStorageGrid sg = this.getGrid().getCache( IStorageGrid.class );
final IMEInventory<IAEItemStack> items = sg.getItemInventory();
final IMEInventory<IAEItemStack> items = sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
IAEItemStack m = null;
if( c != null && this.result.isSimulation() )
@@ -34,6 +34,7 @@ import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
@@ -52,7 +53,7 @@ import appeng.util.Platform;
public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorHandlerReceiver<IAEItemStack>, ICustomNameObject
{
private final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
private IGrid network;
private CraftingCPUCluster monitor = null;
private String cpuName = null;
@@ -54,6 +54,7 @@ import appeng.api.parts.IPart;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
@@ -77,7 +78,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
private final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
private final IMEMonitor<IAEItemStack> monitor;
private final IItemList<IAEItemStack> items = AEApi.instance().storage().createItemList();
private final IItemList<IAEItemStack> items = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
private final IConfigManager clientCM;
private final ITerminalHost host;
@GuiSync( 99 )
@@ -108,7 +109,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
{
this.serverCM = monitorable.getConfigManager();
this.monitor = monitorable.getItemInventory();
this.monitor = monitorable.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
if( this.monitor != null )
{
this.monitor.addListener( this, null );
@@ -188,7 +189,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
{
if( Platform.isServer() )
{
if( this.monitor != this.host.getItemInventory() )
if( this.monitor != this.host.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) )
{
this.setValidContainer( false );
}
@@ -33,6 +33,7 @@ import appeng.api.networking.IGridBlock;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
@@ -113,14 +114,14 @@ public class ContainerNetworkStatus extends AEBaseContainer
for( final Class<? extends IGridHost> machineClass : this.network.getMachinesClasses() )
{
final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
for( final IGridNode machine : this.network.getMachines( machineClass ) )
{
final IGridBlock blk = machine.getGridBlock();
final ItemStack is = blk.getMachineRepresentation();
if( !is.isEmpty() )
{
final IAEItemStack ais = AEItemStack.create( is );
final IAEItemStack ais = AEItemStack.fromItemStack( is );
ais.setStackSize( 1 );
ais.setCountRequestable( (long) ( blk.getIdlePowerUsage() * 100.0 ) );
list.add( ais );
@@ -45,6 +45,7 @@ import appeng.api.config.Actionable;
import appeng.api.definitions.IDefinitions;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull;
@@ -398,7 +399,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
return;
}
final IMEMonitor<IAEItemStack> storage = this.getPatternTerminal().getItemInventory();
final IMEMonitor<IAEItemStack> storage = this.getPatternTerminal()
.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final IItemList<IAEItemStack> all = storage.getStorageList();
final ItemStack is = r.getCraftingResult( ic );
@@ -447,7 +449,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
final ItemStack failed = real.getStackInSlot( x );
if( !failed.isEmpty() )
{
this.getCellInventory().injectItems( AEItemStack.create( failed ), Actionable.MODULATE,
this.getCellInventory().injectItems( AEItemStack.fromItemStack( failed ), Actionable.MODULATE,
new MachineSource( this.getPatternTerminal() ) );
}
}
@@ -33,6 +33,7 @@ import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.config.Upgrades;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.guisync.GuiSync;
@@ -157,7 +158,8 @@ public class ContainerStorageBus extends ContainerUpgradeable
Iterator<IAEItemStack> i = new NullIterator<>();
if( cellInv != null )
{
final IItemList<IAEItemStack> list = cellInv.getAvailableItems( AEApi.instance().storage().createItemList() );
final IItemList<IAEItemStack> list = cellInv
.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
i = list.iterator();
}
@@ -34,11 +34,13 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull;
@@ -105,7 +107,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
return;
}
final IMEMonitor<IAEItemStack> inv = this.storage.getItemInventory();
final IMEMonitor<IAEItemStack> inv = this.storage.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final int howManyPerCraft = this.getStack().getCount();
int maxTimesToCraft = 0;
@@ -306,7 +308,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
else if( !set[x].isEmpty() )
{
// eek! put it back!
final IAEItemStack fail = inv.injectItems( AEItemStack.create( set[x] ), Actionable.MODULATE, this.mySrc );
final IAEItemStack fail = inv.injectItems( AEItemStack.fromItemStack( set[x] ), Actionable.MODULATE, this.mySrc );
if( fail != null )
{
drops.add( fail.createItemStack() );
@@ -29,6 +29,7 @@ import appeng.api.AEApi;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket;
@@ -50,7 +51,8 @@ public class SlotPatternTerm extends SlotCraftingTerm
public AppEngPacket getRequest( final boolean shift ) throws IOException
{
return new PacketPatternSlot( this.getPattern(), AEApi.instance().storage().createItemStack( this.getStack() ), shift );
return new PacketPatternSlot( this
.getPattern(), AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( this.getStack() ), shift );
}
@Override