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
@@ -29,13 +29,15 @@ import java.util.Map;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.core.AELog;
@@ -92,7 +94,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
this.onTick();
}
return AEItemStack.create( remaining );
return AEItemStack.fromItemStack( remaining );
}
@Override
@@ -168,7 +170,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
this.onTick();
}
return AEItemStack.create( gathered );
return AEItemStack.fromItemStack( gathered );
}
return null;
@@ -255,7 +257,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
{
// Completely different item
this.cachedStacks[slot] = newIS;
this.cachedAeStacks[slot] = AEItemStack.create( newIS );
this.cachedAeStacks[slot] = AEItemStack.fromItemStack( newIS );
// If we had a stack previously in this slot, notify the newtork about its disappearance
if( oldAeIS != null )
@@ -330,16 +332,16 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
for( int i = 0; i < this.itemHandler.getSlots(); i++ )
{
out.addStorage( AEItemStack.create( this.itemHandler.getStackInSlot( i ) ) );
out.addStorage( AEItemStack.fromItemStack( this.itemHandler.getStackInSlot( i ) ) );
}
return out;
}
@Override
public StorageChannel getChannel()
public IStorageChannel getChannel()
{
return StorageChannel.ITEMS;
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
@@ -51,9 +51,10 @@ import appeng.api.networking.ticking.TickingRequest;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartModel;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.AECableType;
import appeng.api.util.IConfigManager;
import appeng.core.AppEng;
@@ -192,15 +193,9 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory()
public <T extends IAEStack<T>> IMEMonitor<T> getInventory( IStorageChannel<T> channel )
{
return this.duality.getItemInventory();
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
return this.duality.getFluidInventory();
return this.duality.getInventory( channel );
}
@Override
@@ -62,9 +62,10 @@ import appeng.api.storage.ICellContainer;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.IStorageMonitorableAccessor;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
@@ -257,7 +258,8 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
{
if( this.getProxy().isActive() )
{
this.getProxy().getStorage().postAlterationOfStoredItems( StorageChannel.ITEMS, change, this.mySrc );
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change,
this.mySrc );
}
}
catch( final GridAccessException e )
@@ -340,7 +342,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
this.resetCacheLogic = 0;
final IMEInventory<IAEItemStack> in = this.getInternalHandler();
IItemList<IAEItemStack> before = AEApi.instance().storage().createItemList();
IItemList<IAEItemStack> before = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
if( in != null )
{
before = in.getAvailableItems( before );
@@ -359,7 +361,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
this.monitor.onTick();
}
IItemList<IAEItemStack> after = AEApi.instance().storage().createItemList();
IItemList<IAEItemStack> after = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
if( out != null )
{
after = out.getAvailableItems( after );
@@ -382,7 +384,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
IStorageMonitorable inventory = accessor.getInventory( this.mySrc );
if( inventory != null )
{
return inventory.getItemInventory();
return inventory.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
}
// So this could / can be a design decision. If the tile does support our custom capability,
@@ -469,13 +471,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
{
this.checkInterfaceVsStorageBus( target, this.getSide().getOpposite() );
this.handler = new MEInventoryHandler<>( inv, StorageChannel.ITEMS );
this.handler = new MEInventoryHandler( inv, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
this.handler.setBaseAccess( (AccessRestriction) this.getConfigManager().getSetting( Settings.ACCESS ) );
this.handler.setWhitelist( this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
this.handler.setPriority( this.priority );
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
for( int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++ )
@@ -565,9 +567,9 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
}
@Override
public List<IMEInventoryHandler> getCellArray( final StorageChannel channel )
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
{
if( channel == StorageChannel.ITEMS )
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
final IMEInventoryHandler out = this.getProxy().isActive() ? this.getInternalHandler() : null;
if( out != null )
@@ -203,7 +203,7 @@ public class PartToggleBus extends PartBasicState
{
try
{
this.connection = AEApi.instance().createGridConnection( this.getProxy().getNode(), this.getOuterProxy().getNode() );
this.connection = AEApi.instance().grid().createGridConnection( this.getProxy().getNode(), this.getOuterProxy().getNode() );
}
catch( final FailedConnection e )
{