Show items inserting at end of crafting task
This commit is contained in:
@@ -3,6 +3,7 @@ package refinedstorage.apiimpl.autocrafting.task;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
import refinedstorage.RSUtils;
|
import refinedstorage.RSUtils;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
@@ -79,7 +80,9 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!basePattern) {
|
if (!basePattern) {
|
||||||
addExtras(pattern);
|
pattern.getOutputs().stream()
|
||||||
|
.filter(o -> o.stackSize > 1)
|
||||||
|
.forEach(o -> extras.add(ItemHandlerHelper.copyStackWithSize(o, o.stackSize - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||||
@@ -91,11 +94,13 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
ItemStack extra = extras.get(input, compare);
|
ItemStack extra = extras.get(input, compare);
|
||||||
|
|
||||||
if (extra != null) {
|
if (extra != null) {
|
||||||
|
ItemStack extraToRemove = ItemHandlerHelper.copyStackWithSize(extra, 1);
|
||||||
|
|
||||||
if (!pattern.isProcessing()) {
|
if (!pattern.isProcessing()) {
|
||||||
took[i] = ItemHandlerHelper.copyStackWithSize(extra, 1);
|
took[i] = extraToRemove;
|
||||||
}
|
}
|
||||||
|
|
||||||
decrOrRemoveExtras(extra);
|
extras.remove(extraToRemove, true);
|
||||||
} else {
|
} else {
|
||||||
ICraftingPattern inputPattern = network.getPattern(input, compare);
|
ICraftingPattern inputPattern = network.getPattern(input, compare);
|
||||||
|
|
||||||
@@ -154,12 +159,12 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancelled() {
|
public void onCancelled() {
|
||||||
for (ItemStack took : this.took) {
|
for (ItemStack stack : took) {
|
||||||
network.insertItem(took, took.stackSize, false);
|
network.insertItem(stack, stack.stackSize, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FluidStack took : this.tookFluids) {
|
for (FluidStack stack : tookFluids) {
|
||||||
network.insertFluid(took, took.amount, false);
|
network.insertFluid(stack, stack.amount, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,24 +183,26 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
public boolean update() {
|
public boolean update() {
|
||||||
for (IProcessable processable : toProcess) {
|
for (IProcessable processable : toProcess) {
|
||||||
if (processable.getPattern().getContainer().getFacingInventory() != null && processable.getStackToInsert() != null) {
|
IItemHandler inventory = processable.getPattern().getContainer().getFacingInventory();
|
||||||
|
|
||||||
|
if (inventory != null && processable.getStackToInsert() != null) {
|
||||||
ItemStack toInsert = network.extractItem(processable.getStackToInsert(), 1, compare);
|
ItemStack toInsert = network.extractItem(processable.getStackToInsert(), 1, compare);
|
||||||
|
|
||||||
if (ItemHandlerHelper.insertItem(processable.getPattern().getContainer().getFacingInventory(), toInsert, true) == null) {
|
if (ItemHandlerHelper.insertItem(inventory, toInsert, true) == null) {
|
||||||
ItemHandlerHelper.insertItem(processable.getPattern().getContainer().getFacingInventory(), toInsert, false);
|
ItemHandlerHelper.insertItem(inventory, toInsert, false);
|
||||||
|
|
||||||
processable.nextStack();
|
processable.nextStack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ItemStack toTakeStack : toTake.getStacks()) {
|
for (ItemStack stack : toTake.getStacks()) {
|
||||||
ItemStack took = network.extractItem(toTakeStack, 1, compare);
|
ItemStack stackExtracted = network.extractItem(stack, 1, compare);
|
||||||
|
|
||||||
if (took != null) {
|
if (stackExtracted != null) {
|
||||||
toTake.remove(toTakeStack, 1, true);
|
toTake.remove(stack, 1, true);
|
||||||
|
|
||||||
this.took.add(took);
|
took.add(stackExtracted);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -203,20 +210,20 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
// If we took all the items, we can start taking fluids
|
// If we took all the items, we can start taking fluids
|
||||||
if (toTake.isEmpty()) {
|
if (toTake.isEmpty()) {
|
||||||
for (FluidStack toTakeStack : toTakeFluids.getStacks()) {
|
for (FluidStack stack : toTakeFluids.getStacks()) {
|
||||||
FluidStack took = network.extractFluid(toTakeStack, toTakeStack.amount);
|
FluidStack stackExtracted = network.extractFluid(stack, stack.amount);
|
||||||
|
|
||||||
if (took != null) {
|
if (stackExtracted != null) {
|
||||||
toTakeFluids.remove(toTakeStack, toTakeStack.amount, true);
|
toTakeFluids.remove(stack, stack.amount, true);
|
||||||
|
|
||||||
this.tookFluids.add(took);
|
tookFluids.add(stackExtracted);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toTake.isEmpty() && toTakeFluids.isEmpty() && missing.isEmpty() && hasProcessedItems()) {
|
if (isFinished()) {
|
||||||
ItemStack insert = toInsert.peek();
|
ItemStack insert = toInsert.peek();
|
||||||
|
|
||||||
if (network.insertItem(insert, insert.stackSize, true) == null) {
|
if (network.insertItem(insert, insert.stackSize, true) == null) {
|
||||||
@@ -252,10 +259,10 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
0
|
0
|
||||||
));
|
));
|
||||||
|
|
||||||
if (!toTake.isEmpty()) {
|
if (isFinished()) {
|
||||||
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_taking", 16));
|
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_inserting", 16));
|
||||||
|
|
||||||
elements.addAll(toTake.getStacks().stream()
|
elements.addAll(toInsert.stream()
|
||||||
.map(stack -> new CraftingMonitorElementItemRender(
|
.map(stack -> new CraftingMonitorElementItemRender(
|
||||||
-1,
|
-1,
|
||||||
stack,
|
stack,
|
||||||
@@ -264,33 +271,47 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
))
|
))
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
|
if (!toTake.isEmpty()) {
|
||||||
|
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_taking", 16));
|
||||||
|
|
||||||
if (!toTakeFluids.isEmpty()) {
|
elements.addAll(toTake.getStacks().stream()
|
||||||
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.fluids_taking", 16));
|
.map(stack -> new CraftingMonitorElementItemRender(
|
||||||
|
-1,
|
||||||
|
stack,
|
||||||
|
stack.stackSize,
|
||||||
|
32
|
||||||
|
))
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
elements.addAll(toTakeFluids.getStacks().stream()
|
if (!toTakeFluids.isEmpty()) {
|
||||||
.map(stack -> new CraftingMonitorElementFluidRender(
|
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.fluids_taking", 16));
|
||||||
-1,
|
|
||||||
stack,
|
|
||||||
32
|
|
||||||
))
|
|
||||||
.collect(Collectors.toList())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasProcessedItems()) {
|
elements.addAll(toTakeFluids.getStacks().stream()
|
||||||
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_processing", 16));
|
.map(stack -> new CraftingMonitorElementFluidRender(
|
||||||
|
-1,
|
||||||
|
stack,
|
||||||
|
32
|
||||||
|
))
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for (IProcessable processable : toProcess) {
|
if (!hasProcessedItems()) {
|
||||||
for (int i = 0; i < processable.getPattern().getOutputs().size(); ++i) {
|
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_processing", 16));
|
||||||
if (!processable.hasReceivedOutput(i)) {
|
|
||||||
elements.add(new CraftingMonitorElementItemRender(
|
for (IProcessable processable : toProcess) {
|
||||||
-1,
|
for (int i = 0; i < processable.getPattern().getOutputs().size(); ++i) {
|
||||||
processable.getPattern().getOutputs().get(i),
|
if (!processable.hasReceivedOutput(i)) {
|
||||||
processable.getPattern().getOutputs().get(i).stackSize,
|
elements.add(new CraftingMonitorElementItemRender(
|
||||||
32
|
-1,
|
||||||
));
|
processable.getPattern().getOutputs().get(i),
|
||||||
|
processable.getPattern().getOutputs().get(i).stackSize,
|
||||||
|
32
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -309,17 +330,11 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
return toProcess;
|
return toProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isFinished() {
|
||||||
|
return toTake.isEmpty() && toTakeFluids.isEmpty() && missing.isEmpty() && hasProcessedItems();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hasProcessedItems() {
|
private boolean hasProcessedItems() {
|
||||||
return toProcess.stream().allMatch(IProcessable::hasReceivedOutputs);
|
return toProcess.stream().allMatch(IProcessable::hasReceivedOutputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addExtras(ICraftingPattern pattern) {
|
|
||||||
pattern.getOutputs().stream()
|
|
||||||
.filter(o -> o.stackSize > 1)
|
|
||||||
.forEach(o -> extras.add(ItemHandlerHelper.copyStackWithSize(o, o.stackSize - 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void decrOrRemoveExtras(ItemStack stack) {
|
|
||||||
extras.remove(ItemHandlerHelper.copyStackWithSize(stack, 1), true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ gui.refinedstorage:crafting_monitor=Crafting Monitor
|
|||||||
gui.refinedstorage:crafting_monitor.items_taking=Items taking
|
gui.refinedstorage:crafting_monitor.items_taking=Items taking
|
||||||
gui.refinedstorage:crafting_monitor.fluids_taking=Fluids taking
|
gui.refinedstorage:crafting_monitor.fluids_taking=Fluids taking
|
||||||
gui.refinedstorage:crafting_monitor.items_processing=Items processing
|
gui.refinedstorage:crafting_monitor.items_processing=Items processing
|
||||||
|
gui.refinedstorage:crafting_monitor.items_inserting=Items inserting
|
||||||
gui.refinedstorage:crafting_monitor.machine_in_use=Waiting on machine that is in use by another task
|
gui.refinedstorage:crafting_monitor.machine_in_use=Waiting on machine that is in use by another task
|
||||||
gui.refinedstorage:crafting_monitor.machine_none=No machine found
|
gui.refinedstorage:crafting_monitor.machine_none=No machine found
|
||||||
gui.refinedstorage:wireless_transmitter=Wireless Transmitter
|
gui.refinedstorage:wireless_transmitter=Wireless Transmitter
|
||||||
|
Reference in New Issue
Block a user