Fixed autocrafting getting stuck with processing patterns #389

This commit is contained in:
Raoul Van den Berge
2016-09-29 21:56:37 +02:00
parent 8a68fbb46c
commit 92d820c16f
6 changed files with 34 additions and 40 deletions

View File

@@ -3,6 +3,7 @@
### 1.1.2 ### 1.1.2
- It is now possible to start a crafting task even if the crafting preview says you can't (raoulvdberge) - It is now possible to start a crafting task even if the crafting preview says you can't (raoulvdberge)
- Fixed crash when changing screens in autocrafting (raoulvdberge) - Fixed crash when changing screens in autocrafting (raoulvdberge)
- Fixed autocrafting getting stuck with processing patterns (raoulvdberge)
### 1.1.1 ### 1.1.1
- Fixed crash on servers (raoulvdberge) - Fixed crash on servers (raoulvdberge)

View File

@@ -52,9 +52,10 @@ public interface ICraftingTask {
/** /**
* Returns the status of this crafting task that is used for the tooltip in the crafting monitor. * Returns the status of this crafting task that is used for the tooltip in the crafting monitor.
* *
* @param network the network
* @return the status * @return the status
*/ */
String getStatus(); String getStatus(INetworkMaster network);
/** /**
* @return the progress for display in the crafting monitor, or -1 to not display any progress * @return the progress for display in the crafting monitor, or -1 to not display any progress

View File

@@ -54,7 +54,7 @@ public class CraftingTaskNormal extends CraftingTask {
} }
@Override @Override
public String getStatus() { public String getStatus(INetworkMaster network) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
boolean missingItems = false; boolean missingItems = false;

View File

@@ -20,8 +20,6 @@ public class CraftingTaskProcessing extends CraftingTask {
private boolean satisfiedInsertion[]; private boolean satisfiedInsertion[];
private BlockPos tileInUse; private BlockPos tileInUse;
private boolean waitingOnTileInUse;
public CraftingTaskProcessing(ICraftingPattern pattern, int depth) { public CraftingTaskProcessing(ICraftingPattern pattern, int depth) {
super(pattern, depth); super(pattern, depth);
@@ -64,18 +62,10 @@ public class CraftingTaskProcessing extends CraftingTask {
ICraftingPatternContainer container = pattern.getContainer(); ICraftingPatternContainer container = pattern.getContainer();
if (container.getFacingTile() == null) { if (container.getFacingTile() != null && !isTileInUse(network)) {
tileInUse = null; tileInUse = pattern.getContainer().getFacingTile().getPos();
waitingOnTileInUse = false;
}
if (!took.isEmpty() && container.getFacingTile() != null) {
waitingOnTileInUse = isTileInUse(network);
if (!waitingOnTileInUse) {
tileInUse = pattern.getContainer().getFacingTile().getPos();
if (!took.isEmpty()) {
ItemStack toInsert = took.get(0); ItemStack toInsert = took.get(0);
if (ItemHandlerHelper.insertItem(container.getFacingInventory(), toInsert, true) == null) { if (ItemHandlerHelper.insertItem(container.getFacingInventory(), toInsert, true) == null) {
@@ -84,6 +74,8 @@ public class CraftingTaskProcessing extends CraftingTask {
took.remove(0); took.remove(0);
} }
} }
} else {
tileInUse = null;
} }
return isReady(); return isReady();
@@ -110,9 +102,11 @@ public class CraftingTaskProcessing extends CraftingTask {
} }
private boolean isTileInUse(INetworkMaster network) { private boolean isTileInUse(INetworkMaster network) {
for (ICraftingTask task : network.getCraftingTasks()) { if (tileInUse == null) {
if (isTileInUse(task)) { for (ICraftingTask task : network.getCraftingTasks()) {
return true; if (isTileInUse(task)) {
return true;
}
} }
} }
@@ -120,17 +114,19 @@ public class CraftingTaskProcessing extends CraftingTask {
} }
private boolean isTileInUse(ICraftingTask task) { private boolean isTileInUse(ICraftingTask task) {
if (task != this) { if (task == this) {
if (task.getChild() != null) { return false;
return isTileInUse(task.getChild()); }
}
if (task instanceof CraftingTaskProcessing) { if (task.getChild() != null) {
CraftingTaskProcessing other = (CraftingTaskProcessing) task; return isTileInUse(task.getChild());
}
if (other.tileInUse != null && other.tileInUse.equals(pattern.getContainer().getFacingTile().getPos()) && !other.pattern.equals(pattern)) { if (task instanceof CraftingTaskProcessing) {
return true; CraftingTaskProcessing other = (CraftingTaskProcessing) task;
}
if (other.tileInUse != null && other.tileInUse.equals(pattern.getContainer().getFacingTile().getPos()) && !other.pattern.equals(pattern)) {
return true;
} }
} }
@@ -175,7 +171,7 @@ public class CraftingTaskProcessing extends CraftingTask {
} }
@Override @Override
public String getStatus() { public String getStatus(INetworkMaster network) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
boolean missingItems = false; boolean missingItems = false;
@@ -219,7 +215,7 @@ public class CraftingTaskProcessing extends CraftingTask {
if (pattern.getContainer().getFacingTile() == null) { if (pattern.getContainer().getFacingTile() == null) {
builder.append("B=gui.refinedstorage:crafting_monitor.machine_none"); builder.append("B=gui.refinedstorage:crafting_monitor.machine_none");
} else if (waitingOnTileInUse) { } else if (isTileInUse(network)) {
builder.append("B=gui.refinedstorage:crafting_monitor.machine_in_use"); builder.append("B=gui.refinedstorage:crafting_monitor.machine_in_use");
} }
} }

View File

@@ -2,6 +2,7 @@ package refinedstorage.tile;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import refinedstorage.api.autocrafting.task.ICraftingTask; import refinedstorage.api.autocrafting.task.ICraftingTask;
import refinedstorage.api.network.INetworkMaster;
import java.util.List; import java.util.List;
@@ -26,11 +27,11 @@ public class ClientCraftingTask {
this.progress = progress; this.progress = progress;
} }
public ClientCraftingTask(String status, List<ItemStack> outputs, int progress, ICraftingTask child) { public ClientCraftingTask(INetworkMaster network, ICraftingTask task) {
this.status = status; this.status = task.getStatus(network);
this.outputs = outputs; this.outputs = task.getPattern().getOutputs();
this.progress = progress; this.progress = task.getProgress();
this.child = child != null ? new ClientCraftingTask(child.getStatus(), child.getPattern().getOutputs(), child.getProgress(), child.getChild()) : null; this.child = task.getChild() != null ? new ClientCraftingTask(network, task.getChild()) : null;
} }
public ItemStack getOutput() { public ItemStack getOutput() {

View File

@@ -15,12 +15,7 @@ public class TileCraftingMonitor extends TileNode {
@Override @Override
public List<ClientCraftingTask> getValue(TileCraftingMonitor tile) { public List<ClientCraftingTask> getValue(TileCraftingMonitor tile) {
if (tile.connected) { if (tile.connected) {
return tile.network.getCraftingTasks().stream().map(t -> new ClientCraftingTask( return tile.network.getCraftingTasks().stream().map(t -> new ClientCraftingTask(tile.network, t)).collect(Collectors.toList());
t.getStatus(),
t.getPattern().getOutputs(),
t.getProgress(),
t.getChild()
)).collect(Collectors.toList());
} else { } else {
return Collections.emptyList(); return Collections.emptyList();
} }