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 net.minecraft.item.ItemStack;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
|
|
||||||
import java.util.Deque;
|
|
||||||
|
|
||||||
public interface IProcessable {
|
public interface IProcessable {
|
||||||
ICraftingPattern getPattern();
|
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
|
@Override
|
||||||
public void onCancelled() {
|
public void onCancelled() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculate(IGroupedItemStorage storage, ICraftingPattern pattern, boolean basePattern) {
|
private void calculate(IGroupedItemStorage storage, ICraftingPattern pattern, boolean basePattern) {
|
||||||
for (int i = 0; i < quantity; ++i) {
|
for (int i = 0; i < quantity; ++i) {
|
||||||
if (pattern.isProcessing()) {
|
if (pattern.isProcessing()) {
|
||||||
IProcessable processable = new Processable(pattern);
|
toProcess.add(new Processable(pattern));
|
||||||
|
|
||||||
for (int j = pattern.getInputs().size() - 1; j >= 0; --j) {
|
|
||||||
processable.getToInsert().push(pattern.getInputs().get(j).copy());
|
|
||||||
}
|
|
||||||
|
|
||||||
toProcess.add(processable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ItemStack input : pattern.getInputs()) {
|
for (ItemStack input : pattern.getInputs()) {
|
||||||
@@ -102,13 +95,13 @@ public class CraftingTaskNormal implements ICraftingTask {
|
|||||||
|
|
||||||
public boolean update() {
|
public boolean update() {
|
||||||
for (IProcessable processable : toProcess) {
|
for (IProcessable processable : toProcess) {
|
||||||
if (processable.getPattern().getContainer().getFacingInventory() != null && !processable.getToInsert().isEmpty()) {
|
if (processable.getPattern().getContainer().getFacingInventory() != null && processable.getStackToInsert() != null) {
|
||||||
ItemStack toInsert = NetworkUtils.extractItem(network, processable.getToInsert().peek(), 1);
|
ItemStack toInsert = NetworkUtils.extractItem(network, processable.getStackToInsert(), 1);
|
||||||
|
|
||||||
if (ItemHandlerHelper.insertItem(processable.getPattern().getContainer().getFacingInventory(), toInsert, true) == null) {
|
if (ItemHandlerHelper.insertItem(processable.getPattern().getContainer().getFacingInventory(), toInsert, true) == null) {
|
||||||
ItemHandlerHelper.insertItem(processable.getPattern().getContainer().getFacingInventory(), toInsert, false);
|
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()) {
|
for (ItemStack output : pattern.getOutputs()) {
|
||||||
// @TODO: Handle remainder
|
// @TODO: Handle remainder
|
||||||
network.insertItem(output, output.stackSize, false);
|
network.insertItem(output, output.stackSize, false);
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package refinedstorage.apiimpl.autocrafting.task;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.task.IProcessable;
|
import refinedstorage.api.autocrafting.task.IProcessable;
|
||||||
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
import java.util.ArrayDeque;
|
|
||||||
import java.util.Deque;
|
|
||||||
|
|
||||||
public class Processable implements IProcessable {
|
public class Processable implements IProcessable {
|
||||||
private ICraftingPattern pattern;
|
private ICraftingPattern pattern;
|
||||||
private Deque<ItemStack> toInsert = new ArrayDeque<>();
|
private int pos;
|
||||||
|
private boolean satisfied[];
|
||||||
|
|
||||||
public Processable(ICraftingPattern pattern) {
|
public Processable(ICraftingPattern pattern) {
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
|
this.satisfied = new boolean[pattern.getOutputs().size()];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -21,15 +21,44 @@ public class Processable implements IProcessable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Deque<ItemStack> getToInsert() {
|
public void nextStack() {
|
||||||
return toInsert;
|
++pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public ItemStack getStackToInsert() {
|
||||||
return "ProcessablePattern{" +
|
if (pos > pattern.getInputs().size() - 1) {
|
||||||
"pattern=" + pattern +
|
return null;
|
||||||
", toInsert=" + toInsert +
|
}
|
||||||
'}';
|
|
||||||
|
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.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
|
import refinedstorage.api.autocrafting.task.IProcessable;
|
||||||
import refinedstorage.api.network.*;
|
import refinedstorage.api.network.*;
|
||||||
import refinedstorage.api.network.grid.IFluidGridHandler;
|
import refinedstorage.api.network.grid.IFluidGridHandler;
|
||||||
import refinedstorage.api.network.grid.IItemGridHandler;
|
import refinedstorage.api.network.grid.IItemGridHandler;
|
||||||
@@ -530,17 +531,23 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
if (!simulate && inserted > 0) {
|
if (!simulate && inserted > 0) {
|
||||||
itemStorage.add(ItemHandlerHelper.copyStackWithSize(stack, inserted), false);
|
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) {
|
for (ICraftingTask task : craftingTasks) {
|
||||||
if (inserted == 0) {
|
if (inserted == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onInserted(stack, task)) {
|
for (IProcessable processable : task.getToProcess()) {
|
||||||
inserted--;
|
if (inserted == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (processable.onReceiveOutput(stack)) {
|
||||||
|
inserted--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return remainder;
|
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