Crafting Emitter Progress.
This commit is contained in:
Vendored
+45
@@ -32,6 +32,8 @@ import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.crafting.ICraftingProvider;
|
||||
import appeng.api.networking.crafting.ICraftingProviderHelper;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.networking.crafting.ICraftingWatcher;
|
||||
import appeng.api.networking.crafting.ICraftingWatcherHost;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.events.MENetworkCraftingCpuChange;
|
||||
import appeng.api.networking.events.MENetworkCraftingPatternChange;
|
||||
@@ -48,15 +50,20 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.crafting.CraftingJob;
|
||||
import appeng.crafting.CraftingLink;
|
||||
import appeng.crafting.CraftingLinkNexus;
|
||||
import appeng.crafting.CraftingWatcher;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.me.helpers.GenericInterestManager;
|
||||
import appeng.me.storage.ItemWatcher;
|
||||
import appeng.tile.crafting.TileCraftingStorageTile;
|
||||
import appeng.tile.crafting.TileCraftingTile;
|
||||
import appeng.util.ItemSorters;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
|
||||
public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler
|
||||
{
|
||||
@@ -64,15 +71,20 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
HashSet<CraftingCPUCluster> cpuClusters = new HashSet();
|
||||
HashSet<ICraftingProvider> providers = new HashSet();
|
||||
|
||||
private HashMap<IGridNode, ICraftingWatcher> watchers = new HashMap<IGridNode, ICraftingWatcher>();
|
||||
|
||||
IGrid grid;
|
||||
IStorageGrid sg;
|
||||
IEnergyGrid eg;
|
||||
|
||||
HashMap<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new HashMap();
|
||||
HashMap<IAEItemStack, ImmutableSet<ICraftingPatternDetails>> craftableItems = new HashMap();
|
||||
HashSet<IAEItemStack> emitableItems = new HashSet();
|
||||
HashMap<String, CraftingLinkNexus> links = new HashMap();
|
||||
|
||||
boolean updateList = false;
|
||||
final private SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
|
||||
final public GenericInterestManager interestManager = new GenericInterestManager( interests );
|
||||
|
||||
class ActiveCpuIterator implements Iterator<ICraftingCPU>
|
||||
{
|
||||
@@ -183,6 +195,16 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
@Override
|
||||
public void removeNode(IGridNode gridNode, IGridHost machine)
|
||||
{
|
||||
if ( machine instanceof ICraftingWatcherHost )
|
||||
{
|
||||
ICraftingWatcher myWatcher = watchers.get( machine );
|
||||
if ( myWatcher != null )
|
||||
{
|
||||
myWatcher.clear();
|
||||
watchers.remove( machine );
|
||||
}
|
||||
}
|
||||
|
||||
if ( machine instanceof ICraftingRequester )
|
||||
{
|
||||
Iterator<CraftingLinkNexus> nex = links.values().iterator();
|
||||
@@ -206,6 +228,14 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
@Override
|
||||
public void addNode(IGridNode gridNode, IGridHost machine)
|
||||
{
|
||||
if ( machine instanceof ICraftingWatcherHost )
|
||||
{
|
||||
ICraftingWatcherHost swh = (ICraftingWatcherHost) machine;
|
||||
CraftingWatcher iw = new CraftingWatcher( this, (ICraftingWatcherHost) swh );
|
||||
watchers.put( gridNode, iw );
|
||||
swh.updateWatcher( iw );
|
||||
}
|
||||
|
||||
if ( machine instanceof ICraftingRequester )
|
||||
{
|
||||
for (ICraftingLink l : ((ICraftingRequester) machine).getRequestedJobs())
|
||||
@@ -523,4 +553,19 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
return cpuClusters.contains( cpu );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRequesting(IAEItemStack what)
|
||||
{
|
||||
for (CraftingCPUCluster c : cpuClusters)
|
||||
if ( c.isMaking( what ) )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEmitFor(IAEItemStack what)
|
||||
{
|
||||
return emitableItems.contains( what );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -27,7 +27,7 @@ import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.helpers.StorageInterestManager;
|
||||
import appeng.me.helpers.GenericInterestManager;
|
||||
import appeng.me.storage.ItemWatcher;
|
||||
import appeng.me.storage.NetworkInventoryHandler;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class GridStorageCache implements IStorageGrid
|
||||
{
|
||||
|
||||
final private SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
|
||||
final public StorageInterestManager interestManager = new StorageInterestManager( interests );
|
||||
final public GenericInterestManager interestManager = new GenericInterestManager( interests );
|
||||
|
||||
final HashSet<ICellProvider> activeCellProviders = new HashSet();
|
||||
final HashSet<ICellProvider> inactiveCellProviders = new HashSet();
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -44,6 +45,7 @@ import appeng.core.AELog;
|
||||
import appeng.crafting.CraftBranchFailure;
|
||||
import appeng.crafting.CraftingJob;
|
||||
import appeng.crafting.CraftingLink;
|
||||
import appeng.crafting.CraftingWatcher;
|
||||
import appeng.crafting.MECraftingInventory;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
import appeng.me.cluster.IAECluster;
|
||||
@@ -51,6 +53,9 @@ import appeng.tile.crafting.TileCraftingMonitorTile;
|
||||
import appeng.tile.crafting.TileCraftingTile;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
@@ -269,6 +274,22 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
return false;
|
||||
}
|
||||
|
||||
public void postCraftingStatusChange(IAEItemStack diff)
|
||||
{
|
||||
CraftingGridCache sg = getGrid().getCache( ICraftingGrid.class );
|
||||
|
||||
if ( sg.interestManager.containsKey( diff ) )
|
||||
{
|
||||
Set<CraftingWatcher> list = sg.interestManager.get( diff );
|
||||
if ( !list.isEmpty() )
|
||||
{
|
||||
for (CraftingWatcher iw : list)
|
||||
iw.getHost().onRequestChange( sg, diff );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IAEStack injectItems(IAEStack input, Actionable type, BaseActionSource src)
|
||||
{
|
||||
if ( input instanceof IAEItemStack && type == Actionable.SIMULATE )// causes crafting to lock up?
|
||||
@@ -325,11 +346,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
{
|
||||
is.decStackSize( input.getStackSize() );
|
||||
markDirty();
|
||||
|
||||
// AELog.info( "Task: " + is.getStackSize() + " remaining : " + getRemainingTasks() +
|
||||
// " remaining : "
|
||||
// + (is.getStackSize() + getRemainingTasks()) + " total left : waiting: " + (waiting ? "yes" :
|
||||
// "no") );
|
||||
postCraftingStatusChange( is );
|
||||
|
||||
if ( finalOutput.equals( input ) )
|
||||
{
|
||||
@@ -478,8 +495,14 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
isComplete = true;
|
||||
myLastLink = null;
|
||||
tasks.clear();
|
||||
|
||||
ImmutableSet<IAEItemStack> items = ImmutableSet.copyOf( waitingFor );
|
||||
|
||||
waitingFor.resetStatus();
|
||||
|
||||
for (IAEItemStack is : items)
|
||||
postCraftingStatusChange( is );
|
||||
|
||||
finalOutput = null;
|
||||
updateCPU();
|
||||
|
||||
@@ -642,6 +665,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
{
|
||||
postChange( out, machineSrc );
|
||||
waitingFor.add( out.copy() );
|
||||
postCraftingStatusChange( out.copy() );
|
||||
}
|
||||
|
||||
if ( details.isCraftable() )
|
||||
@@ -1037,4 +1061,9 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
return getCore().getActionableNode().isActive();
|
||||
}
|
||||
|
||||
public boolean isMaking(IAEItemStack what)
|
||||
{
|
||||
return waitingFor.findPrecise( what ) != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,93 +1,94 @@
|
||||
package appeng.me.helpers;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.me.storage.ItemWatcher;
|
||||
|
||||
import com.google.common.collect.SetMultimap;
|
||||
|
||||
public class StorageInterestManager {
|
||||
|
||||
class SavedTransactions {
|
||||
public final boolean put;
|
||||
public final IAEStack stack;
|
||||
public final ItemWatcher iw;
|
||||
|
||||
public SavedTransactions( boolean putOperation, IAEStack myStack, ItemWatcher watcher )
|
||||
{
|
||||
put = putOperation;
|
||||
stack = myStack;
|
||||
iw = watcher;
|
||||
}
|
||||
};
|
||||
|
||||
private final SetMultimap<IAEStack, ItemWatcher> container;
|
||||
private LinkedList<SavedTransactions> transactions = null;
|
||||
private int transDepth=0;
|
||||
|
||||
public StorageInterestManager(SetMultimap<IAEStack, ItemWatcher> interests) {
|
||||
container = interests;
|
||||
}
|
||||
|
||||
public void enableTransactions()
|
||||
{
|
||||
if ( transDepth == 0 )
|
||||
transactions = new LinkedList();
|
||||
|
||||
transDepth++;
|
||||
}
|
||||
|
||||
public void disableTransactions()
|
||||
{
|
||||
transDepth--;
|
||||
|
||||
if ( transDepth == 0 )
|
||||
{
|
||||
LinkedList<SavedTransactions> myActions = transactions;
|
||||
transactions = null;
|
||||
|
||||
for ( SavedTransactions t : myActions )
|
||||
{
|
||||
if ( t.put )
|
||||
put( t.stack, t.iw );
|
||||
else
|
||||
remove( t.stack, t.iw );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsKey( IAEStack stack )
|
||||
{
|
||||
return container.containsKey( stack );
|
||||
}
|
||||
|
||||
public Set<ItemWatcher> get( IAEStack stack )
|
||||
{
|
||||
return container.get( stack );
|
||||
}
|
||||
|
||||
public boolean put( IAEStack stack, ItemWatcher iw )
|
||||
{
|
||||
if ( transactions != null )
|
||||
{
|
||||
transactions.add( new SavedTransactions( true, stack, iw ) );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return container.put( stack, iw );
|
||||
}
|
||||
|
||||
public boolean remove( IAEStack stack, ItemWatcher iw )
|
||||
{
|
||||
if ( transactions != null )
|
||||
{
|
||||
transactions.add( new SavedTransactions( true, stack, iw ) );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return container.remove( stack, iw );
|
||||
}
|
||||
|
||||
}
|
||||
package appeng.me.helpers;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
import com.google.common.collect.SetMultimap;
|
||||
|
||||
public class GenericInterestManager<T>
|
||||
{
|
||||
|
||||
class SavedTransactions
|
||||
{
|
||||
|
||||
public final boolean put;
|
||||
public final IAEStack stack;
|
||||
public final T iw;
|
||||
|
||||
public SavedTransactions(boolean putOperation, IAEStack myStack, T watcher) {
|
||||
put = putOperation;
|
||||
stack = myStack;
|
||||
iw = watcher;
|
||||
}
|
||||
};
|
||||
|
||||
private final SetMultimap<IAEStack, T> container;
|
||||
private LinkedList<SavedTransactions> transactions = null;
|
||||
private int transDepth = 0;
|
||||
|
||||
public GenericInterestManager(SetMultimap<IAEStack, T> interests) {
|
||||
container = interests;
|
||||
}
|
||||
|
||||
public void enableTransactions()
|
||||
{
|
||||
if ( transDepth == 0 )
|
||||
transactions = new LinkedList();
|
||||
|
||||
transDepth++;
|
||||
}
|
||||
|
||||
public void disableTransactions()
|
||||
{
|
||||
transDepth--;
|
||||
|
||||
if ( transDepth == 0 )
|
||||
{
|
||||
LinkedList<SavedTransactions> myActions = transactions;
|
||||
transactions = null;
|
||||
|
||||
for (SavedTransactions t : myActions)
|
||||
{
|
||||
if ( t.put )
|
||||
put( t.stack, t.iw );
|
||||
else
|
||||
remove( t.stack, t.iw );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsKey(IAEStack stack)
|
||||
{
|
||||
return container.containsKey( stack );
|
||||
}
|
||||
|
||||
public Set<T> get(IAEStack stack)
|
||||
{
|
||||
return container.get( stack );
|
||||
}
|
||||
|
||||
public boolean put(IAEStack stack, T iw)
|
||||
{
|
||||
if ( transactions != null )
|
||||
{
|
||||
transactions.add( new SavedTransactions( true, stack, iw ) );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return container.put( stack, iw );
|
||||
}
|
||||
|
||||
public boolean remove(IAEStack stack, T iw)
|
||||
{
|
||||
if ( transactions != null )
|
||||
{
|
||||
transactions.add( new SavedTransactions( true, stack, iw ) );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return container.remove( stack, iw );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user