2014-05-09 06:10:12 +02:00
|
|
|
package appeng.me.cache;
|
|
|
|
|
2014-05-19 03:05:03 +02:00
|
|
|
import java.util.ArrayList;
|
2014-07-18 05:39:18 +02:00
|
|
|
import java.util.Collection;
|
2014-07-11 06:46:51 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2014-05-19 03:05:03 +02:00
|
|
|
import java.util.HashMap;
|
2014-05-09 06:10:12 +02:00
|
|
|
import java.util.HashSet;
|
2014-07-04 08:19:35 +02:00
|
|
|
import java.util.Iterator;
|
2014-05-19 03:05:03 +02:00
|
|
|
import java.util.List;
|
2014-07-03 06:48:18 +02:00
|
|
|
import java.util.Map.Entry;
|
2014-06-06 06:26:01 +02:00
|
|
|
import java.util.Set;
|
2014-07-03 06:48:18 +02:00
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.Future;
|
|
|
|
import java.util.concurrent.ThreadFactory;
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
import net.minecraft.world.World;
|
2014-05-19 03:05:03 +02:00
|
|
|
import appeng.api.config.AccessRestriction;
|
|
|
|
import appeng.api.config.Actionable;
|
2014-05-18 05:19:23 +02:00
|
|
|
import appeng.api.networking.IGrid;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.api.networking.IGridHost;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.IGridStorage;
|
2014-07-03 06:48:18 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingCPU;
|
|
|
|
import appeng.api.networking.crafting.ICraftingCallback;
|
|
|
|
import appeng.api.networking.crafting.ICraftingGrid;
|
|
|
|
import appeng.api.networking.crafting.ICraftingJob;
|
2014-07-04 08:19:35 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingLink;
|
2014-05-19 03:05:03 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingMedium;
|
2014-05-18 05:19:23 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingProvider;
|
2014-05-18 05:19:23 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingProviderHelper;
|
2014-07-04 08:19:35 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingRequester;
|
2014-06-28 07:20:12 +02:00
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
2014-05-18 05:19:23 +02:00
|
|
|
import appeng.api.networking.events.MENetworkCraftingCpuChange;
|
|
|
|
import appeng.api.networking.events.MENetworkCraftingPatternChange;
|
2014-05-20 06:13:12 +02:00
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
2014-05-19 03:05:03 +02:00
|
|
|
import appeng.api.networking.events.MENetworkPostCacheConstruction;
|
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
|
|
|
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.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IAEStack;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
2014-06-19 08:28:45 +02:00
|
|
|
import appeng.crafting.CraftingJob;
|
2014-07-04 08:19:35 +02:00
|
|
|
import appeng.crafting.CraftingLink;
|
|
|
|
import appeng.crafting.CraftingLinkNexus;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
2014-05-18 05:19:23 +02:00
|
|
|
import appeng.tile.crafting.TileCraftingStorageTile;
|
|
|
|
import appeng.tile.crafting.TileCraftingTile;
|
2014-07-11 06:46:51 +02:00
|
|
|
import appeng.util.ItemSorters;
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
import com.google.common.collect.ImmutableCollection;
|
2014-06-19 08:28:45 +02:00
|
|
|
import com.google.common.collect.ImmutableList;
|
2014-06-16 07:48:43 +02:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
2014-07-18 05:38:57 +02:00
|
|
|
import com.google.common.collect.ImmutableSortedSet;
|
2014-06-16 07:48:43 +02:00
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
HashSet<CraftingCPUCluster> cpuClusters = new HashSet();
|
|
|
|
HashSet<ICraftingProvider> providers = new HashSet();
|
2014-06-28 07:20:12 +02:00
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
IGrid grid;
|
2014-06-28 07:20:12 +02:00
|
|
|
IStorageGrid sg;
|
|
|
|
IEnergyGrid eg;
|
2014-05-18 05:19:23 +02:00
|
|
|
|
2014-05-19 03:05:03 +02:00
|
|
|
HashMap<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new HashMap();
|
2014-07-03 06:48:18 +02:00
|
|
|
HashMap<IAEItemStack, ImmutableSet<ICraftingPatternDetails>> craftableItems = new HashMap();
|
2014-07-04 08:19:35 +02:00
|
|
|
HashMap<String, CraftingLinkNexus> links = new HashMap();
|
2014-05-19 03:05:03 +02:00
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
boolean updateList = false;
|
|
|
|
|
2014-07-18 05:39:18 +02:00
|
|
|
class ActiveCpuIterator implements Iterator<ICraftingCPU>
|
|
|
|
{
|
|
|
|
|
|
|
|
final Iterator<CraftingCPUCluster> i;
|
|
|
|
CraftingCPUCluster c = null;
|
|
|
|
|
|
|
|
public ActiveCpuIterator(Collection<CraftingCPUCluster> o) {
|
|
|
|
i = o.iterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext()
|
|
|
|
{
|
|
|
|
findNext();
|
|
|
|
return c != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void findNext()
|
|
|
|
{
|
|
|
|
while (i.hasNext() && c == null)
|
|
|
|
{
|
|
|
|
c = i.next();
|
|
|
|
if ( !c.isActive() || c.isDestroyed )
|
|
|
|
c = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ICraftingCPU next()
|
|
|
|
{
|
|
|
|
ICraftingCPU o = c;
|
|
|
|
c = null;
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove()
|
|
|
|
{
|
|
|
|
// no..
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-07-11 06:46:51 +02:00
|
|
|
@Override
|
|
|
|
public ImmutableSet<ICraftingCPU> getCpus()
|
|
|
|
{
|
2014-07-18 05:39:18 +02:00
|
|
|
return ImmutableSet.copyOf( new ActiveCpuIterator( cpuClusters ) );
|
2014-07-11 06:46:51 +02:00
|
|
|
}
|
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
public CraftingGridCache(IGrid g) {
|
2014-05-18 05:19:23 +02:00
|
|
|
grid = g;
|
|
|
|
}
|
|
|
|
|
2014-05-23 04:42:27 +02:00
|
|
|
@MENetworkEventSubscribe
|
2014-05-19 03:05:03 +02:00
|
|
|
public void afterCacheConstruction(MENetworkPostCacheConstruction cc)
|
|
|
|
{
|
2014-06-28 07:20:12 +02:00
|
|
|
sg = grid.getCache( IStorageGrid.class );
|
|
|
|
eg = grid.getCache( IEnergyGrid.class );
|
|
|
|
|
2014-05-23 04:42:27 +02:00
|
|
|
sg.registerCellProvider( this );
|
2014-05-19 03:05:03 +02:00
|
|
|
}
|
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
public void addLink(CraftingLink l)
|
|
|
|
{
|
|
|
|
if ( l.isStandalone() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
CraftingLinkNexus n = links.get( l.getCraftingID() );
|
|
|
|
if ( n == null )
|
|
|
|
links.put( l.getCraftingID(), n = new CraftingLinkNexus( l.getCraftingID() ) );
|
|
|
|
|
|
|
|
l.setNextus( n );
|
|
|
|
}
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
@Override
|
|
|
|
public void onUpdateTick()
|
|
|
|
{
|
2014-05-18 05:19:23 +02:00
|
|
|
if ( updateList )
|
|
|
|
{
|
|
|
|
updateList = false;
|
|
|
|
updateCPUClusters();
|
|
|
|
}
|
2014-06-19 08:28:45 +02:00
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
Iterator<CraftingLinkNexus> i = links.values().iterator();
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
if ( i.next().isDead( grid, this ) )
|
|
|
|
i.remove();
|
|
|
|
}
|
|
|
|
|
2014-06-19 08:28:45 +02:00
|
|
|
for (CraftingCPUCluster cpu : cpuClusters)
|
2014-06-28 07:20:12 +02:00
|
|
|
cpu.updateCraftingLogic( grid, eg, this );
|
2014-05-18 05:19:23 +02:00
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2014-05-20 06:13:12 +02:00
|
|
|
@MENetworkEventSubscribe
|
2014-05-18 05:19:23 +02:00
|
|
|
public void updateCPUClusters(MENetworkCraftingCpuChange c)
|
|
|
|
{
|
|
|
|
updateList = true;
|
|
|
|
}
|
|
|
|
|
2014-05-20 06:13:12 +02:00
|
|
|
@MENetworkEventSubscribe
|
2014-05-18 05:19:23 +02:00
|
|
|
public void updateCPUClusters(MENetworkCraftingPatternChange c)
|
|
|
|
{
|
|
|
|
updatePatterns();
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeNode(IGridNode gridNode, IGridHost machine)
|
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
if ( machine instanceof ICraftingRequester )
|
|
|
|
{
|
|
|
|
Iterator<CraftingLinkNexus> nex = links.values().iterator();
|
|
|
|
while (nex.hasNext())
|
|
|
|
{
|
|
|
|
CraftingLinkNexus n = nex.next();
|
|
|
|
if ( n.isMachine( machine ) )
|
|
|
|
n.removeNode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
if ( machine instanceof TileCraftingTile )
|
|
|
|
updateList = true;
|
2014-05-09 06:10:12 +02:00
|
|
|
if ( machine instanceof ICraftingProvider )
|
2014-05-18 05:19:23 +02:00
|
|
|
{
|
2014-05-09 06:10:12 +02:00
|
|
|
providers.remove( machine );
|
2014-05-18 05:19:23 +02:00
|
|
|
updatePatterns();
|
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addNode(IGridNode gridNode, IGridHost machine)
|
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
if ( machine instanceof ICraftingRequester )
|
|
|
|
{
|
|
|
|
for (ICraftingLink l : ((ICraftingRequester) machine).getRequestedJobs())
|
|
|
|
{
|
|
|
|
if ( l instanceof CraftingLink )
|
|
|
|
addLink( (CraftingLink) l );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
if ( machine instanceof TileCraftingTile )
|
|
|
|
updateList = true;
|
2014-05-09 06:10:12 +02:00
|
|
|
if ( machine instanceof ICraftingProvider )
|
2014-05-18 05:19:23 +02:00
|
|
|
{
|
2014-05-09 06:10:12 +02:00
|
|
|
providers.add( (ICraftingProvider) machine );
|
2014-05-18 05:19:23 +02:00
|
|
|
updatePatterns();
|
|
|
|
}
|
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
private void updateCPUClusters()
|
|
|
|
{
|
|
|
|
cpuClusters.clear();
|
|
|
|
for (IGridNode cst : grid.getMachines( TileCraftingStorageTile.class ))
|
|
|
|
{
|
|
|
|
TileCraftingStorageTile tile = (TileCraftingStorageTile) cst.getMachine();
|
2014-06-19 08:28:45 +02:00
|
|
|
CraftingCPUCluster clust = (CraftingCPUCluster) tile.getCluster();
|
|
|
|
if ( clust != null )
|
2014-07-04 08:19:35 +02:00
|
|
|
{
|
2014-06-19 08:28:45 +02:00
|
|
|
cpuClusters.add( clust );
|
2014-07-04 08:19:35 +02:00
|
|
|
|
|
|
|
if ( clust.myLastLink != null )
|
|
|
|
addLink( (CraftingLink) clust.myLastLink );
|
|
|
|
}
|
2014-05-18 05:19:23 +02:00
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
@Override
|
2014-05-19 03:05:03 +02:00
|
|
|
public void addCraftingOption(ICraftingMedium medium, ICraftingPatternDetails api)
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2014-05-19 03:05:03 +02:00
|
|
|
List<ICraftingMedium> details = craftingMethods.get( api );
|
|
|
|
if ( details == null )
|
|
|
|
{
|
|
|
|
details = new ArrayList<ICraftingMedium>();
|
|
|
|
details.add( medium );
|
|
|
|
craftingMethods.put( api, details );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
details.add( medium );
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
private void updatePatterns()
|
|
|
|
{
|
2014-05-19 03:05:03 +02:00
|
|
|
// update the stuff that was in the list...
|
2014-06-06 06:26:01 +02:00
|
|
|
for (IAEItemStack out : craftableItems.keySet())
|
|
|
|
{
|
|
|
|
out.reset();
|
|
|
|
sg.postAlterationOfStoredItems( StorageChannel.ITEMS, out, new BaseActionSource() );
|
|
|
|
}
|
2014-05-19 03:05:03 +02:00
|
|
|
|
|
|
|
// erase list.
|
|
|
|
craftingMethods.clear();
|
2014-06-06 06:26:01 +02:00
|
|
|
craftableItems.clear();
|
2014-05-19 03:05:03 +02:00
|
|
|
|
|
|
|
// re-create list..
|
2014-05-18 05:19:23 +02:00
|
|
|
for (ICraftingProvider cp : providers)
|
|
|
|
cp.provideCrafting( this );
|
2014-05-19 03:05:03 +02:00
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
HashMap<IAEItemStack, Set<ICraftingPatternDetails>> tmpCraft = new HashMap();
|
|
|
|
|
2014-05-19 03:05:03 +02:00
|
|
|
// new craftables!
|
|
|
|
for (ICraftingPatternDetails details : craftingMethods.keySet())
|
2014-07-03 06:48:18 +02:00
|
|
|
{
|
2014-05-19 03:05:03 +02:00
|
|
|
for (IAEItemStack out : details.getOutputs())
|
|
|
|
{
|
2014-06-20 09:10:28 +02:00
|
|
|
out = out.copy();
|
2014-05-19 03:05:03 +02:00
|
|
|
out.reset();
|
|
|
|
out.setCraftable( true );
|
2014-06-06 06:26:01 +02:00
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
Set<ICraftingPatternDetails> methods = tmpCraft.get( out );
|
2014-06-06 06:26:01 +02:00
|
|
|
|
|
|
|
if ( methods == null )
|
2014-07-18 05:03:42 +02:00
|
|
|
tmpCraft.put( out, methods = new HashSet() );
|
2014-06-06 06:26:01 +02:00
|
|
|
|
|
|
|
methods.add( details );
|
2014-05-19 03:05:03 +02:00
|
|
|
sg.postAlterationOfStoredItems( StorageChannel.ITEMS, out, new BaseActionSource() );
|
|
|
|
}
|
2014-07-03 06:48:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// make them immutable
|
|
|
|
for (Entry<IAEItemStack, Set<ICraftingPatternDetails>> e : tmpCraft.entrySet())
|
|
|
|
{
|
2014-07-18 05:38:57 +02:00
|
|
|
craftableItems.put( e.getKey(), ImmutableSortedSet.copyOf( e.getValue() ) );
|
2014-07-03 06:48:18 +02:00
|
|
|
}
|
2014-05-18 05:19:23 +02:00
|
|
|
}
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
@Override
|
|
|
|
public void onSplit(IGridStorage destinationStorage)
|
|
|
|
{ // nothing!
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onJoin(IGridStorage sourceStorage)
|
|
|
|
{
|
|
|
|
// nothing!
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void populateGridStorage(IGridStorage destinationStorage)
|
|
|
|
{
|
|
|
|
// nothing!
|
|
|
|
}
|
|
|
|
|
2014-05-19 03:05:03 +02:00
|
|
|
@Override
|
|
|
|
public List<IMEInventoryHandler> getCellArray(StorageChannel channel)
|
|
|
|
{
|
|
|
|
ArrayList<IMEInventoryHandler> list = new ArrayList<IMEInventoryHandler>( 1 );
|
2014-05-23 04:42:27 +02:00
|
|
|
if ( channel == StorageChannel.ITEMS )
|
|
|
|
list.add( this );
|
2014-05-19 03:05:03 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPriority()
|
|
|
|
{
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAEStack extractItems(IAEStack request, Actionable mode, BaseActionSource src)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IItemList getAvailableItems(IItemList out)
|
|
|
|
{
|
|
|
|
// add craftable items!
|
2014-06-06 06:26:01 +02:00
|
|
|
for (IAEItemStack st : craftableItems.keySet())
|
|
|
|
out.addCrafting( st );
|
2014-05-19 03:05:03 +02:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StorageChannel getChannel()
|
|
|
|
{
|
|
|
|
return StorageChannel.ITEMS;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AccessRestriction getAccess()
|
|
|
|
{
|
|
|
|
return AccessRestriction.WRITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPrioritized(IAEStack input)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAEStack injectItems(IAEStack input, Actionable type, BaseActionSource src)
|
|
|
|
{
|
|
|
|
for (CraftingCPUCluster cpu : cpuClusters)
|
|
|
|
input = cpu.injectItems( input, type, src );
|
|
|
|
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canAccept(IAEStack input)
|
|
|
|
{
|
|
|
|
for (CraftingCPUCluster cpu : cpuClusters)
|
|
|
|
if ( cpu.canAccept( (IAEItemStack) input ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
@Override
|
|
|
|
public ICraftingLink submitJob(ICraftingJob job, ICraftingRequester requestingMachine, ICraftingCPU target, BaseActionSource src)
|
2014-06-19 08:28:45 +02:00
|
|
|
{
|
2014-06-22 09:00:38 +02:00
|
|
|
if ( job.isSimulation() )
|
2014-07-04 08:19:35 +02:00
|
|
|
return null;
|
2014-06-22 09:00:38 +02:00
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
CraftingCPUCluster cpuClust = null;
|
|
|
|
|
|
|
|
if ( target instanceof CraftingCPUCluster )
|
|
|
|
cpuClust = (CraftingCPUCluster) target;
|
|
|
|
|
2014-06-19 08:28:45 +02:00
|
|
|
if ( target == null )
|
|
|
|
{
|
2014-07-11 06:46:51 +02:00
|
|
|
List<CraftingCPUCluster> validCpusClusters = new ArrayList<CraftingCPUCluster>();
|
2014-06-19 08:28:45 +02:00
|
|
|
for (CraftingCPUCluster cpu : cpuClusters)
|
|
|
|
{
|
2014-07-18 05:39:18 +02:00
|
|
|
if ( cpu.isActive() && !cpu.isBusy() && cpu.getAvailableStorage() >= job.getByteTotal() )
|
2014-06-22 09:00:38 +02:00
|
|
|
{
|
2014-07-11 06:46:51 +02:00
|
|
|
validCpusClusters.add( cpu );
|
2014-06-22 09:00:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-06-19 08:28:45 +02:00
|
|
|
}
|
2014-07-11 06:46:51 +02:00
|
|
|
|
|
|
|
Collections.sort( validCpusClusters, new Comparator<CraftingCPUCluster>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compare(CraftingCPUCluster o1, CraftingCPUCluster o2)
|
|
|
|
{
|
|
|
|
int a = ItemSorters.compareLong( o2.getCoProcessors(), o1.getCoProcessors() );
|
|
|
|
if ( a != 0 )
|
|
|
|
return a;
|
|
|
|
return ItemSorters.compareLong( o2.getAvailableStorage(), o1.getAvailableStorage() );
|
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( !validCpusClusters.isEmpty() )
|
|
|
|
cpuClust = validCpusClusters.get( 0 );
|
2014-06-19 08:28:45 +02:00
|
|
|
}
|
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
if ( cpuClust != null )
|
2014-07-11 06:46:51 +02:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
return cpuClust.submitJob( grid, job, src, requestingMachine );
|
2014-07-11 06:46:51 +02:00
|
|
|
}
|
2014-06-19 08:28:45 +02:00
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
return null;
|
2014-06-19 08:28:45 +02:00
|
|
|
}
|
|
|
|
|
2014-05-19 03:05:03 +02:00
|
|
|
@Override
|
|
|
|
public int getSlot()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
public ImmutableCollection<ICraftingPatternDetails> getCraftingFor(IAEItemStack what)
|
2014-06-06 06:26:01 +02:00
|
|
|
{
|
2014-07-03 06:48:18 +02:00
|
|
|
ImmutableSet<ICraftingPatternDetails> res = craftableItems.get( what );
|
2014-06-16 07:48:43 +02:00
|
|
|
if ( res == null )
|
|
|
|
return ImmutableSet.of();
|
|
|
|
return res;
|
2014-06-06 06:26:01 +02:00
|
|
|
}
|
|
|
|
|
2014-06-19 08:28:45 +02:00
|
|
|
public List<ICraftingMedium> getMediums(ICraftingPatternDetails key)
|
|
|
|
{
|
|
|
|
List<ICraftingMedium> o = craftingMethods.get( key );
|
|
|
|
|
|
|
|
if ( o == null )
|
|
|
|
o = ImmutableList.of();
|
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2014-06-20 09:10:02 +02:00
|
|
|
@Override
|
|
|
|
public boolean validForPass(int i)
|
|
|
|
{
|
|
|
|
return i == 1;
|
|
|
|
}
|
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
final public static ExecutorService craftingPool;
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
ThreadFactory factory = new ThreadFactory() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Thread newThread(Runnable ar)
|
|
|
|
{
|
|
|
|
return new Thread( ar, "AE Crafting Calculator" );
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
craftingPool = Executors.newCachedThreadPool( factory );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Future<ICraftingJob> beginCraftingJob(World world, IGrid grid, BaseActionSource actionSrc, IAEItemStack slotItem, ICraftingCallback cb)
|
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
if ( world == null || grid == null || actionSrc == null || slotItem == null )
|
|
|
|
throw new RuntimeException( "Invalid Craftinb Job Request" );
|
|
|
|
|
2014-07-03 06:48:18 +02:00
|
|
|
CraftingJob cj = new CraftingJob( world, grid, actionSrc, slotItem, cb );
|
|
|
|
return craftingPool.submit( cj, (ICraftingJob) cj );
|
|
|
|
}
|
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
public boolean hasCpu(ICraftingCPU cpu)
|
|
|
|
{
|
|
|
|
return cpuClusters.contains( cpu );
|
|
|
|
}
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|