Implement processing patterns completely
This commit is contained in:
@@ -8,7 +8,6 @@ import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.registry.ICraftingTaskFactory;
|
||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTask;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTaskNormal;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTaskProcessing;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -26,8 +25,9 @@ public class CraftingTaskFactoryProcessing implements ICraftingTaskFactory {
|
||||
|
||||
if (tag != null) {
|
||||
task.setChildrenCreated(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_CHILDREN_CREATED));
|
||||
task.setSatisfied(CraftingTask.readBooleanArray(tag, CraftingTaskNormal.NBT_SATISFIED));
|
||||
task.setChecked(CraftingTask.readBooleanArray(tag, CraftingTaskNormal.NBT_CHECKED));
|
||||
task.setSatisfied(CraftingTask.readBooleanArray(tag, CraftingTaskProcessing.NBT_SATISFIED));
|
||||
task.setSatisfiedInsertion(CraftingTask.readBooleanArray(tag, CraftingTaskProcessing.NBT_SATISFIED_INSERTION));
|
||||
task.setChecked(CraftingTask.readBooleanArray(tag, CraftingTaskProcessing.NBT_CHECKED));
|
||||
|
||||
List<ItemStack> took = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -8,18 +8,22 @@ import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.api.network.NetworkUtils;
|
||||
import refinedstorage.api.storage.CompareUtils;
|
||||
|
||||
public class CraftingTaskProcessing extends CraftingTask {
|
||||
public static final String NBT_SATISFIED = "Satisfied";
|
||||
public static final String NBT_SATISFIED_INSERTION = "SatisfiedInsertion";
|
||||
public static final String NBT_CHECKED = "Checked";
|
||||
|
||||
private boolean satisfied[];
|
||||
private boolean satisfiedInsertion[];
|
||||
private boolean checked[];
|
||||
|
||||
public CraftingTaskProcessing(ICraftingPattern pattern) {
|
||||
super(pattern);
|
||||
|
||||
this.satisfied = new boolean[pattern.getInputs().length];
|
||||
this.satisfiedInsertion = new boolean[pattern.getInputs().length];
|
||||
this.checked = new boolean[pattern.getInputs().length];
|
||||
}
|
||||
|
||||
@@ -27,6 +31,10 @@ public class CraftingTaskProcessing extends CraftingTask {
|
||||
this.satisfied = satisfied;
|
||||
}
|
||||
|
||||
public void setSatisfiedInsertion(boolean[] satisfiedInsertion) {
|
||||
this.satisfiedInsertion = satisfiedInsertion;
|
||||
}
|
||||
|
||||
public void setChecked(boolean[] checked) {
|
||||
this.checked = checked;
|
||||
}
|
||||
@@ -59,9 +67,9 @@ public class CraftingTaskProcessing extends CraftingTask {
|
||||
return false;
|
||||
}
|
||||
|
||||
ICraftingPatternContainer container = pattern.getContainer(world);
|
||||
|
||||
if (!took.isEmpty()) {
|
||||
ICraftingPatternContainer container = pattern.getContainer(world);
|
||||
|
||||
ItemStack toInsert = took.get(0);
|
||||
|
||||
if (ItemHandlerHelper.insertItem(container.getConnectedItems(), toInsert, true) == null) {
|
||||
@@ -71,6 +79,36 @@ public class CraftingTaskProcessing extends CraftingTask {
|
||||
}
|
||||
}
|
||||
|
||||
return isDone();
|
||||
}
|
||||
|
||||
private boolean isDone() {
|
||||
for (boolean item : satisfiedInsertion) {
|
||||
if (!item) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onInserted(ItemStack stack) {
|
||||
if (isDone()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pattern.getOutputs().length; ++i) {
|
||||
ItemStack output = pattern.getOutputs()[i];
|
||||
|
||||
if (!satisfiedInsertion[i]) {
|
||||
if (CompareUtils.compareStackNoQuantity(output, stack)) {
|
||||
satisfiedInsertion[i] = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -79,6 +117,7 @@ public class CraftingTaskProcessing extends CraftingTask {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
writeBooleanArray(tag, NBT_SATISFIED, satisfied);
|
||||
writeBooleanArray(tag, NBT_SATISFIED_INSERTION, satisfiedInsertion);
|
||||
writeBooleanArray(tag, NBT_CHECKED, checked);
|
||||
|
||||
return tag;
|
||||
|
||||
@@ -32,6 +32,7 @@ import refinedstorage.api.storage.fluid.IGroupedFluidStorage;
|
||||
import refinedstorage.api.storage.item.IGroupedItemStorage;
|
||||
import refinedstorage.api.storage.item.IItemStorage;
|
||||
import refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTaskProcessing;
|
||||
import refinedstorage.apiimpl.network.NetworkNodeGraph;
|
||||
import refinedstorage.apiimpl.network.WirelessGridHandler;
|
||||
import refinedstorage.apiimpl.network.grid.FluidGridHandler;
|
||||
@@ -558,26 +559,33 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @TODO: Processing crafting tasks
|
||||
|
||||
int inserted = remainder != null ? (orginalSize - remainder.stackSize) : orginalSize;
|
||||
|
||||
if (!simulate && inserted > 0) {
|
||||
/*for (int i = 0; i < inserted; ++i) {
|
||||
if (!craftingTasks.empty() && craftingTasks.peek() instanceof ProcessingCraftingTask) {
|
||||
if (((ProcessingCraftingTask) craftingTasks.peek()).onInserted(stack)) {
|
||||
updateTopCraftingTask(false);
|
||||
itemStorage.add(ItemHandlerHelper.copyStackWithSize(stack, inserted), false);
|
||||
|
||||
for (int i = 0; i < inserted; ++i) {
|
||||
for (ICraftingTask task : craftingTasks) {
|
||||
if (checkProcessing(stack, task)) {
|
||||
inserted--;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
itemStorage.add(ItemHandlerHelper.copyStackWithSize(stack, inserted), false);
|
||||
}
|
||||
}
|
||||
|
||||
return remainder;
|
||||
}
|
||||
|
||||
private boolean checkProcessing(ItemStack stack, ICraftingTask task) {
|
||||
if (task.getChild() instanceof CraftingTaskProcessing) {
|
||||
if (checkProcessing(stack, task.getChild())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return task instanceof CraftingTaskProcessing && ((CraftingTaskProcessing) task).onInserted(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem(ItemStack stack, int size, int flags) {
|
||||
int requested = size;
|
||||
|
||||
Reference in New Issue
Block a user