feat: seperated ICraftingCPU from Cluster
This commit is contained in:
parent
493dc5aa1d
commit
af7d9f6f0e
|
@ -23,9 +23,14 @@
|
|||
|
||||
package appeng.api.networking.crafting;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.storage.IBaseMonitor;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public interface ICraftingCPU extends IBaseMonitor<IAEItemStack> {
|
||||
/**
|
||||
|
@ -52,4 +57,38 @@ public interface ICraftingCPU extends IBaseMonitor<IAEItemStack> {
|
|||
* @return an empty string or the name of the cpu.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
void getListOfItem(final IItemList<IAEItemStack> list, final CraftingItemList whichList);
|
||||
|
||||
void cancel();
|
||||
|
||||
IAEItemStack getItemStack(final IAEItemStack what, final CraftingItemList storage2);
|
||||
|
||||
long getElapsedTime();
|
||||
|
||||
long getRemainingItemCount();
|
||||
|
||||
long getStartItemCount();
|
||||
|
||||
void addCrafting(final ICraftingPatternDetails details, final long crafts);
|
||||
|
||||
void addStorage(final IAEItemStack extractItems);
|
||||
|
||||
void addEmitable(final IAEItemStack i);
|
||||
|
||||
void updateCraftingLogic(final IGrid grid, final IEnergyGrid eg, final ICraftingGrid cc);
|
||||
|
||||
ICraftingLink getLastCraftingLink();
|
||||
|
||||
boolean canAccept(final IAEStack<?> input);
|
||||
|
||||
IAEStack<?> injectItems(final IAEStack<?> input, final Actionable type, final BaseActionSource src);
|
||||
|
||||
ICraftingLink submitJob(final IGrid g, final ICraftingJob job, final BaseActionSource src, final ICraftingRequester requestingMachine);
|
||||
|
||||
boolean isMaking(final IAEItemStack what);
|
||||
|
||||
boolean isActive();
|
||||
|
||||
boolean isDestroyed();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ import appeng.core.sync.packets.PacketMEInventoryUpdate;
|
|||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.helpers.ICustomNameObject;
|
||||
import appeng.me.cluster.IAEMultiBlock;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.tile.crafting.TileCraftingTile;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -53,7 +52,7 @@ public class ContainerCraftingCPU extends AEBaseContainer
|
|||
private final IItemList<IAEItemStack> list
|
||||
= AEApi.instance().storage().createItemList();
|
||||
private IGrid network;
|
||||
private CraftingCPUCluster monitor = null;
|
||||
private ICraftingCPU monitor = null;
|
||||
private String cpuName = null;
|
||||
|
||||
@GuiSync(0)
|
||||
|
@ -110,9 +109,9 @@ public class ContainerCraftingCPU extends AEBaseContainer
|
|||
}
|
||||
}
|
||||
|
||||
if (c instanceof CraftingCPUCluster) {
|
||||
if (c instanceof ICraftingCPU) {
|
||||
this.cpuName = c.getName();
|
||||
this.setMonitor((CraftingCPUCluster) c);
|
||||
this.setMonitor((ICraftingCPU) c);
|
||||
this.list.resetStatus();
|
||||
this.getMonitor().getListOfItem(this.list, CraftingItemList.ALL);
|
||||
this.getMonitor().addListener(this, null);
|
||||
|
@ -242,11 +241,11 @@ public class ContainerCraftingCPU extends AEBaseContainer
|
|||
this.eta = eta;
|
||||
}
|
||||
|
||||
CraftingCPUCluster getMonitor() {
|
||||
ICraftingCPU getMonitor() {
|
||||
return this.monitor;
|
||||
}
|
||||
|
||||
private void setMonitor(final CraftingCPUCluster monitor) {
|
||||
private void setMonitor(final ICraftingCPU monitor) {
|
||||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,12 @@ import java.util.List;
|
|||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.networking.crafting.ICraftingCPU;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -313,7 +313,7 @@ public class CraftingTreeNode {
|
|||
|
||||
public void setJob(
|
||||
final MECraftingInventory storage,
|
||||
final CraftingCPUCluster craftingCPUCluster,
|
||||
final ICraftingCPU ICraftingCPU,
|
||||
final BaseActionSource src
|
||||
) throws CraftBranchFailure {
|
||||
for (final IAEItemStack i : this.used) {
|
||||
|
@ -323,17 +323,17 @@ public class CraftingTreeNode {
|
|||
throw new CraftBranchFailure(i, i.getStackSize());
|
||||
}
|
||||
|
||||
craftingCPUCluster.addStorage(ex);
|
||||
ICraftingCPU.addStorage(ex);
|
||||
}
|
||||
|
||||
if (this.howManyEmitted > 0) {
|
||||
final IAEItemStack i = this.what.copy();
|
||||
i.setStackSize(this.howManyEmitted);
|
||||
craftingCPUCluster.addEmitable(i);
|
||||
ICraftingCPU.addEmitable(i);
|
||||
}
|
||||
|
||||
for (final CraftingTreeProcess pro : this.nodes) {
|
||||
pro.setJob(storage, craftingCPUCluster, src);
|
||||
pro.setJob(storage, ICraftingCPU, src);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,13 +24,13 @@ import java.util.Map.Entry;
|
|||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.crafting.ICraftingCPU;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
|
@ -287,13 +287,13 @@ public class CraftingTreeProcess {
|
|||
|
||||
void setJob(
|
||||
final MECraftingInventory storage,
|
||||
final CraftingCPUCluster craftingCPUCluster,
|
||||
final ICraftingCPU ICraftingCPU,
|
||||
final BaseActionSource src
|
||||
) throws CraftBranchFailure {
|
||||
craftingCPUCluster.addCrafting(this.details, this.crafts);
|
||||
ICraftingCPU.addCrafting(this.details, this.crafts);
|
||||
|
||||
for (final CraftingTreeNode pro : this.nodes.keySet()) {
|
||||
pro.setJob(storage, craftingCPUCluster, src);
|
||||
pro.setJob(storage, ICraftingCPU, src);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ 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.tile.crafting.TileCraftingStorageTile;
|
||||
import appeng.tile.crafting.TileCraftingTile;
|
||||
|
@ -82,8 +81,8 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||
CRAFTING_POOL = Executors.newCachedThreadPool(factory);
|
||||
}
|
||||
|
||||
private final Set<CraftingCPUCluster> craftingCPUClusters
|
||||
= new HashSet<CraftingCPUCluster>();
|
||||
private final Set<ICraftingCPU> ICraftingCPUs
|
||||
= new HashSet<ICraftingCPU>();
|
||||
private final Set<ICraftingProvider> craftingProviders
|
||||
= new HashSet<ICraftingProvider>();
|
||||
private final Map<IGridNode, ICraftingWatcher> craftingWatchers
|
||||
|
@ -131,7 +130,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||
}
|
||||
}
|
||||
|
||||
for (final CraftingCPUCluster cpu : this.craftingCPUClusters) {
|
||||
for (final ICraftingCPU cpu : this.ICraftingCPUs) {
|
||||
cpu.updateCraftingLogic(this.grid, this.energyGrid, this);
|
||||
}
|
||||
}
|
||||
|
@ -259,14 +258,14 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||
}
|
||||
|
||||
private void updateCPUClusters() {
|
||||
this.craftingCPUClusters.clear();
|
||||
this.ICraftingCPUs.clear();
|
||||
|
||||
for (final IGridNode cst : this.grid.getMachines(TileCraftingStorageTile.class)) {
|
||||
final TileCraftingStorageTile tile
|
||||
= (TileCraftingStorageTile) cst.getMachine();
|
||||
final CraftingCPUCluster cluster = (CraftingCPUCluster) tile.getCluster();
|
||||
final ICraftingCPU cluster = (ICraftingCPU) tile.getCluster();
|
||||
if (cluster != null) {
|
||||
this.craftingCPUClusters.add(cluster);
|
||||
this.ICraftingCPUs.add(cluster);
|
||||
|
||||
if (cluster.getLastCraftingLink() != null) {
|
||||
this.addLink((CraftingLink) cluster.getLastCraftingLink());
|
||||
|
@ -346,7 +345,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||
|
||||
@Override
|
||||
public boolean canAccept(final IAEStack input) {
|
||||
for (final CraftingCPUCluster cpu : this.craftingCPUClusters) {
|
||||
for (final ICraftingCPU cpu : this.ICraftingCPUs) {
|
||||
if (cpu.canAccept(input)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -368,7 +367,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||
@Override
|
||||
public IAEStack
|
||||
injectItems(IAEStack input, final Actionable type, final BaseActionSource src) {
|
||||
for (final CraftingCPUCluster cpu : this.craftingCPUClusters) {
|
||||
for (final ICraftingCPU cpu : this.ICraftingCPUs) {
|
||||
input = cpu.injectItems(input, type, src);
|
||||
}
|
||||
|
||||
|
@ -461,27 +460,27 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||
return null;
|
||||
}
|
||||
|
||||
CraftingCPUCluster cpuCluster = null;
|
||||
ICraftingCPU cpuCluster = null;
|
||||
|
||||
if (target instanceof CraftingCPUCluster) {
|
||||
cpuCluster = (CraftingCPUCluster) target;
|
||||
if (target instanceof ICraftingCPU) {
|
||||
cpuCluster = (ICraftingCPU) target;
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
final List<CraftingCPUCluster> validCpusClusters
|
||||
= new ArrayList<CraftingCPUCluster>();
|
||||
for (final CraftingCPUCluster cpu : this.craftingCPUClusters) {
|
||||
final List<ICraftingCPU> validCpusClusters
|
||||
= new ArrayList<ICraftingCPU>();
|
||||
for (final ICraftingCPU cpu : this.ICraftingCPUs) {
|
||||
if (cpu.isActive() && !cpu.isBusy()
|
||||
&& cpu.getAvailableStorage() >= job.getByteTotal()) {
|
||||
validCpusClusters.add(cpu);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(validCpusClusters, new Comparator<CraftingCPUCluster>() {
|
||||
Collections.sort(validCpusClusters, new Comparator<ICraftingCPU>() {
|
||||
@Override
|
||||
public int compare(
|
||||
final CraftingCPUCluster firstCluster,
|
||||
final CraftingCPUCluster nextCluster
|
||||
final ICraftingCPU firstCluster,
|
||||
final ICraftingCPU nextCluster
|
||||
) {
|
||||
if (prioritizePower) {
|
||||
final int comparison = ItemSorters.compareLong(
|
||||
|
@ -523,7 +522,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingCPU> getCpus() {
|
||||
return ImmutableSet.copyOf(new ActiveCpuIterator(this.craftingCPUClusters));
|
||||
return ImmutableSet.copyOf(new ActiveCpuIterator(this.ICraftingCPUs));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -533,7 +532,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||
|
||||
@Override
|
||||
public boolean isRequesting(final IAEItemStack what) {
|
||||
for (final CraftingCPUCluster cluster : this.craftingCPUClusters) {
|
||||
for (final ICraftingCPU cluster : this.ICraftingCPUs) {
|
||||
if (cluster.isMaking(what)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -553,7 +552,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||
}
|
||||
|
||||
public boolean hasCpu(final ICraftingCPU cpu) {
|
||||
return this.craftingCPUClusters.contains(cpu);
|
||||
return this.ICraftingCPUs.contains(cpu);
|
||||
}
|
||||
|
||||
public GenericInterestManager<CraftingWatcher> getInterestManager() {
|
||||
|
@ -561,10 +560,10 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||
}
|
||||
|
||||
private static class ActiveCpuIterator implements Iterator<ICraftingCPU> {
|
||||
private final Iterator<CraftingCPUCluster> iterator;
|
||||
private CraftingCPUCluster cpuCluster;
|
||||
private final Iterator<ICraftingCPU> iterator;
|
||||
private ICraftingCPU cpuCluster;
|
||||
|
||||
public ActiveCpuIterator(final Collection<CraftingCPUCluster> o) {
|
||||
public ActiveCpuIterator(final Collection<ICraftingCPU> o) {
|
||||
this.iterator = o.iterator();
|
||||
this.cpuCluster = null;
|
||||
}
|
||||
|
|
|
@ -104,10 +104,12 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDestroyed() {
|
||||
return this.isDestroyed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingLink getLastCraftingLink() {
|
||||
return this.myLastLink;
|
||||
}
|
||||
|
@ -189,6 +191,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(final IAEStack input) {
|
||||
if (input instanceof IAEItemStack) {
|
||||
final IAEItemStack is = this.waitingFor.findPrecise((IAEItemStack) input);
|
||||
|
@ -199,6 +202,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEStack
|
||||
injectItems(final IAEStack input, final Actionable type, final BaseActionSource src) {
|
||||
if (!(input instanceof IAEItemStack)) {
|
||||
|
@ -456,6 +460,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if (this.myLastLink != null) {
|
||||
this.myLastLink.cancel();
|
||||
|
@ -487,8 +492,9 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
this.storeItems(); // marks dirty
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCraftingLogic(
|
||||
final IGrid grid, final IEnergyGrid eg, final CraftingGridCache cc
|
||||
final IGrid grid, final IEnergyGrid eg, final ICraftingGrid cc
|
||||
) {
|
||||
if (!this.getCore().isActive()) {
|
||||
return;
|
||||
|
@ -523,7 +529,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
if (this.remainingOperations > 0) {
|
||||
do {
|
||||
this.somethingChanged = false;
|
||||
this.executeCrafting(eg, cc);
|
||||
this.executeCrafting(eg, (CraftingGridCache)cc);
|
||||
} while (this.somethingChanged && this.remainingOperations > 0);
|
||||
}
|
||||
this.usedOps[2] = this.usedOps[1];
|
||||
|
@ -754,6 +760,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingLink submitJob(
|
||||
final IGrid g,
|
||||
final ICraftingJob job,
|
||||
|
@ -862,6 +869,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
return this.myName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
final TileCraftingTile core = this.getCore();
|
||||
|
||||
|
@ -908,6 +916,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void
|
||||
getListOfItem(final IItemList<IAEItemStack> list, final CraftingItemList whichList) {
|
||||
switch (whichList) {
|
||||
|
@ -949,15 +958,18 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage(final IAEItemStack extractItems) {
|
||||
this.inventory.injectItems(extractItems, Actionable.MODULATE, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEmitable(final IAEItemStack i) {
|
||||
this.waitingFor.add(i);
|
||||
this.postCraftingStatusChange(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting(final ICraftingPatternDetails details, final long crafts) {
|
||||
TaskProgress i = this.tasks.get(details);
|
||||
|
||||
|
@ -968,6 +980,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
i.value += crafts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack
|
||||
getItemStack(final IAEItemStack what, final CraftingItemList storage2) {
|
||||
IAEItemStack is;
|
||||
|
@ -1153,6 +1166,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
return this.getCore().getWorldObj();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaking(final IAEItemStack what) {
|
||||
final IAEItemStack wat = this.waitingFor.findPrecise(what);
|
||||
return wat != null && wat.getStackSize() > 0;
|
||||
|
@ -1191,14 +1205,17 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
|||
this.remainingItemCount = this.getRemainingItemCount() - is.getStackSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getElapsedTime() {
|
||||
return this.elapsedTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRemainingItemCount() {
|
||||
return this.remainingItemCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartItemCount() {
|
||||
return this.startItemCount;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package appeng.me.legacy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class CraftingJobPacket
|
||||
{
|
||||
public ItemStack Target;
|
||||
public List<ItemStack> Dependencies;
|
||||
public List<ItemStack> Missing;
|
||||
|
||||
public CraftingJobPacket() {
|
||||
this.Dependencies = new ArrayList<ItemStack>();
|
||||
this.Missing = new ArrayList<ItemStack>();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue