Machines in use, doesn't work yet

This commit is contained in:
Raoul Van den Berge
2016-10-18 22:56:39 +02:00
parent e5ac59dc9a
commit 1c7bcd7458
2 changed files with 45 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
package refinedstorage.api.autocrafting;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler;
@@ -21,6 +22,8 @@ public interface ICraftingPatternContainer {
*/
IItemHandler getFacingInventory();
TileEntity getFacingTile();
/**
* @return the patterns stored in this container
*/

View File

@@ -164,12 +164,14 @@ public class CraftingTask implements ICraftingTask {
}
}
for (ItemStack byproduct : (pattern.isOredict() && missing.isEmpty() ? pattern.getByproducts(took) : pattern.getByproducts())) {
toInsert.add(byproduct.copy());
}
if (!pattern.isProcessing()) {
for (ItemStack byproduct : (pattern.isOredict() && missing.isEmpty() ? pattern.getByproducts(took) : pattern.getByproducts())) {
toInsert.add(byproduct.copy());
}
for (ItemStack output : (pattern.isOredict() && missing.isEmpty() ? pattern.getOutputs(took) : pattern.getOutputs())) {
toInsert.add(output.copy());
for (ItemStack output : (pattern.isOredict() && missing.isEmpty() ? pattern.getOutputs(took) : pattern.getOutputs())) {
toInsert.add(output.copy());
}
}
usedPatterns.remove(pattern);
@@ -232,7 +234,7 @@ public class CraftingTask implements ICraftingTask {
for (IProcessable processable : toProcess) {
IItemHandler inventory = processable.getPattern().getContainer().getFacingInventory();
if (inventory != null && !processable.getToInsert().isEmpty()) {
if (inventory != null && !processable.getToInsert().isEmpty() && canProcess(processable)) {
ItemStack toInsert = network.extractItem(processable.getToInsert().peek(), 1, DEFAULT_COMPARE | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0));
if (ItemHandlerHelper.insertItem(inventory, toInsert, true) == null) {
@@ -283,7 +285,7 @@ public class CraftingTask implements ICraftingTask {
network.insertItem(insert, insert.stackSize, false);
toInsert.pop();
network.sendCraftingMonitorUpdate();
}
@@ -293,6 +295,35 @@ public class CraftingTask implements ICraftingTask {
return false;
}
private boolean canProcess(IProcessable processable) {
for (ICraftingTask otherTask : network.getCraftingTasks()) {
for (IProcessable otherProcessable : otherTask.getToProcess()) {
if (otherProcessable != processable) {
if (!isPatternsEqual(processable.getPattern(), otherProcessable.getPattern())) {
if (processable.getPattern().getContainer().getFacingTile().getPos().equals(otherProcessable.getPattern().getContainer().getFacingTile().getPos())) {
return false;
}
}
}
}
}
return true;
}
private boolean isPatternsEqual(ICraftingPattern left, ICraftingPattern right) {
for (int i = 0; i < 9; ++i) {
ItemStack leftStack = left.getInputs().get(i);
ItemStack rightStack = right.getInputs().get(i);
if (!API.instance().getComparer().isEqual(leftStack, rightStack)) {
return false;
}
}
return true;
}
@Override
public int getQuantity() {
return quantity;
@@ -411,6 +442,10 @@ public class CraftingTask implements ICraftingTask {
));
}
}
if (!canProcess(processable)) {
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.machine_in_use", 32));
}
}
}
}