ICraftingMonitorElement for the win
This commit is contained in:
@@ -295,7 +295,7 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
return guiTop;
|
return guiTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int calculateOffsetOnScale(int pos, float scale) {
|
public int calculateOffsetOnScale(int pos, float scale) {
|
||||||
float multiplier = (pos / scale);
|
float multiplier = (pos / scale);
|
||||||
|
|
||||||
return (int) multiplier;
|
return (int) multiplier;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import net.minecraft.world.World;
|
|||||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||||
import refinedstorage.RefinedStorageGui;
|
import refinedstorage.RefinedStorageGui;
|
||||||
import refinedstorage.container.*;
|
import refinedstorage.container.*;
|
||||||
|
import refinedstorage.gui.craftingmonitor.GuiCraftingMonitor;
|
||||||
import refinedstorage.gui.grid.GuiGrid;
|
import refinedstorage.gui.grid.GuiGrid;
|
||||||
import refinedstorage.tile.*;
|
import refinedstorage.tile.*;
|
||||||
import refinedstorage.tile.externalstorage.TileExternalStorage;
|
import refinedstorage.tile.externalstorage.TileExternalStorage;
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package refinedstorage.gui.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.gui.GuiBase;
|
||||||
|
|
||||||
|
public class CraftingMonitorElementRoot implements ICraftingMonitorElement {
|
||||||
|
static {
|
||||||
|
REGISTRY.put(0, buf -> new CraftingMonitorElementRoot(buf.readInt(), ByteBufUtils.readItemStack(buf), buf.readInt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
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 void draw(GuiBase gui, int x, int y) {
|
||||||
|
gui.drawItem(x + 2, y + 1, output);
|
||||||
|
|
||||||
|
float scale = 0.5f;
|
||||||
|
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
GlStateManager.scale(scale, scale, 1);
|
||||||
|
|
||||||
|
gui.drawString(gui.calculateOffsetOnScale(x + 21, scale), gui.calculateOffsetOnScale(y + 7, scale), quantity + " " + output.getDisplayName());
|
||||||
|
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTaskId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getType() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf) {
|
||||||
|
buf.writeInt(id);
|
||||||
|
ByteBufUtils.writeItemStack(buf, output);
|
||||||
|
buf.writeInt(quantity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package refinedstorage.gui;
|
package refinedstorage.gui.craftingmonitor;
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
|
||||||
import net.minecraft.client.renderer.RenderHelper;
|
import net.minecraft.client.renderer.RenderHelper;
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.container.ContainerCraftingMonitor;
|
import refinedstorage.container.ContainerCraftingMonitor;
|
||||||
|
import refinedstorage.gui.GuiBase;
|
||||||
|
import refinedstorage.gui.Scrollbar;
|
||||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import refinedstorage.network.MessageCraftingMonitorCancel;
|
import refinedstorage.network.MessageCraftingMonitorCancel;
|
||||||
import refinedstorage.tile.ClientCraftingTask;
|
|
||||||
import refinedstorage.tile.TileCraftingMonitor;
|
import refinedstorage.tile.TileCraftingMonitor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -56,12 +56,12 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
scrollbar.setEnabled(getRows() > VISIBLE_ROWS);
|
scrollbar.setEnabled(getRows() > VISIBLE_ROWS);
|
||||||
scrollbar.setMaxOffset(getRows() - VISIBLE_ROWS);
|
scrollbar.setMaxOffset(getRows() - VISIBLE_ROWS);
|
||||||
|
|
||||||
if (itemSelected >= getTasks().size()) {
|
if (itemSelected >= getElements().size()) {
|
||||||
itemSelected = -1;
|
itemSelected = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelButton.enabled = itemSelected != -1;
|
cancelButton.enabled = itemSelected != -1;
|
||||||
cancelAllButton.enabled = getTasks().size() > 0;
|
cancelAllButton.enabled = getElements().size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -92,50 +92,15 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
itemSelectedY = -1;
|
itemSelectedY = -1;
|
||||||
|
|
||||||
for (int i = 0; i < VISIBLE_ROWS; ++i) {
|
for (int i = 0; i < VISIBLE_ROWS; ++i) {
|
||||||
if (item < getTasks().size()) {
|
if (item < getElements().size()) {
|
||||||
ClientCraftingTask task = getTasks().get(item);
|
ICraftingMonitorElement element = getElements().get(item);
|
||||||
|
|
||||||
if (item == itemSelected) {
|
if (item == itemSelected) {
|
||||||
itemSelectedX = x;
|
itemSelectedX = x;
|
||||||
itemSelectedY = y;
|
itemSelectedY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (task.getDepth() > 0) {
|
element.draw(this, x, y);
|
||||||
x += 16F - ((float) (task.getChildren() - task.getDepth()) / (float) task.getChildren() * 16F);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
drawItem(x + 2, y + 1, task.getOutput());
|
|
||||||
|
|
||||||
float scale = 0.5f;
|
|
||||||
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
GlStateManager.scale(scale, scale, 1);
|
|
||||||
|
|
||||||
drawString(calculateOffsetOnScale(x + 21, scale), calculateOffsetOnScale(y + 7, scale), task.getQuantity() + " " + task.getOutput().getDisplayName());
|
|
||||||
|
|
||||||
/*if (task.getProgress() != -1) {
|
|
||||||
drawString(calculateOffsetOnScale(ox + ITEM_WIDTH - 15, scale), calculateOffsetOnScale(y + 7, scale), task.getProgress() + "%");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
|
|
||||||
/*if (inBounds(x + 2, y + 1, 16, 16, mouseX, mouseY) && !task.getStatus().trim().equals("")) {
|
|
||||||
lines = task.getStatus().split("\n");
|
|
||||||
|
|
||||||
for (int j = 0; j < lines.length; ++j) {
|
|
||||||
String line = lines[j];
|
|
||||||
|
|
||||||
if (line.startsWith("T=")) {
|
|
||||||
line = t(line.substring(2));
|
|
||||||
} else if (line.startsWith("I=")) {
|
|
||||||
line = TextFormatting.YELLOW + t(line.substring(2));
|
|
||||||
} else if (line.startsWith("B=")) {
|
|
||||||
line = TextFormatting.BLUE + t(line.substring(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
lines[j] = line;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
x = ox;
|
x = ox;
|
||||||
y += ITEM_HEIGHT;
|
y += ITEM_HEIGHT;
|
||||||
@@ -146,7 +111,7 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getRows() {
|
private int getRows() {
|
||||||
return getTasks().size();
|
return getElements().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -154,8 +119,12 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
super.actionPerformed(button);
|
super.actionPerformed(button);
|
||||||
|
|
||||||
if (button == cancelButton && itemSelected != -1) {
|
if (button == cancelButton && itemSelected != -1) {
|
||||||
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, itemSelected));
|
ICraftingMonitorElement element = getElements().get(itemSelected);
|
||||||
} else if (button == cancelAllButton && getTasks().size() > 0) {
|
|
||||||
|
if (element.getTaskId() != -1) {
|
||||||
|
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, element.getTaskId()));
|
||||||
|
}
|
||||||
|
} else if (button == cancelAllButton && getElements().size() > 0) {
|
||||||
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, -1));
|
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,14 +142,14 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
int ix = 8;
|
int ix = 8;
|
||||||
int iy = 20 + (i * ITEM_HEIGHT);
|
int iy = 20 + (i * ITEM_HEIGHT);
|
||||||
|
|
||||||
if (inBounds(ix, iy, ITEM_WIDTH, ITEM_HEIGHT, mouseX - guiLeft, mouseY - guiTop) && (item + i) < getTasks().size()) {
|
if (inBounds(ix, iy, ITEM_WIDTH, ITEM_HEIGHT, mouseX - guiLeft, mouseY - guiTop) && (item + i) < getElements().size()) {
|
||||||
itemSelected = item + i;
|
itemSelected = item + i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ClientCraftingTask> getTasks() {
|
private List<ICraftingMonitorElement> getElements() {
|
||||||
return TileCraftingMonitor.TASKS.getValue();
|
return TileCraftingMonitor.ELEMENTS.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package refinedstorage.gui.craftingmonitor;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import refinedstorage.gui.GuiBase;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public interface ICraftingMonitorElement {
|
||||||
|
Map<Integer, Function<ByteBuf, ICraftingMonitorElement>> REGISTRY = new HashMap<>();
|
||||||
|
|
||||||
|
void draw(GuiBase gui, int x, int y);
|
||||||
|
|
||||||
|
int getTaskId();
|
||||||
|
|
||||||
|
int getType();
|
||||||
|
|
||||||
|
void write(ByteBuf buf);
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package refinedstorage.tile;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public class ClientCraftingTask {
|
|
||||||
private ItemStack output;
|
|
||||||
private int quantity;
|
|
||||||
|
|
||||||
public ClientCraftingTask(ItemStack output, int quantity) {
|
|
||||||
this.output = output;
|
|
||||||
this.quantity = quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getOutput() {
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getQuantity() {
|
|
||||||
return quantity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -322,7 +322,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
public void updateCraftingMonitors() {
|
public void updateCraftingMonitors() {
|
||||||
for (INetworkNode node : nodeGraph.all()) {
|
for (INetworkNode node : nodeGraph.all()) {
|
||||||
if (node instanceof TileCraftingMonitor) {
|
if (node instanceof TileCraftingMonitor) {
|
||||||
((TileCraftingMonitor) node).dataManager.sendParameterToWatchers(TileCraftingMonitor.TASKS);
|
((TileCraftingMonitor) node).dataManager.sendParameterToWatchers(TileCraftingMonitor.ELEMENTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package refinedstorage.tile;
|
package refinedstorage.tile;
|
||||||
|
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
|
import refinedstorage.gui.craftingmonitor.CraftingMonitorElementRoot;
|
||||||
|
import refinedstorage.gui.craftingmonitor.ICraftingMonitorElement;
|
||||||
import refinedstorage.tile.data.ITileDataProducer;
|
import refinedstorage.tile.data.ITileDataProducer;
|
||||||
import refinedstorage.tile.data.RefinedStorageSerializers;
|
import refinedstorage.tile.data.RefinedStorageSerializers;
|
||||||
import refinedstorage.tile.data.TileDataParameter;
|
import refinedstorage.tile.data.TileDataParameter;
|
||||||
@@ -10,11 +12,12 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TileCraftingMonitor extends TileNode {
|
public class TileCraftingMonitor extends TileNode {
|
||||||
public static final TileDataParameter<List<ClientCraftingTask>> TASKS = new TileDataParameter<>(RefinedStorageSerializers.CLIENT_CRAFTING_TASK_SERIALIZER, Collections.emptyList(), new ITileDataProducer<List<ClientCraftingTask>, TileCraftingMonitor>() {
|
public static final TileDataParameter<List<ICraftingMonitorElement>> ELEMENTS = new TileDataParameter<>(RefinedStorageSerializers.CLIENT_CRAFTING_TASK_SERIALIZER, Collections.emptyList(), new ITileDataProducer<List<ICraftingMonitorElement>, TileCraftingMonitor>() {
|
||||||
@Override
|
@Override
|
||||||
public List<ClientCraftingTask> getValue(TileCraftingMonitor tile) {
|
public List<ICraftingMonitorElement> getValue(TileCraftingMonitor tile) {
|
||||||
if (tile.connected) {
|
if (tile.connected) {
|
||||||
List<ClientCraftingTask> tasks = tile.network.getCraftingTasks().stream().map(t -> new ClientCraftingTask(
|
List<ICraftingMonitorElement> tasks = tile.network.getCraftingTasks().stream().map(t -> new CraftingMonitorElementRoot(
|
||||||
|
tile.network.getCraftingTasks().indexOf(t),
|
||||||
t.getPattern().getOutputs().get(0),
|
t.getPattern().getOutputs().get(0),
|
||||||
t.getQuantity()
|
t.getQuantity()
|
||||||
)).collect(Collectors.toList());
|
)).collect(Collectors.toList());
|
||||||
@@ -27,7 +30,7 @@ public class TileCraftingMonitor extends TileNode {
|
|||||||
});
|
});
|
||||||
|
|
||||||
public TileCraftingMonitor() {
|
public TileCraftingMonitor() {
|
||||||
dataManager.addParameter(TASKS);
|
dataManager.addParameter(ELEMENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import net.minecraft.network.datasync.DataSerializer;
|
|||||||
import net.minecraftforge.fluids.FluidRegistry;
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||||
import refinedstorage.tile.ClientCraftingTask;
|
import refinedstorage.gui.craftingmonitor.ICraftingMonitorElement;
|
||||||
import refinedstorage.tile.ClientNode;
|
import refinedstorage.tile.ClientNode;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -45,32 +45,37 @@ public final class RefinedStorageSerializers {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final DataSerializer<List<ClientCraftingTask>> CLIENT_CRAFTING_TASK_SERIALIZER = new DataSerializer<List<ClientCraftingTask>>() {
|
public static final DataSerializer<List<ICraftingMonitorElement>> CLIENT_CRAFTING_TASK_SERIALIZER = new DataSerializer<List<ICraftingMonitorElement>>() {
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketBuffer buf, List<ClientCraftingTask> tasks) {
|
public void write(PacketBuffer buf, List<ICraftingMonitorElement> tasks) {
|
||||||
buf.writeInt(tasks.size());
|
buf.writeInt(tasks.size());
|
||||||
|
|
||||||
for (ClientCraftingTask task : tasks) {
|
for (ICraftingMonitorElement task : tasks) {
|
||||||
ByteBufUtils.writeItemStack(buf, task.getOutput());
|
buf.writeInt(task.getType());
|
||||||
buf.writeInt(task.getQuantity());
|
|
||||||
|
task.write(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ClientCraftingTask> read(PacketBuffer buf) {
|
public List<ICraftingMonitorElement> read(PacketBuffer buf) {
|
||||||
List<ClientCraftingTask> tasks = new ArrayList<>();
|
List<ICraftingMonitorElement> tasks = new ArrayList<>();
|
||||||
|
|
||||||
int size = buf.readInt();
|
int size = buf.readInt();
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
tasks.add(new ClientCraftingTask(ByteBufUtils.readItemStack(buf), buf.readInt()));
|
int type = buf.readInt();
|
||||||
|
|
||||||
|
if (ICraftingMonitorElement.REGISTRY.containsKey(type)) {
|
||||||
|
tasks.add(ICraftingMonitorElement.REGISTRY.get(type).apply(buf));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataParameter<List<ClientCraftingTask>> createKey(int id) {
|
public DataParameter<List<ICraftingMonitorElement>> createKey(int id) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user