Detect when inserted for processing patterns
This commit is contained in:
@@ -3,10 +3,14 @@ package refinedstorage.api.autocrafting.task;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
|
||||
import java.util.Deque;
|
||||
|
||||
public interface IProcessable {
|
||||
ICraftingPattern getPattern();
|
||||
|
||||
Deque<ItemStack> getToInsert();
|
||||
ItemStack getStackToInsert();
|
||||
|
||||
void nextStack();
|
||||
|
||||
boolean hasReceivedOutputs();
|
||||
|
||||
boolean onReceiveOutput(ItemStack stack);
|
||||
}
|
||||
|
||||
@@ -41,19 +41,12 @@ public class CraftingTaskNormal implements ICraftingTask {
|
||||
|
||||
@Override
|
||||
public void onCancelled() {
|
||||
|
||||
}
|
||||
|
||||
private void calculate(IGroupedItemStorage storage, ICraftingPattern pattern, boolean basePattern) {
|
||||
for (int i = 0; i < quantity; ++i) {
|
||||
if (pattern.isProcessing()) {
|
||||
IProcessable processable = new Processable(pattern);
|
||||
|
||||
for (int j = pattern.getInputs().size() - 1; j >= 0; --j) {
|
||||
processable.getToInsert().push(pattern.getInputs().get(j).copy());
|
||||
}
|
||||
|
||||
toProcess.add(processable);
|
||||
toProcess.add(new Processable(pattern));
|
||||
}
|
||||
|
||||
for (ItemStack input : pattern.getInputs()) {
|
||||
@@ -102,13 +95,13 @@ public class CraftingTaskNormal implements ICraftingTask {
|
||||
|
||||
public boolean update() {
|
||||
for (IProcessable processable : toProcess) {
|
||||
if (processable.getPattern().getContainer().getFacingInventory() != null && !processable.getToInsert().isEmpty()) {
|
||||
ItemStack toInsert = NetworkUtils.extractItem(network, processable.getToInsert().peek(), 1);
|
||||
if (processable.getPattern().getContainer().getFacingInventory() != null && processable.getStackToInsert() != null) {
|
||||
ItemStack toInsert = NetworkUtils.extractItem(network, processable.getStackToInsert(), 1);
|
||||
|
||||
if (ItemHandlerHelper.insertItem(processable.getPattern().getContainer().getFacingInventory(), toInsert, true) == null) {
|
||||
ItemHandlerHelper.insertItem(processable.getPattern().getContainer().getFacingInventory(), toInsert, false);
|
||||
|
||||
processable.getToInsert().pop();
|
||||
processable.nextStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +114,7 @@ public class CraftingTaskNormal implements ICraftingTask {
|
||||
}
|
||||
}
|
||||
|
||||
if (toTake.isEmpty() && missing.isEmpty()) {
|
||||
if (toTake.isEmpty() && missing.isEmpty() && toProcess.stream().allMatch(IProcessable::hasReceivedOutputs)) {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
// @TODO: Handle remainder
|
||||
network.insertItem(output, output.stackSize, false);
|
||||
|
||||
@@ -3,16 +3,16 @@ package refinedstorage.apiimpl.autocrafting.task;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.task.IProcessable;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import refinedstorage.api.storage.CompareUtils;
|
||||
|
||||
public class Processable implements IProcessable {
|
||||
private ICraftingPattern pattern;
|
||||
private Deque<ItemStack> toInsert = new ArrayDeque<>();
|
||||
private int pos;
|
||||
private boolean satisfied[];
|
||||
|
||||
public Processable(ICraftingPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
this.satisfied = new boolean[pattern.getOutputs().size()];
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -21,15 +21,44 @@ public class Processable implements IProcessable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Deque<ItemStack> getToInsert() {
|
||||
return toInsert;
|
||||
public void nextStack() {
|
||||
++pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProcessablePattern{" +
|
||||
"pattern=" + pattern +
|
||||
", toInsert=" + toInsert +
|
||||
'}';
|
||||
public ItemStack getStackToInsert() {
|
||||
if (pos > pattern.getInputs().size() - 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return pattern.getInputs().get(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasReceivedOutputs() {
|
||||
for (boolean item : satisfied) {
|
||||
if (!item) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onReceiveOutput(ItemStack stack) {
|
||||
for (int i = 0; i < pattern.getOutputs().size(); ++i) {
|
||||
if (!satisfied[i]) {
|
||||
ItemStack item = pattern.getOutputs().get(i);
|
||||
|
||||
if (CompareUtils.compareStackNoQuantity(stack, item)) {
|
||||
satisfied[i] = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import refinedstorage.api.autocrafting.task.IProcessable;
|
||||
import refinedstorage.api.network.*;
|
||||
import refinedstorage.api.network.grid.IFluidGridHandler;
|
||||
import refinedstorage.api.network.grid.IItemGridHandler;
|
||||
@@ -530,17 +531,23 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
if (!simulate && inserted > 0) {
|
||||
itemStorage.add(ItemHandlerHelper.copyStackWithSize(stack, inserted), false);
|
||||
|
||||
/*for (int i = 0; i < inserted; ++i) {
|
||||
for (int i = 0; i < inserted; ++i) {
|
||||
for (ICraftingTask task : craftingTasks) {
|
||||
if (inserted == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (onInserted(stack, task)) {
|
||||
inserted--;
|
||||
for (IProcessable processable : task.getToProcess()) {
|
||||
if (inserted == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (processable.onReceiveOutput(stack)) {
|
||||
inserted--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
return remainder;
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 2.0 KiB |
Reference in New Issue
Block a user