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
+17 -13
View File
@@ -44,6 +44,7 @@ import com.google.common.collect.Multimap;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.IGrid;
@@ -71,7 +72,8 @@ import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.ICellProvider;
import appeng.api.storage.IMEInventoryHandler;
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.IAEStack;
import appeng.api.storage.data.IItemList;
@@ -87,7 +89,7 @@ import appeng.tile.crafting.TileCraftingTile;
import appeng.util.ItemSorters;
public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler<IAEStack>
public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler<IAEItemStack>
{
private static final ExecutorService CRAFTING_POOL;
@@ -264,7 +266,8 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
this.emitableItems.clear();
// update the stuff that was in the list...
this.storageGrid.postAlterationOfStoredItems( StorageChannel.ITEMS, oldItems.keySet(), new BaseActionSource() );
this.storageGrid.postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), oldItems.keySet(),
new BaseActionSource() );
// re-create list..
for( final ICraftingProvider provider : this.craftingProviders )
@@ -300,7 +303,8 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
this.craftableItems.put( e.getKey(), ImmutableList.copyOf( e.getValue() ) );
}
this.storageGrid.postAlterationOfStoredItems( StorageChannel.ITEMS, this.craftableItems.keySet(), new BaseActionSource() );
this.storageGrid.postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), this.craftableItems.keySet(),
new BaseActionSource() );
}
private void updateCPUClusters()
@@ -375,11 +379,11 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
}
@Override
public List<IMEInventoryHandler> getCellArray( final StorageChannel channel )
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
{
final List<IMEInventoryHandler> list = new ArrayList<>( 1 );
if( channel == StorageChannel.ITEMS )
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
list.add( this );
}
@@ -400,13 +404,13 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
}
@Override
public boolean isPrioritized( final IAEStack input )
public boolean isPrioritized( final IAEItemStack input )
{
return true;
}
@Override
public boolean canAccept( final IAEStack input )
public boolean canAccept( final IAEItemStack input )
{
for( final CraftingCPUCluster cpu : this.craftingCPUClusters )
{
@@ -432,7 +436,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
}
@Override
public IAEStack injectItems( IAEStack input, final Actionable type, final IActionSource src )
public IAEItemStack injectItems( IAEItemStack input, final Actionable type, final IActionSource src )
{
for( final CraftingCPUCluster cpu : this.craftingCPUClusters )
{
@@ -443,13 +447,13 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
}
@Override
public IAEStack extractItems( final IAEStack request, final Actionable mode, final IActionSource src )
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final IActionSource src )
{
return null;
}
@Override
public IItemList<IAEStack> getAvailableItems( final IItemList<IAEStack> out )
public IItemList<IAEItemStack> getAvailableItems( final IItemList<IAEItemStack> out )
{
// add craftable items!
for( final IAEItemStack stack : this.craftableItems.keySet() )
@@ -466,9 +470,9 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
}
@Override
public StorageChannel getChannel()
public IStorageChannel<IAEItemStack> getChannel()
{
return StorageChannel.ITEMS;
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
+61 -133
View File
@@ -21,8 +21,10 @@ package appeng.me.cache;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
@@ -44,8 +46,7 @@ import appeng.api.storage.ICellContainer;
import appeng.api.storage.ICellProvider;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
@@ -64,22 +65,23 @@ public class GridStorageCache implements IStorageGrid
private final HashSet<ICellProvider> inactiveCellProviders = new HashSet<>();
private final SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
private final GenericInterestManager<ItemWatcher> interestManager = new GenericInterestManager<>( this.interests );
private final NetworkMonitor<IAEItemStack> itemMonitor = new NetworkMonitor<>( this, StorageChannel.ITEMS );
private final NetworkMonitor<IAEFluidStack> fluidMonitor = new NetworkMonitor<>( this, StorageChannel.FLUIDS );
private final HashMap<IGridNode, IStackWatcher> watchers = new HashMap<>();
private NetworkInventoryHandler<IAEItemStack> myItemNetwork;
private NetworkInventoryHandler<IAEFluidStack> myFluidNetwork;
private Map<IStorageChannel<? extends IAEStack>, NetworkInventoryHandler<?>> storageNetworks;
private Map<IStorageChannel<? extends IAEStack>, NetworkMonitor<?>> storageMonitors;
public GridStorageCache( final IGrid g )
{
this.myGrid = g;
this.storageNetworks = new IdentityHashMap<>();
this.storageMonitors = new IdentityHashMap<>();
AEApi.instance().storage().storageChannels().forEach( channel -> this.storageMonitors.put( channel, new NetworkMonitor<>( this, channel ) ) );
}
@Override
public void onUpdateTick()
{
this.itemMonitor.onTick();
this.fluidMonitor.onTick();
this.storageMonitors.forEach( ( channel, monitor ) -> monitor.onTick() );
}
@Override
@@ -155,6 +157,17 @@ public class GridStorageCache implements IStorageGrid
}
public <T extends IAEStack<T>> IMEInventoryHandler<T> getInventoryHandler( IStorageChannel<T> channel )
{
return (IMEInventoryHandler<T>) this.storageNetworks.computeIfAbsent( channel, this::buildNetworkStorage );
}
@Override
public <T extends IAEStack<T>> IMEMonitor<T> getInventory( IStorageChannel<T> channel )
{
return (IMEMonitor<T>) this.storageMonitors.get( channel );
}
private CellChangeTracker addCellProvider( final ICellProvider cc, final CellChangeTracker tracker )
{
if( this.inactiveCellProviders.contains( cc ) )
@@ -162,21 +175,15 @@ public class GridStorageCache implements IStorageGrid
this.inactiveCellProviders.remove( cc );
this.activeCellProviders.add( cc );
IActionSource actionSrc = new BaseActionSource();
if( cc instanceof IActionHost )
{
actionSrc = new MachineSource( (IActionHost) cc );
}
final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource( (IActionHost) cc ) : new BaseActionSource();
for( final IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ) )
this.storageMonitors.forEach( ( channel, monitor ) ->
{
tracker.postChanges( StorageChannel.ITEMS, 1, h, actionSrc );
}
for( final IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ) )
{
tracker.postChanges( StorageChannel.FLUIDS, 1, h, actionSrc );
}
for( final IMEInventoryHandler<?> h : cc.getCellArray( channel ) )
{
tracker.postChanges( channel, 1, h, actionSrc );
}
} );
}
return tracker;
@@ -189,22 +196,15 @@ public class GridStorageCache implements IStorageGrid
this.activeCellProviders.remove( cc );
this.inactiveCellProviders.add( cc );
IActionSource actionSrc = new BaseActionSource();
final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource( (IActionHost) cc ) : new BaseActionSource();
if( cc instanceof IActionHost )
this.storageMonitors.forEach( ( channel, monitor ) ->
{
actionSrc = new MachineSource( (IActionHost) cc );
}
for( final IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ) )
{
tracker.postChanges( StorageChannel.ITEMS, -1, h, actionSrc );
}
for( final IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ) )
{
tracker.postChanges( StorageChannel.FLUIDS, -1, h, actionSrc );
}
for( final IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( channel ) )
{
tracker.postChanges( channel, -1, h, actionSrc );
}
} );
}
return tracker;
@@ -213,10 +213,9 @@ public class GridStorageCache implements IStorageGrid
@MENetworkEventSubscribe
public void cellUpdate( final MENetworkCellArrayUpdate ev )
{
this.myItemNetwork = null;
this.myFluidNetwork = null;
this.storageNetworks.clear();
final LinkedList<ICellProvider> ll = new LinkedList();
final List<ICellProvider> ll = new LinkedList<ICellProvider>();
ll.addAll( this.inactiveCellProviders );
ll.addAll( this.activeCellProviders );
@@ -249,85 +248,37 @@ public class GridStorageCache implements IStorageGrid
}
}
this.itemMonitor.forceUpdate();
this.fluidMonitor.forceUpdate();
this.storageMonitors.forEach( ( channel, monitor ) -> monitor.forceUpdate() );
tracker.applyChanges();
}
private void postChangesToNetwork( final StorageChannel chan, final int upOrDown, final IItemList availableItems, final IActionSource src )
private <T extends IAEStack<T>, C extends IStorageChannel<T>> void postChangesToNetwork( final C chan, final int upOrDown, final IItemList<T> availableItems, final IActionSource src )
{
switch( chan )
{
case FLUIDS:
this.fluidMonitor.postChange( upOrDown > 0, availableItems, src );
break;
case ITEMS:
this.itemMonitor.postChange( upOrDown > 0, availableItems, src );
break;
default:
}
this.storageMonitors.get( chan ).postChange( upOrDown > 0, (Iterable) availableItems, src );
}
IMEInventoryHandler<IAEItemStack> getItemInventoryHandler()
{
if( this.myItemNetwork == null )
{
this.buildNetworkStorage( StorageChannel.ITEMS );
}
return this.myItemNetwork;
}
private void buildNetworkStorage( final StorageChannel chan )
private <T extends IAEStack<T>, C extends IStorageChannel<T>> NetworkInventoryHandler<T> buildNetworkStorage( final C chan )
{
final SecurityCache security = this.getGrid().getCache( ISecurityGrid.class );
switch( chan )
{
case FLUIDS:
this.myFluidNetwork = new NetworkInventoryHandler<>( StorageChannel.FLUIDS, security );
for( final ICellProvider cc : this.activeCellProviders )
{
for( final IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( chan ) )
{
this.myFluidNetwork.addNewStorage( h );
}
}
break;
case ITEMS:
this.myItemNetwork = new NetworkInventoryHandler<>( StorageChannel.ITEMS, security );
for( final ICellProvider cc : this.activeCellProviders )
{
for( final IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( chan ) )
{
this.myItemNetwork.addNewStorage( h );
}
}
break;
default:
}
}
final NetworkInventoryHandler<T> storageNetwork = new NetworkInventoryHandler<>( chan, security );
IMEInventoryHandler<IAEFluidStack> getFluidInventoryHandler()
{
if( this.myFluidNetwork == null )
for( final ICellProvider cc : this.activeCellProviders )
{
this.buildNetworkStorage( StorageChannel.FLUIDS );
for( final IMEInventoryHandler<T> h : cc.getCellArray( chan ) )
{
storageNetwork.addNewStorage( h );
}
}
return this.myFluidNetwork;
return storageNetwork;
}
@Override
public void postAlterationOfStoredItems( final StorageChannel chan, final Iterable<? extends IAEStack> input, final IActionSource src )
public void postAlterationOfStoredItems( final IStorageChannel chan, final Iterable<? extends IAEStack> input, final IActionSource src )
{
if( chan == StorageChannel.ITEMS )
{
this.itemMonitor.postChange( true, (Iterable<IAEItemStack>) input, src );
}
else if( chan == StorageChannel.FLUIDS )
{
this.fluidMonitor.postChange( true, (Iterable<IAEFluidStack>) input, src );
}
this.storageMonitors.get( chan ).postChange( true, (Iterable) input, src );
}
@Override
@@ -344,18 +295,6 @@ public class GridStorageCache implements IStorageGrid
this.inactiveCellProviders.remove( provider );
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory()
{
return this.itemMonitor;
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
return this.fluidMonitor;
}
public GenericInterestManager<ItemWatcher> getInterestManager()
{
return this.interestManager;
@@ -366,32 +305,21 @@ public class GridStorageCache implements IStorageGrid
return this.myGrid;
}
private class CellChangeTrackerRecord
private class CellChangeTrackerRecord<T extends IAEStack<T>>
{
final StorageChannel channel;
final IStorageChannel<T> channel;
final int up_or_down;
final IItemList list;
final IItemList<T> list;
final IActionSource src;
public CellChangeTrackerRecord( final StorageChannel channel, final int i, final IMEInventoryHandler<? extends IAEStack> h, final IActionSource actionSrc )
public CellChangeTrackerRecord( final IStorageChannel<T> channel, final int i, final IMEInventoryHandler<T> h, final IActionSource actionSrc )
{
this.channel = channel;
this.up_or_down = i;
this.src = actionSrc;
if( channel == StorageChannel.ITEMS )
{
this.list = ( (IMEInventoryHandler<IAEItemStack>) h ).getAvailableItems( AEApi.instance().storage().createItemList() );
}
else if( channel == StorageChannel.FLUIDS )
{
this.list = ( (IMEInventoryHandler<IAEFluidStack>) h ).getAvailableItems( AEApi.instance().storage().createFluidList() );
}
else
{
this.list = null;
}
this.list = h.getAvailableItems( channel.createList() );
}
public void applyChanges()
@@ -400,19 +328,19 @@ public class GridStorageCache implements IStorageGrid
}
}
private class CellChangeTracker
private class CellChangeTracker<T extends IAEStack<T>>
{
final List<CellChangeTrackerRecord> data = new LinkedList<>();
final List<CellChangeTrackerRecord<T>> data = new LinkedList<>();
public void postChanges( final StorageChannel channel, final int i, final IMEInventoryHandler<? extends IAEStack> h, final IActionSource actionSrc )
public void postChanges( final IStorageChannel<T> channel, final int i, final IMEInventoryHandler<T> h, final IActionSource actionSrc )
{
this.data.add( new CellChangeTrackerRecord( channel, i, h, actionSrc ) );
this.data.add( new CellChangeTrackerRecord<T>( channel, i, h, actionSrc ) );
}
public void applyChanges()
{
for( final CellChangeTrackerRecord rec : this.data )
for( final CellChangeTrackerRecord<T> rec : this.data )
{
rec.applyChanges();
}
+10 -20
View File
@@ -40,7 +40,7 @@ import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.me.storage.ItemWatcher;
@@ -54,7 +54,7 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
@Nonnull
private final GridStorageCache myGridCache;
@Nonnull
private final StorageChannel myChannel;
private final IStorageChannel<T> myChannel;
@Nonnull
private final IItemList<T> cachedList;
@Nonnull
@@ -65,11 +65,11 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
@Nonnegative
private int localDepthSemaphore = 0;
public NetworkMonitor( final GridStorageCache cache, final StorageChannel chan )
public NetworkMonitor( final GridStorageCache cache, final IStorageChannel<T> chan )
{
this.myGridCache = cache;
this.myChannel = chan;
this.cachedList = (IItemList<T>) chan.createList();
this.cachedList = chan.createList();
this.listeners = new HashMap<>();
}
@@ -112,13 +112,13 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
}
@Override
public IItemList<T> getAvailableItems( final IItemList out )
public IItemList<T> getAvailableItems( final IItemList<T> out )
{
return this.getHandler().getAvailableItems( out );
}
@Override
public StorageChannel getChannel()
public IStorageChannel<T> getChannel()
{
return this.getHandler().getChannel();
}
@@ -188,18 +188,9 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
}
@Nullable
@SuppressWarnings( "unchecked" )
private IMEInventoryHandler<T> getHandler()
{
switch( this.myChannel )
{
case ITEMS:
return (IMEInventoryHandler<T>) this.myGridCache.getItemInventoryHandler();
case FLUIDS:
return (IMEInventoryHandler<T>) this.myGridCache.getFluidInventoryHandler();
default:
}
return null;
return this.myGridCache.getInventoryHandler( this.myChannel );
}
private Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> getListeners()
@@ -207,9 +198,9 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
return this.listeners.entrySet().iterator();
}
private T monitorDifference( final IAEStack original, final T leftOvers, final boolean extraction, final IActionSource src )
private T monitorDifference( final IAEStack<T> original, final T leftOvers, final boolean extraction, final IActionSource src )
{
final T diff = (T) original.copy();
final T diff = original.copy();
if( extraction )
{
@@ -283,7 +274,7 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
if( !list.isEmpty() )
{
IAEStack fullStack = this.getStorageList().findPrecise( changedItem );
IAEStack<T> fullStack = this.getStorageList().findPrecise( changedItem );
if( fullStack == null )
{
@@ -341,5 +332,4 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
this.myGridCache.getGrid().postEvent( new MENetworkStorageEvent( this, this.myChannel ) );
}
}
}
@@ -59,8 +59,8 @@ import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.WorldCoord;
import appeng.container.ContainerNull;
@@ -102,7 +102,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
private MECraftingInventory inventory = new MECraftingInventory();
private IAEItemStack finalOutput;
private boolean waiting = false;
private IItemList<IAEItemStack> waitingFor = AEApi.instance().storage().createItemList();
private IItemList<IAEItemStack> waitingFor = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
private long availableStorage = 0;
private MachineSource machineSrc = null;
private int accelerator = 0;
@@ -223,7 +223,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
}
}
public boolean canAccept( final IAEStack input )
public boolean canAccept( final IAEItemStack input )
{
if( input instanceof IAEItemStack )
{
@@ -236,7 +236,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
return false;
}
public IAEStack injectItems( final IAEStack input, final Actionable type, final IActionSource src )
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src )
{
if( !( input instanceof IAEItemStack ) )
{
@@ -303,7 +303,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
if( this.finalOutput.equals( what ) )
{
IAEStack leftover = what;
IAEItemStack leftover = what;
this.finalOutput.decStackSize( what.getStackSize() );
@@ -334,7 +334,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
if( this.finalOutput.equals( insert ) )
{
IAEStack leftover = input;
IAEItemStack leftover = input;
this.finalOutput.decStackSize( insert.getStackSize() );
@@ -546,7 +546,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
}
final IItemList<IAEItemStack> list;
this.getListOfItem( list = AEApi.instance().storage().createItemList(), CraftingItemList.ALL );
this.getListOfItem( list = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList(), CraftingItemList.ALL );
for( final IAEItemStack is : list )
{
this.postChange( is, this.machineSrc );
@@ -697,7 +697,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
if( !is.isEmpty() )
{
this.postChange( AEItemStack.create( is ), this.machineSrc );
this.postChange( AEItemStack.fromItemStack( is ), this.machineSrc );
ic.setInventorySlotContents( x, is );
found = true;
break;
@@ -737,7 +737,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
final ItemStack is = ic.getStackInSlot( x );
if( !is.isEmpty() )
{
this.inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, this.machineSrc );
this.inventory.injectItems( AEItemStack.fromItemStack( is ), Actionable.MODULATE, this.machineSrc );
}
}
ic = null;
@@ -767,7 +767,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
final ItemStack output = Platform.getContainerItem( ic.getStackInSlot( x ) );
if( !output.isEmpty() )
{
final IAEItemStack cItem = AEItemStack.create( output );
final IAEItemStack cItem = AEItemStack.fromItemStack( output );
this.postChange( cItem, this.machineSrc );
this.waitingFor.add( cItem );
this.postCraftingStatusChange( cItem );
@@ -800,7 +800,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
final ItemStack is = ic.getStackInSlot( x );
if( !is.isEmpty() )
{
this.inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, this.machineSrc );
this.inventory.injectItems( AEItemStack.fromItemStack( is ), Actionable.MODULATE, this.machineSrc );
}
}
}
@@ -818,7 +818,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
}
final IStorageGrid sg = g.getCache( IStorageGrid.class );
final IMEInventory<IAEItemStack> ii = sg.getItemInventory();
final IMEInventory<IAEItemStack> ii = sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
for( IAEItemStack is : this.inventory.getItemList() )
{
@@ -862,7 +862,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
}
final IStorageGrid sg = g.getCache( IStorageGrid.class );
final IMEInventory<IAEItemStack> storage = sg.getItemInventory();
final IMEInventory<IAEItemStack> storage = sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final MECraftingInventory ci = new MECraftingInventory( storage, true, false, false );
try
@@ -893,7 +893,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
this.submitLink( this.myLastLink );
this.submitLink( whatLink );
final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
this.getListOfItem( list, CraftingItemList.ALL );
for( final IAEItemStack ge : list )
{
@@ -1138,7 +1138,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
final NBTTagList list = new NBTTagList();
for( final Entry<ICraftingPatternDetails, TaskProgress> e : this.tasks.entrySet() )
{
final NBTTagCompound item = this.writeItem( AEItemStack.create( e.getKey().getPattern() ) );
final NBTTagCompound item = this.writeItem( AEItemStack.fromItemStack( e.getKey().getPattern() ) );
item.setLong( "craftingProgress", e.getValue().value );
list.appendTag( item );
}
@@ -1193,7 +1193,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
public void readFromNBT( final NBTTagCompound data )
{
this.finalOutput = AEItemStack.loadItemStackFromNBT( (NBTTagCompound) data.getTag( "finalOutput" ) );
this.finalOutput = AEItemStack.fromNBT( (NBTTagCompound) data.getTag( "finalOutput" ) );
for( final IAEItemStack ais : this.readList( (NBTTagList) data.getTag( "inventory" ) ) )
{
this.inventory.injectItems( ais, Actionable.MODULATE, this.machineSrc );
@@ -1213,7 +1213,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
for( int x = 0; x < list.tagCount(); x++ )
{
final NBTTagCompound item = list.getCompoundTagAt( x );
final IAEItemStack pattern = AEItemStack.loadItemStackFromNBT( item );
final IAEItemStack pattern = AEItemStack.fromNBT( item );
if( pattern != null && pattern.getItem() instanceof ICraftingPatternItem )
{
final ICraftingPatternItem cpi = (ICraftingPatternItem) pattern.getItem();
@@ -1261,7 +1261,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
private IItemList<IAEItemStack> readList( final NBTTagList tag )
{
final IItemList<IAEItemStack> out = AEApi.instance().storage().createItemList();
final IItemList<IAEItemStack> out = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
if( tag == null )
{
@@ -1270,7 +1270,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
for( int x = 0; x < tag.tagCount(); x++ )
{
final IAEItemStack ais = AEItemStack.loadItemStackFromNBT( tag.getCompoundTagAt( x ) );
final IAEItemStack ais = AEItemStack.fromNBT( tag.getCompoundTagAt( x ) );
if( ais != null )
{
out.add( ais );
@@ -1306,7 +1306,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
this.lastTime = System.nanoTime();
this.elapsedTime = 0;
final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
this.getListOfItem( list, CraftingItemList.ACTIVE );
this.getListOfItem( list, CraftingItemList.PENDING );
@@ -155,7 +155,8 @@ public class QuantumCluster implements ILocatable, IAECluster
}
}
sideA.connection = sideB.connection = new ConnectionWrapper( AEApi.instance().createGridConnection( sideA.getNode(), sideB.getNode() ) );
sideA.connection = sideB.connection = new ConnectionWrapper( AEApi.instance().grid().createGridConnection( sideA.getNode(),
sideB.getNode() ) );
}
catch( final FailedConnection e )
{
@@ -147,7 +147,7 @@ public class AENetworkProxy implements IGridBlock
{
if( this.node == null && Platform.isServer() && this.isReady )
{
this.node = AEApi.instance().createGridNode( this );
this.node = AEApi.instance().grid().createGridNode( this );
this.readFromNBT( this.data );
this.node.updateState();
}
@@ -37,7 +37,8 @@ import appeng.api.storage.ICellInventory;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider;
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.AEConfig;
@@ -197,7 +198,7 @@ public class CellInventory implements ICellInventory
private boolean isEmpty( final IMEInventory meInventory )
{
return meInventory.getAvailableItems( AEApi.instance().storage().createItemList() ).isEmpty();
return meInventory.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() ).isEmpty();
}
@Override
@@ -275,12 +276,12 @@ public class CellInventory implements ICellInventory
final ItemStack toWrite = sharedItemStack.copy();
toWrite.setCount( remainingItemCount );
this.cellItems.add( AEItemStack.create( toWrite ) );
this.cellItems.add( AEItemStack.fromItemStack( toWrite ) );
this.updateItemCount( toWrite.getCount() );
this.saveChanges();
}
return AEItemStack.create( toReturn );
return AEItemStack.fromItemStack( toReturn );
}
if( mode == Actionable.MODULATE )
@@ -343,7 +344,7 @@ public class CellInventory implements ICellInventory
{
if( this.cellItems == null )
{
this.cellItems = AEApi.instance().storage().createItemList();
this.cellItems = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
this.loadCellItems();
}
@@ -424,7 +425,7 @@ public class CellInventory implements ICellInventory
{
if( this.cellItems == null )
{
this.cellItems = AEApi.instance().storage().createItemList();
this.cellItems = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
}
this.cellItems.resetStatus(); // clears totals and stuff.
@@ -471,7 +472,7 @@ public class CellInventory implements ICellInventory
{
try
{
this.cellItems.add( AEItemStack.create( t ) );
this.cellItems.add( AEItemStack.fromItemStack( t ) );
}
catch( Throwable ex )
{
@@ -497,9 +498,9 @@ public class CellInventory implements ICellInventory
}
@Override
public StorageChannel getChannel()
public IStorageChannel getChannel()
{
return StorageChannel.ITEMS;
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
@@ -31,7 +31,7 @@ import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
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.util.Platform;
@@ -45,12 +45,12 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
CellInventoryHandler( final IMEInventory c )
{
super( c, StorageChannel.ITEMS );
super( c, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final ICellInventory ci = this.getCellInv();
if( ci != null )
{
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
final IItemHandler upgrades = ci.getUpgradesInventory();
final IItemHandler config = ci.getConfigInventory();
@@ -86,7 +86,7 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
final ItemStack is = config.getStackInSlot( x );
if( !is.isEmpty() )
{
priorityList.add( AEItemStack.create( is ) );
priorityList.add( AEItemStack.fromItemStack( is ) );
}
}
@@ -26,7 +26,8 @@ import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventoryHandler;
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.items.contents.CellConfig;
@@ -36,7 +37,7 @@ import appeng.util.item.AEItemStack;
public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
{
private final IItemList<IAEItemStack> itemListCache = AEApi.instance().storage().createItemList();
private final IItemList<IAEItemStack> itemListCache = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
protected CreativeCellInventory( final ItemStack o )
{
@@ -45,7 +46,7 @@ public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
{
if( !is.isEmpty() )
{
final IAEItemStack i = AEItemStack.create( is );
final IAEItemStack i = AEItemStack.fromItemStack( is );
i.setStackSize( Integer.MAX_VALUE );
this.itemListCache.add( i );
}
@@ -92,9 +93,9 @@ public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
}
@Override
public StorageChannel getChannel()
public IStorageChannel getChannel()
{
return StorageChannel.ITEMS;
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
@@ -25,7 +25,7 @@ import appeng.api.config.IncludeExclude;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.util.prioritylist.DefaultPriorityList;
@@ -45,7 +45,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
private boolean hasReadAccess;
private boolean hasWriteAccess;
public MEInventoryHandler( final IMEInventory<T> i, final StorageChannel channel )
public MEInventoryHandler( final IMEInventory<T> i, final IStorageChannel<T> channel )
{
if( i instanceof IMEInventoryHandler )
{
@@ -129,7 +129,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
}
@Override
public StorageChannel getChannel()
public IStorageChannel getChannel()
{
return this.internal.getChannel();
}
@@ -36,7 +36,8 @@ import appeng.api.networking.security.IActionSource;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.storage.IMEMonitor;
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.util.InventoryAdaptor;
@@ -48,7 +49,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, ITickingMo
{
private final InventoryAdaptor adaptor;
private final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
private final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<>();
private final NavigableMap<Integer, CachedItemStack> memory;
private IActionSource mySource;
@@ -134,9 +135,9 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, ITickingMo
}
@Override
public StorageChannel getChannel()
public IStorageChannel getChannel()
{
return StorageChannel.ITEMS;
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
@@ -180,7 +181,10 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, ITickingMo
final int newSize = ( newIS.isEmpty() ? 0 : newIS.getCount() );
final int diff = newSize - ( oldIS.isEmpty() ? 0 : oldIS.getCount() );
final IAEItemStack stack = ( old == null || old.aeStack == null ? AEApi.instance().storage().createItemStack( newIS ) : old.aeStack.copy() );
final IAEItemStack stack = ( old == null || old.aeStack == null ? AEApi.instance()
.storage()
.getStorageChannel( IItemStorageChannel.class )
.createStack( newIS ) : old.aeStack.copy() );
if( stack != null )
{
stack.setStackSize( newSize );
@@ -352,7 +356,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, ITickingMo
else
{
this.itemStack = is.copy();
this.aeStack = AEApi.instance().storage().createItemStack( is );
this.aeStack = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( is );
}
}
}
@@ -28,7 +28,7 @@ import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.util.Platform;
@@ -42,7 +42,7 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
private IActionSource changeSource;
private IMEMonitor<T> monitor;
public MEMonitorPassThrough( final IMEInventory<T> i, final StorageChannel channel )
public MEMonitorPassThrough( final IMEInventory<T> i, final IStorageChannel channel )
{
super( i, channel );
if( i instanceof IMEMonitor )
@@ -24,7 +24,7 @@ import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
@@ -32,10 +32,10 @@ import appeng.api.storage.data.IItemList;
public class MEPassThrough<T extends IAEStack<T>> implements IMEInventoryHandler<T>
{
private final StorageChannel wrappedChannel;
private final IStorageChannel wrappedChannel;
private IMEInventory<T> internal;
public MEPassThrough( final IMEInventory<T> i, final StorageChannel channel )
public MEPassThrough( final IMEInventory<T> i, final IStorageChannel channel )
{
this.wrappedChannel = channel;
this.setInternal( i );
@@ -70,7 +70,7 @@ public class MEPassThrough<T extends IAEStack<T>> implements IMEInventoryHandler
}
@Override
public StorageChannel getChannel()
public IStorageChannel getChannel()
{
return this.internal.getChannel();
}
@@ -111,7 +111,7 @@ public class MEPassThrough<T extends IAEStack<T>> implements IMEInventoryHandler
return true;
}
StorageChannel getWrappedChannel()
IStorageChannel getWrappedChannel()
{
return this.wrappedChannel;
}
@@ -35,7 +35,7 @@ import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.me.cache.SecurityCache;
@@ -50,12 +50,12 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
private static final Comparator<Integer> PRIORITY_SORTER = ( o1, o2 ) -> ItemSorters.compareInt( o2, o1 );
private static int currentPass = 0;
private final StorageChannel myChannel;
private final IStorageChannel<T> myChannel;
private final SecurityCache security;
private final NavigableMap<Integer, List<IMEInventoryHandler<T>>> priorityInventory;
private int myPass = 0;
public NetworkInventoryHandler( final StorageChannel chan, final SecurityCache security )
public NetworkInventoryHandler( final IStorageChannel<T> chan, final SecurityCache security )
{
this.myChannel = chan;
this.security = security;
@@ -240,7 +240,7 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
}
@Override
public IItemList<T> getAvailableItems( IItemList out )
public IItemList<T> getAvailableItems( IItemList<T> out )
{
if( this.diveIteration( this, Actionable.SIMULATE ) )
{
@@ -286,7 +286,7 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
}
@Override
public StorageChannel getChannel()
public IStorageChannel<T> getChannel()
{
return this.myChannel;
}
@@ -19,11 +19,13 @@
package appeng.me.storage;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
@@ -50,9 +52,9 @@ public class NullInventory<T extends IAEStack<T>> implements IMEInventoryHandler
}
@Override
public StorageChannel getChannel()
public IStorageChannel getChannel()
{
return StorageChannel.ITEMS;
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
@@ -28,7 +28,8 @@ import appeng.api.config.SecurityPermissions;
import appeng.api.implementations.items.IBiometricCard;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventoryHandler;
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.me.GridAccessException;
@@ -38,7 +39,7 @@ import appeng.tile.misc.TileSecurityStation;
public class SecurityStationInventory implements IMEInventoryHandler<IAEItemStack>
{
private final IItemList<IAEItemStack> storedItems = AEApi.instance().storage().createItemList();
private final IItemList<IAEItemStack> storedItems = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
private final TileSecurityStation securityTile;
public SecurityStationInventory( final TileSecurityStation ts )
@@ -120,9 +121,9 @@ public class SecurityStationInventory implements IMEInventoryHandler<IAEItemStac
}
@Override
public StorageChannel getChannel()
public IStorageChannel getChannel()
{
return StorageChannel.ITEMS;
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override