Show IProcessable items in crafting monitor too

This commit is contained in:
Raoul Van den Berge
2016-10-08 00:11:19 +02:00
parent 09b0620c85
commit 423696d89a
7 changed files with 82 additions and 115 deletions

View File

@@ -27,6 +27,8 @@ public interface IProcessable {
*/
boolean hasReceivedOutputs();
boolean hasReceivedOutput(int i);
/**
* @param stack the stack that was inserted in the storage system
* @return whether this item belonged to the processable item

View File

@@ -1,26 +1,56 @@
package refinedstorage.apiimpl.autocrafting.craftingmonitor;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import refinedstorage.gui.GuiBase;
public abstract class CraftingMonitorElementItemRender implements ICraftingMonitorElement<GuiBase> {
public class CraftingMonitorElementItemRender implements ICraftingMonitorElement<GuiBase> {
public static final String ID = "item_render";
private int taskId;
private ItemStack stack;
private int quantity;
private int offset;
public CraftingMonitorElementItemRender(int taskId, ItemStack stack, int quantity, int offset) {
this.taskId = taskId;
this.stack = stack;
this.quantity = quantity;
this.offset = offset;
}
@Override
public void draw(GuiBase gui, int x, int y) {
gui.drawItem(x + 2, y + 1, getItem());
gui.drawItem(x + 2 + offset, y + 1, stack);
float scale = 0.5f;
GlStateManager.pushMatrix();
GlStateManager.scale(scale, scale, 1);
gui.drawString(gui.calculateOffsetOnScale(x + 21, scale), gui.calculateOffsetOnScale(y + 7, scale), getQuantity() + " " + getItem().getDisplayName());
gui.drawString(gui.calculateOffsetOnScale(x + 21 + offset, scale), gui.calculateOffsetOnScale(y + 7, scale), quantity + " " + stack.getDisplayName());
GlStateManager.popMatrix();
}
protected abstract ItemStack getItem();
protected abstract int getQuantity();
@Override
public int getTaskId() {
return taskId;
}
@Override
public String getId() {
return ID;
}
@Override
public void write(ByteBuf buf) {
buf.writeInt(taskId);
ByteBufUtils.writeItemStack(buf, stack);
buf.writeInt(quantity);
buf.writeInt(offset);
}
}

View File

@@ -1,46 +0,0 @@
package refinedstorage.apiimpl.autocrafting.craftingmonitor;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.network.ByteBufUtils;
public class CraftingMonitorElementRoot extends CraftingMonitorElementItemRender {
public static final String ID = "root";
private int id;
private ItemStack output;
private int quantity;
public CraftingMonitorElementRoot(int id, ItemStack output, int quantity) {
this.id = id;
this.output = output;
this.quantity = quantity;
}
@Override
public int getTaskId() {
return id;
}
@Override
public String getId() {
return ID;
}
@Override
public void write(ByteBuf buf) {
buf.writeInt(id);
ByteBufUtils.writeItemStack(buf, output);
buf.writeInt(quantity);
}
@Override
protected ItemStack getItem() {
return output;
}
@Override
protected int getQuantity() {
return quantity;
}
}

View File

@@ -1,49 +0,0 @@
package refinedstorage.apiimpl.autocrafting.craftingmonitor;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import refinedstorage.gui.GuiBase;
public class CraftingMonitorElementToTake extends CraftingMonitorElementItemRender {
public static final String ID = "to_take";
private ItemStack toTake;
private int remaining;
public CraftingMonitorElementToTake(ItemStack toTake, int remaining) {
this.toTake = toTake;
this.remaining = remaining;
}
@Override
public void draw(GuiBase gui, int x, int y) {
super.draw(gui, x + 32, y);
}
@Override
public int getTaskId() {
return -1;
}
@Override
public String getId() {
return ID;
}
@Override
public void write(ByteBuf buf) {
ByteBufUtils.writeItemStack(buf, toTake);
buf.writeInt(remaining);
}
@Override
protected ItemStack getItem() {
return toTake;
}
@Override
protected int getQuantity() {
return remaining;
}
}

View File

@@ -10,9 +10,8 @@ import refinedstorage.api.autocrafting.task.ICraftingTask;
import refinedstorage.api.autocrafting.task.IProcessable;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.util.IItemStackList;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementRoot;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementToTake;
import java.util.ArrayList;
import java.util.List;
@@ -123,7 +122,7 @@ public class CraftingTaskNormal implements ICraftingTask {
break;
}
if (toTake.isEmpty() && missing.isEmpty() && toProcess.stream().allMatch(IProcessable::hasReceivedOutputs)) {
if (toTake.isEmpty() && missing.isEmpty() && hasProcessedItems()) {
for (ItemStack output : pattern.getOutputs()) {
// @TODO: Handle remainder
network.insertItem(output, output.stackSize, false);
@@ -154,18 +153,43 @@ public class CraftingTaskNormal implements ICraftingTask {
public List<ICraftingMonitorElement> getCraftingMonitorElements() {
List<ICraftingMonitorElement> elements = new ArrayList<>();
elements.add(new CraftingMonitorElementRoot(
elements.add(new CraftingMonitorElementItemRender(
network.getCraftingTasks().indexOf(this),
pattern.getOutputs().get(0),
quantity
quantity,
0
));
if (!toTake.isEmpty()) {
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_taking", 16));
elements.addAll(toTake.getStacks().stream()
.map(stack -> new CraftingMonitorElementToTake(stack, stack.stackSize))
.map(stack -> new CraftingMonitorElementItemRender(
-1,
stack,
stack.stackSize,
32
))
.collect(Collectors.toList())
);
}
if (!hasProcessedItems()) {
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_processing", 16));
for (IProcessable processable : toProcess) {
for (int i = 0; i < processable.getPattern().getOutputs().size(); ++i) {
if (!processable.hasReceivedOutput(i)) {
elements.add(new CraftingMonitorElementItemRender(
-1,
processable.getPattern().getOutputs().get(i),
processable.getPattern().getOutputs().get(i).stackSize,
32
));
}
}
}
}
return elements;
}
@@ -175,12 +199,15 @@ public class CraftingTaskNormal implements ICraftingTask {
return pattern;
}
@Override
public List<IProcessable> getToProcess() {
return toProcess;
}
private boolean hasProcessedItems() {
return toProcess.stream().allMatch(IProcessable::hasReceivedOutputs);
}
private void addExtras(ICraftingPattern pattern) {
pattern.getOutputs().stream()
.filter(o -> o.stackSize > 1)

View File

@@ -45,6 +45,11 @@ public class Processable implements IProcessable {
return true;
}
@Override
public boolean hasReceivedOutput(int i) {
return satisfied[i];
}
@Override
public boolean onReceiveOutput(ItemStack stack) {
for (int i = 0; i < pattern.getOutputs().size(); ++i) {

View File

@@ -19,9 +19,8 @@ import refinedstorage.RS;
import refinedstorage.RSBlocks;
import refinedstorage.RSItems;
import refinedstorage.api.RSAPI;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementRoot;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementToTake;
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryNormal;
import refinedstorage.apiimpl.solderer.*;
import refinedstorage.apiimpl.storage.fluid.FluidStorageNBT;
@@ -50,8 +49,7 @@ public class CommonProxy {
RSAPI.instance().getCraftingTaskRegistry().addFactory(CraftingTaskFactoryNormal.ID, new CraftingTaskFactoryNormal());
RSAPI.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementRoot.ID, buf -> new CraftingMonitorElementRoot(buf.readInt(), ByteBufUtils.readItemStack(buf), buf.readInt()));
RSAPI.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementToTake.ID, buf -> new CraftingMonitorElementToTake(ByteBufUtils.readItemStack(buf), buf.readInt()));
RSAPI.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementItemRender.ID, buf -> new CraftingMonitorElementItemRender(buf.readInt(), ByteBufUtils.readItemStack(buf), buf.readInt(), buf.readInt()));
RSAPI.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementText.ID, buf -> new CraftingMonitorElementText(ByteBufUtils.readUTF8String(buf), buf.readInt()));
int id = 0;