Better crafting monitor element for machines in use / machine not found

This commit is contained in:
Raoul Van den Berge
2016-10-19 19:00:55 +02:00
parent a4b859764a
commit 8a7f301abc
14 changed files with 181 additions and 49 deletions

View File

@@ -1,25 +1,25 @@
package refinedstorage.api.autocrafting.craftingmonitor;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import refinedstorage.api.render.IElementDrawer;
/**
* Represents a crafting monitor element.
*/
public interface ICraftingMonitorElement<T> {
/**
* @param x position on the x axis to render
* @param y position on the y axis to render
* @param itemDrawer a drawer for {@link ItemStack}s
* @param fluidDrawer a drawer for {@link FluidStack}s
* @param stringDrawer a drawer for {@link String}s
* @param x position on the x axis to render
* @param y position on the y axis to render
* @param drawers the drawers that this element can use
*/
@SideOnly(Side.CLIENT)
void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer);
void draw(int x, int y, ICraftingMonitorElementDrawers drawers);
/**
* @return whether the crafting monitor can draw a grey background behind the element when selected
*/
boolean canDrawSelection();
/**
* Returns the position where the corresponding task is in the crafting task list.
@@ -36,6 +36,13 @@ public interface ICraftingMonitorElement<T> {
*/
String getId();
/**
* @return the tooltip of this element, or null for no tooltip
*/
default String getTooltip() {
return null;
}
/**
* Writes the data to the network.
*

View File

@@ -0,0 +1,15 @@
package refinedstorage.api.autocrafting.craftingmonitor;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import refinedstorage.api.render.IElementDrawer;
public interface ICraftingMonitorElementDrawers {
IElementDrawer<ItemStack> getItemDrawer();
IElementDrawer<FluidStack> getFluidDrawer();
IElementDrawer<String> getStringDrawer();
IElementDrawer<?> getRedOverlayDrawer();
}

View File

@@ -5,8 +5,6 @@ import net.minecraft.nbt.NBTTagCompound;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.util.IItemStackList;
import java.util.Deque;
/**
* Represents a item in a crafting task that can be processed.
*/
@@ -31,7 +29,7 @@ public interface IProcessable {
void setStartedProcessing();
boolean isStartedProcessing();
boolean hasStartedProcessing();
/**
* @return true if we received all outputs, false otherwise

View File

@@ -0,0 +1,53 @@
package refinedstorage.apiimpl.autocrafting.craftingmonitor;
import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementDrawers;
public class CraftingMonitorElementError implements ICraftingMonitorElement {
public static final String ID = "error";
private ICraftingMonitorElement base;
private String tooltip;
public CraftingMonitorElementError(ICraftingMonitorElement base, String tooltip) {
this.base = base;
this.tooltip = tooltip;
}
@Override
public void draw(int x, int y, ICraftingMonitorElementDrawers drawers) {
drawers.getRedOverlayDrawer().draw(x, y, null);
base.draw(x, y, drawers);
}
@Override
public boolean canDrawSelection() {
return false;
}
@Override
public int getTaskId() {
return base.getTaskId();
}
@Override
public String getId() {
return ID;
}
@Override
public String getTooltip() {
return tooltip;
}
@Override
public void write(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf, base.getId());
ByteBufUtils.writeUTF8String(buf, tooltip);
base.write(buf);
}
}

View File

@@ -2,13 +2,12 @@ package refinedstorage.apiimpl.autocrafting.craftingmonitor;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import refinedstorage.RSUtils;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import refinedstorage.api.render.IElementDrawer;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementDrawers;
import refinedstorage.gui.GuiBase;
public class CraftingMonitorElementFluidRender implements ICraftingMonitorElement<FluidStack> {
@@ -26,19 +25,24 @@ public class CraftingMonitorElementFluidRender implements ICraftingMonitorElemen
@Override
@SideOnly(Side.CLIENT)
public void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer) {
fluidDrawer.draw(x + 2 + offset, y + 1, stack);
public void draw(int x, int y, ICraftingMonitorElementDrawers drawers) {
drawers.getFluidDrawer().draw(x + 2 + offset, y + 1, stack);
float scale = 0.5f;
GlStateManager.pushMatrix();
GlStateManager.scale(scale, scale, 1);
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 21 + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), RSUtils.formatFluidStackQuantity(stack) + " " + stack.getLocalizedName());
drawers.getStringDrawer().draw(GuiBase.calculateOffsetOnScale(x + 21 + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), RSUtils.formatFluidStackQuantity(stack) + " " + stack.getLocalizedName());
GlStateManager.popMatrix();
}
@Override
public boolean canDrawSelection() {
return true;
}
@Override
public int getTaskId() {
return taskId;

View File

@@ -3,12 +3,11 @@ package refinedstorage.apiimpl.autocrafting.craftingmonitor;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import refinedstorage.api.render.IElementDrawer;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementDrawers;
import refinedstorage.gui.GuiBase;
public class CraftingMonitorElementItemRender implements ICraftingMonitorElement<ItemStack> {
@@ -28,19 +27,24 @@ public class CraftingMonitorElementItemRender implements ICraftingMonitorElement
@Override
@SideOnly(Side.CLIENT)
public void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer) {
itemDrawer.draw(x + 2 + offset, y + 1, stack);
public void draw(int x, int y, ICraftingMonitorElementDrawers drawers) {
drawers.getItemDrawer().draw(x + 2 + offset, y + 1, stack);
float scale = 0.5f;
GlStateManager.pushMatrix();
GlStateManager.scale(scale, scale, 1);
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 21 + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), quantity + " " + stack.getDisplayName());
drawers.getStringDrawer().draw(GuiBase.calculateOffsetOnScale(x + 21 + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), quantity + " " + stack.getDisplayName());
GlStateManager.popMatrix();
}
@Override
public boolean canDrawSelection() {
return true;
}
@Override
public int getTaskId() {
return taskId;

View File

@@ -3,13 +3,11 @@ package refinedstorage.apiimpl.autocrafting.craftingmonitor;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import refinedstorage.api.render.IElementDrawer;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementDrawers;
import refinedstorage.gui.GuiBase;
public class CraftingMonitorElementText implements ICraftingMonitorElement<String> {
@@ -33,17 +31,22 @@ public class CraftingMonitorElementText implements ICraftingMonitorElement<Strin
@Override
@SideOnly(Side.CLIENT)
public void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer) {
public void draw(int x, int y, ICraftingMonitorElementDrawers drawers) {
float scale = 0.5f;
GlStateManager.pushMatrix();
GlStateManager.scale(scale, scale, 1);
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), I18n.format(text));
drawers.getStringDrawer().draw(GuiBase.calculateOffsetOnScale(x + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), I18n.format(text));
GlStateManager.popMatrix();
}
@Override
public boolean canDrawSelection() {
return true;
}
@Override
public int getTaskId() {
return -1;

View File

@@ -17,6 +17,7 @@ import refinedstorage.api.util.IComparer;
import refinedstorage.api.util.IFluidStackList;
import refinedstorage.api.util.IItemStackList;
import refinedstorage.apiimpl.API;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementError;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementFluidRender;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
@@ -236,7 +237,7 @@ public class CraftingTask implements ICraftingTask {
for (IProcessable processable : toProcess) {
IItemHandler inventory = processable.getPattern().getContainer().getFacingInventory();
if (!processable.isStartedProcessing() && inventory != null && processable.canStartProcessing(network.getItemStorageCache().getList()) && canProcess(processable)) {
if (inventory != null && !processable.hasStartedProcessing() && processable.canStartProcessing(network.getItemStorageCache().getList()) && canProcess(processable)) {
processable.setStartedProcessing();
for (ItemStack insertStack : processable.getToInsert().getStacks()) {
@@ -302,8 +303,8 @@ public class CraftingTask implements ICraftingTask {
private boolean canProcess(IProcessable processable) {
for (ICraftingTask otherTask : network.getCraftingTasks()) {
for (IProcessable otherProcessable : otherTask.getToProcess()) {
if (otherProcessable != processable && !otherProcessable.hasReceivedOutputs() && otherProcessable.isStartedProcessing()) {
if (!isPatternsEqual(processable.getPattern(), otherProcessable.getPattern())) {
if (otherProcessable != processable && !otherProcessable.hasReceivedOutputs() && otherProcessable.hasStartedProcessing() && otherProcessable.getPattern().getContainer().getFacingTile() != null) {
if (!arePatternsEqual(processable.getPattern(), otherProcessable.getPattern())) {
if (processable.getPattern().getContainer().getFacingTile().getPos().equals(otherProcessable.getPattern().getContainer().getFacingTile().getPos())) {
return false;
}
@@ -315,7 +316,7 @@ public class CraftingTask implements ICraftingTask {
return true;
}
private boolean isPatternsEqual(ICraftingPattern left, ICraftingPattern right) {
private boolean arePatternsEqual(ICraftingPattern left, ICraftingPattern right) {
for (int i = 0; i < 9; ++i) {
ItemStack leftStack = left.getInputs().get(i);
ItemStack rightStack = right.getInputs().get(i);
@@ -436,23 +437,23 @@ public class CraftingTask implements ICraftingTask {
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_processing", 16));
for (IProcessable processable : toProcess) {
if (processable.hasReceivedOutputs()) {
continue;
}
for (int i = 0; i < processable.getPattern().getOutputs().size(); ++i) {
if (!processable.hasReceivedOutput(i)) {
elements.add(new CraftingMonitorElementItemRender(
ICraftingMonitorElement element = new CraftingMonitorElementItemRender(
-1,
processable.getPattern().getOutputs().get(i),
processable.getPattern().getOutputs().get(i).stackSize,
32
));
}
}
);
if (!canProcess(processable)) {
elements.add(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.machine_in_use", 32));
if (processable.getPattern().getContainer().getFacingTile() == null) {
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_none");
} else if (!canProcess(processable)) {
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_in_use");
}
elements.add(element);
}
}
}
}

View File

@@ -73,7 +73,7 @@ public class Processable implements IProcessable {
}
@Override
public boolean isStartedProcessing() {
public boolean hasStartedProcessing() {
return startedProcessing;
}

View File

@@ -1,11 +1,14 @@
package refinedstorage.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import refinedstorage.RS;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementDrawers;
import refinedstorage.api.render.IElementDrawer;
import refinedstorage.container.ContainerCraftingMonitor;
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
@@ -16,6 +19,36 @@ import java.io.IOException;
import java.util.List;
public class GuiCraftingMonitor extends GuiBase {
public class CraftingMonitorElementDrawers implements ICraftingMonitorElementDrawers {
private IElementDrawer<FluidStack> fluidDrawer = (x, y, element) -> FLUID_RENDERER.draw(GuiCraftingMonitor.this.mc, x, y, element);
private IElementDrawer redOverlayDrawer = (x, y, element) -> {
GlStateManager.color(1, 1, 1);
bindTexture("gui/crafting_preview.png"); // Don't even care
drawTexture(x, y, 0, 238, ITEM_WIDTH, ITEM_HEIGHT - 1);
bindTexture("gui/crafting_monitor.png");
};
@Override
public IElementDrawer<ItemStack> getItemDrawer() {
return GuiCraftingMonitor.this::drawItem;
}
@Override
public IElementDrawer<FluidStack> getFluidDrawer() {
return fluidDrawer;
}
@Override
public IElementDrawer<String> getStringDrawer() {
return GuiCraftingMonitor.this::drawString;
}
@Override
public IElementDrawer<?> getRedOverlayDrawer() {
return redOverlayDrawer;
}
}
private static final int VISIBLE_ROWS = 5;
private static final int ITEM_WIDTH = 143;
@@ -26,15 +59,13 @@ public class GuiCraftingMonitor extends GuiBase {
private GuiButton cancelButton;
private GuiButton cancelAllButton;
private ICraftingMonitorElementDrawers drawers = new CraftingMonitorElementDrawers();
private int itemSelected = -1;
private int itemSelectedX = -1;
private int itemSelectedY = -1;
private IElementDrawer<String> stringDrawer = this::drawString;
private IElementDrawer<ItemStack> itemDrawer = this::drawItem;
private IElementDrawer<FluidStack> fluidDrawer = (x, y, element) -> FLUID_RENDERER.draw(mc, x, y, element);
public GuiCraftingMonitor(ContainerCraftingMonitor container, TileCraftingMonitor craftingMonitor) {
super(container, 176, 230);
@@ -76,7 +107,7 @@ public class GuiCraftingMonitor extends GuiBase {
drawTexture(x, y, 0, 0, width, height);
if (itemSelectedX != -1 && itemSelectedY != -1) {
if (itemSelectedX != -1 && itemSelectedY != -1 && itemSelected >= 0 && itemSelected < getElements().size() && getElements().get(itemSelected).canDrawSelection()) {
drawTexture(x + itemSelectedX, y + itemSelectedY, 0, 232, ITEM_WIDTH, ITEM_HEIGHT);
}
}
@@ -96,6 +127,7 @@ public class GuiCraftingMonitor extends GuiBase {
itemSelectedX = -1;
itemSelectedY = -1;
String itemSelectedTooltip = null;
for (int i = 0; i < VISIBLE_ROWS; ++i) {
if (item < getElements().size()) {
@@ -104,9 +136,13 @@ public class GuiCraftingMonitor extends GuiBase {
if (item == itemSelected) {
itemSelectedX = x;
itemSelectedY = y;
if (inBounds(itemSelectedX, itemSelectedY, ITEM_WIDTH, ITEM_HEIGHT, mouseX, mouseY)) {
itemSelectedTooltip = element.getTooltip();
}
}
element.draw(x, y, itemDrawer, fluidDrawer, stringDrawer);
element.draw(x, y, drawers);
x = ox;
y += ITEM_HEIGHT;
@@ -114,6 +150,10 @@ public class GuiCraftingMonitor extends GuiBase {
item++;
}
if (itemSelectedTooltip != null) {
drawTooltip(mouseX, mouseY, I18n.format(itemSelectedTooltip));
}
}
private int getRows() {

View File

@@ -20,6 +20,7 @@ import refinedstorage.RSBlocks;
import refinedstorage.RSItems;
import refinedstorage.RSUtils;
import refinedstorage.apiimpl.API;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementError;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementFluidRender;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
@@ -58,6 +59,12 @@ public class ProxyCommon {
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementItemRender.ID, buf -> new CraftingMonitorElementItemRender(buf.readInt(), ByteBufUtils.readItemStack(buf), buf.readInt(), buf.readInt()));
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementFluidRender.ID, buf -> new CraftingMonitorElementFluidRender(buf.readInt(), RSUtils.readFluidStack(buf).getRight(), buf.readInt()));
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementText.ID, buf -> new CraftingMonitorElementText(ByteBufUtils.readUTF8String(buf), buf.readInt()));
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementError.ID, buf -> {
String id = ByteBufUtils.readUTF8String(buf);
String tooltip = ByteBufUtils.readUTF8String(buf);
return new CraftingMonitorElementError(API.instance().getCraftingMonitorElementRegistry().getFactory(id).apply(buf), tooltip);
});
API.instance().getCraftingPreviewElementRegistry().add(CraftingPreviewElementItemStack.ID, CraftingPreviewElementItemStack::fromByteBuf);
API.instance().getCraftingPreviewElementRegistry().add(CraftingPreviewElementFluidStack.ID, CraftingPreviewElementFluidStack::fromByteBuf);

View File

@@ -23,7 +23,7 @@ gui.refinedstorage:crafting_monitor.items_taking=Items taking
gui.refinedstorage:crafting_monitor.fluids_taking=Fluids taking
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=Machine is in use
gui.refinedstorage:crafting_monitor.machine_none=No machine found
gui.refinedstorage:wireless_transmitter=Wireless Transmitter
gui.refinedstorage:wireless_transmitter.distance=%d blocks

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB