Apply speed to running of tasks

This commit is contained in:
Raoul Van den Berge
2016-10-06 15:13:20 +02:00
parent 9eb1ecbcf1
commit c3721c2561
3 changed files with 28 additions and 15 deletions

View File

@@ -20,6 +20,8 @@ public class CraftingMonitorElementToTake implements ICraftingMonitorElement {
@Override
public void draw(GuiBase gui, int x, int y) {
x += 3;
gui.drawItem(x + 2, y + 1, toTake);
float scale = 0.5f;

View File

@@ -15,6 +15,7 @@ import refinedstorage.api.network.NetworkUtils;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.api.storage.item.IGroupedItemStorage;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementRoot;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementToTake;
import java.util.ArrayDeque;
import java.util.ArrayList;
@@ -153,6 +154,18 @@ public class CraftingTaskNormal implements ICraftingTask {
quantity
));
if (!toTake.isEmpty()) {
Multimap<Item, ItemStack> toTake = ArrayListMultimap.create();
for (ItemStack stack : new ArrayList<>(this.toTake)) {
add(toTake, stack);
}
for (ItemStack stack : toTake.values()) {
elements.add(new CraftingMonitorElementToTake(stack, stack.stackSize));
}
}
return elements;
}
@@ -182,7 +195,15 @@ public class CraftingTaskNormal implements ICraftingTask {
}
private void addMissing(ItemStack stack) {
for (ItemStack m : missing.get(stack.getItem())) {
add(missing, stack);
}
private void addToCraft(ItemStack stack) {
add(toCraft, stack);
}
private void add(Multimap<Item, ItemStack> map, ItemStack stack) {
for (ItemStack m : map.get(stack.getItem())) {
if (CompareUtils.compareStackNoQuantity(m, stack)) {
m.stackSize += stack.stackSize;
@@ -190,7 +211,7 @@ public class CraftingTaskNormal implements ICraftingTask {
}
}
missing.put(stack.getItem(), stack.copy());
map.put(stack.getItem(), stack.copy());
}
private void addExtras(ICraftingPattern pattern) {
@@ -226,16 +247,4 @@ public class CraftingTaskNormal implements ICraftingTask {
this.extras.remove(extras.getItem(), extras);
}
}
private void addToCraft(ItemStack stack) {
for (ItemStack m : toCraft.get(stack.getItem())) {
if (CompareUtils.compareStackNoQuantity(m, stack)) {
m.stackSize += stack.stackSize;
return;
}
}
toCraft.put(stack.getItem(), stack.copy());
}
}

View File

@@ -275,7 +275,9 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
while (craftingTaskIterator.hasNext()) {
ICraftingTask task = craftingTaskIterator.next();
if (task.update()) {
ICraftingPatternContainer container = task.getPattern().getContainer();
if (container != null && ticks % container.getSpeed() == 0 && task.update()) {
craftingTaskIterator.remove();
craftingTasksChanged = true;