forward port crafting fixes, #879, #876

This commit is contained in:
way2muchnoise
2017-01-24 21:29:51 +01:00
parent 0e45cf9fb8
commit c4e170609b
5 changed files with 31 additions and 22 deletions

View File

@@ -39,6 +39,7 @@ public class CraftingManager implements ICraftingManager {
private List<ICraftingTask> craftingTasksToAdd = new ArrayList<>();
private List<ICraftingTask> craftingTasksToCancel = new ArrayList<>();
private List<NBTTagCompound> craftingTasksToRead = new ArrayList<>();
private List<ICraftingStep> runningSteps = new ArrayList<>();
private int ticks;
@@ -190,6 +191,12 @@ public class CraftingManager implements ICraftingManager {
}
}
runningSteps = craftingTasks.stream()
.map(ICraftingTask::getSteps)
.flatMap(List::stream)
.filter(ICraftingStep::hasStartedProcessing)
.collect(Collectors.toList());
if (craftingTasksChanged) {
network.getNetwork().markCraftingMonitorForUpdate();
}
@@ -255,11 +262,9 @@ public class CraftingManager implements ICraftingManager {
public void track(ItemStack stack, int size) {
ItemStack inserted = ItemHandlerHelper.copyStackWithSize(stack, size);
for (ICraftingTask task : craftingTasks) {
for (ICraftingStep processable : task.getSteps().stream().filter(ICraftingStep::hasStartedProcessing).collect(Collectors.toList())) {
if (processable.onReceiveOutput(inserted)) {
return;
}
for (ICraftingStep step : runningSteps) {
if (step.onReceiveOutput(inserted)) {
return;
}
}
}

View File

@@ -103,7 +103,7 @@ public abstract class CraftingStep implements ICraftingStep {
@Override
public List<ICraftingStep> getPreliminarySteps() {
return preliminarySteps;
return preliminarySteps != null ? preliminarySteps : Collections.emptyList();
}
@Override

View File

@@ -90,6 +90,9 @@ public class CraftingStepCraft extends CraftingStep {
toInsertItems.add(byproduct.copy());
}
}
} else {
// Couldn't extract items
startedProcessing = false;
}
}

View File

@@ -356,6 +356,21 @@ public class CraftingTask implements ICraftingTask {
return false;
}
// We need to copy the size cause we'll re-add unadded stacks to the queue
// Do inserting on the next tick, reliefs CPU time during insertion
// See TileController#runningSteps
int times = toInsertItems.size();
for (int i = 0; i < times; i++) {
ItemStack insert = toInsertItems.poll();
if (insert != null) {
ItemStack remainder = network.insertItemTracked(insert, insert.getCount());
if (remainder != null) {
toInsertItems.add(remainder);
}
}
}
// Collect all leaf steps
List<ICraftingStep> leafSteps = new LinkedList<>();
Queue<ICraftingStep> steps = new LinkedList<>();
@@ -391,18 +406,7 @@ public class CraftingTask implements ICraftingTask {
}
}
// We need to copy the size cause we'll re-add unadded stacks to the queue
int times = toInsertItems.size();
for (int i = 0; i < times; i++) {
ItemStack insert = toInsertItems.poll();
if (insert != null) {
ItemStack remainder = network.insertItemTracked(insert, insert.getCount());
if (remainder != null) {
toInsertItems.add(remainder);
}
}
}
if (getSteps().stream().filter(ICraftingStep::hasStartedProcessing).count() == 0) {
// When there is no started processes, restart the task.

View File

@@ -152,11 +152,8 @@ public class ProxyCommon {
registerTile(TileFluidStorage.class, "fluid_storage");
registerTile(TileDiskManipulator.class, "disk_manipulator");
registerTile(TileSecurityManager.class, "security_manager");
if (READER_WRITER_ENABLED) {
registerTile(TileReader.class, "reader");
registerTile(TileWriter.class, "writer");
}
registerTile(TileReader.class, "reader");
registerTile(TileWriter.class, "writer");
registerBlock(RSBlocks.CONTROLLER);
registerBlock(RSBlocks.GRID);