Don't start task with missing items

This commit is contained in:
Raoul Van den Berge
2016-10-25 19:48:40 +02:00
parent 86fd4f9dae
commit 82a0a364e7
4 changed files with 18 additions and 3 deletions

View File

@@ -106,6 +106,11 @@ public interface ICraftingTask {
*/ */
boolean isValid(); boolean isValid();
/**
* @return whether this crafting task has missing items
*/
boolean hasMissing();
/** /**
* {@link ICraftingTask#calculate()} must be run before this! * {@link ICraftingTask#calculate()} must be run before this!
* *

View File

@@ -185,11 +185,12 @@ public interface INetworkMaster {
task.calculate(); task.calculate();
// @TODO: Only schedule when there are no items missing? if (!task.hasMissing()) {
addCraftingTask(task); addCraftingTask(task);
} }
} }
} }
}
/** /**
* Sends a grid update packet with all the items to all clients that are watching a grid connected to this network. * Sends a grid update packet with all the items to all clients that are watching a grid connected to this network.

View File

@@ -474,6 +474,11 @@ public class CraftingTask implements ICraftingTask {
return !recurseFound; return !recurseFound;
} }
@Override
public boolean hasMissing() {
return !missing.isEmpty();
}
@Override @Override
public List<ICraftingPreviewElement> getPreviewStacks() { public List<ICraftingPreviewElement> getPreviewStacks() {
if (!isValid()) { if (!isValid()) {

View File

@@ -145,10 +145,14 @@ public class ItemGridHandler implements IItemGridHandler {
if (stack != null) { if (stack != null) {
ICraftingTask task = new CraftingTask(network, stack, network.getPattern(stack), quantity); ICraftingTask task = new CraftingTask(network, stack, network.getPattern(stack), quantity);
task.calculate(); task.calculate();
if (!task.hasMissing()) {
network.addCraftingTask(task); network.addCraftingTask(task);
} }
} }
}
@Override @Override
public void onCraftingCancelRequested(int id) { public void onCraftingCancelRequested(int id) {