From c834cfb02a7e805596164e52aa1917db9f2a40b3 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Thu, 17 Jul 2014 22:39:18 -0500 Subject: [PATCH] Crafting Grid now ignores CPUs that have are inactive. --- me/cache/CraftingGridCache.java | 48 ++++++++++++++++++- .../implementations/CraftingCPUCluster.java | 5 ++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/me/cache/CraftingGridCache.java b/me/cache/CraftingGridCache.java index 4f76c333..3f2d532c 100644 --- a/me/cache/CraftingGridCache.java +++ b/me/cache/CraftingGridCache.java @@ -1,6 +1,7 @@ package appeng.me.cache; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -73,10 +74,53 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper boolean updateList = false; + class ActiveCpuIterator implements Iterator + { + + final Iterator i; + CraftingCPUCluster c = null; + + public ActiveCpuIterator(Collection 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.. + } + + }; + @Override public ImmutableSet getCpus() { - return ImmutableSet.copyOf( (HashSet) (HashSet) cpuClusters ); + return ImmutableSet.copyOf( new ActiveCpuIterator( cpuClusters ) ); } public CraftingGridCache(IGrid g) { @@ -357,7 +401,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper List validCpusClusters = new ArrayList(); for (CraftingCPUCluster cpu : cpuClusters) { - if ( !cpu.isBusy() && cpu.getAvailableStorage() >= job.getByteTotal() ) + if ( cpu.isActive() && !cpu.isBusy() && cpu.getAvailableStorage() >= job.getByteTotal() ) { validCpusClusters.add( cpu ); break; diff --git a/me/cluster/implementations/CraftingCPUCluster.java b/me/cluster/implementations/CraftingCPUCluster.java index d6ddc44f..da6db177 100644 --- a/me/cluster/implementations/CraftingCPUCluster.java +++ b/me/cluster/implementations/CraftingCPUCluster.java @@ -1028,4 +1028,9 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU } } + public boolean isActive() + { + return getCore().getActionableNode().isActive(); + } + }