Make crafting monitor semi-functional again
This commit is contained in:
@@ -60,7 +60,6 @@ public interface IItemGridHandler {
|
|||||||
* Called when a player wants to cancel a crafting task.
|
* Called when a player wants to cancel a crafting task.
|
||||||
*
|
*
|
||||||
* @param id the task id, or -1 to cancel all tasks
|
* @param id the task id, or -1 to cancel all tasks
|
||||||
* @param depth the depth to cancel. 0 to cancel the entire task, or n to cancel the nth child of the task
|
|
||||||
*/
|
*/
|
||||||
void onCraftingCancelRequested(int id, int depth);
|
void onCraftingCancelRequested(int id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import net.minecraft.util.EnumFacing;
|
|||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
import refinedstorage.api.network.NetworkUtils;
|
import refinedstorage.api.network.NetworkUtils;
|
||||||
import refinedstorage.api.network.grid.IItemGridHandler;
|
import refinedstorage.api.network.grid.IItemGridHandler;
|
||||||
@@ -162,30 +163,13 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingCancelRequested(int id, int depth) {
|
public void onCraftingCancelRequested(int id) {
|
||||||
/*if (id >= 0 && id < network.getCraftingTasks().size()) {
|
if (id >= 0 && id < network.getCraftingTasks().size()) {
|
||||||
ICraftingTask task = network.getCraftingTasks().get(id);
|
network.cancelCraftingTask(network.getCraftingTasks().get(id));
|
||||||
|
|
||||||
if (depth == 0) {
|
|
||||||
network.cancelCraftingTask(task);
|
|
||||||
} else {
|
|
||||||
for (int i = 0; i < depth - 1; ++i) {
|
|
||||||
if (task == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
task = task.getChild();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (task != null) {
|
|
||||||
task.getChild().onCancelled(network);
|
|
||||||
task.setChild(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (id == -1) {
|
} else if (id == -1) {
|
||||||
for (ICraftingTask task : network.getCraftingTasks()) {
|
for (ICraftingTask task : network.getCraftingTasks()) {
|
||||||
network.cancelCraftingTask(task);
|
network.cancelCraftingTask(task);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package refinedstorage.gui;
|
package refinedstorage.gui;
|
||||||
|
|
||||||
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.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;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GuiCraftingMonitor extends GuiBase {
|
public class GuiCraftingMonitor extends GuiBase {
|
||||||
@@ -46,8 +47,8 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
int cancelButtonWidth = 14 + fontRendererObj.getStringWidth(cancel);
|
int cancelButtonWidth = 14 + fontRendererObj.getStringWidth(cancel);
|
||||||
int cancelAllButtonWidth = 14 + fontRendererObj.getStringWidth(cancelAll);
|
int cancelAllButtonWidth = 14 + fontRendererObj.getStringWidth(cancelAll);
|
||||||
|
|
||||||
cancelButton = addButton(x + 7, y + 114, cancelButtonWidth, 20, cancel, false);
|
cancelButton = addButton(x + 7, y + 113, cancelButtonWidth, 20, cancel, false);
|
||||||
cancelAllButton = addButton(x + 7 + cancelButtonWidth + 4, y + 114, cancelAllButtonWidth, 20, cancelAll, false);
|
cancelAllButton = addButton(x + 7 + cancelButtonWidth + 4, y + 113, cancelAllButtonWidth, 20, cancelAll, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,8 +84,6 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
|
|
||||||
RenderHelper.enableGUIStandardItemLighting();
|
RenderHelper.enableGUIStandardItemLighting();
|
||||||
|
|
||||||
String[] lines = null;
|
|
||||||
|
|
||||||
int ox = 8;
|
int ox = 8;
|
||||||
int x = ox;
|
int x = ox;
|
||||||
int y = 20;
|
int y = 20;
|
||||||
@@ -92,7 +91,7 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
itemSelectedX = -1;
|
itemSelectedX = -1;
|
||||||
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 < getTasks().size()) {
|
||||||
ClientCraftingTask task = getTasks().get(item);
|
ClientCraftingTask task = getTasks().get(item);
|
||||||
|
|
||||||
@@ -101,9 +100,9 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
itemSelectedY = y;
|
itemSelectedY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task.getDepth() > 0) {
|
/*if (task.getDepth() > 0) {
|
||||||
x += 16F - ((float) (task.getChildren() - task.getDepth()) / (float) task.getChildren() * 16F);
|
x += 16F - ((float) (task.getChildren() - task.getDepth()) / (float) task.getChildren() * 16F);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
drawItem(x + 2, y + 1, task.getOutput());
|
drawItem(x + 2, y + 1, task.getOutput());
|
||||||
|
|
||||||
@@ -112,15 +111,15 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
GlStateManager.scale(scale, scale, 1);
|
GlStateManager.scale(scale, scale, 1);
|
||||||
|
|
||||||
drawString(calculateOffsetOnScale(x + 21, scale), calculateOffsetOnScale(y + 7, scale), task.getOutput().getDisplayName());
|
drawString(calculateOffsetOnScale(x + 21, scale), calculateOffsetOnScale(y + 7, scale), task.getQuantity() + " " + task.getOutput().getDisplayName());
|
||||||
|
|
||||||
if (task.getProgress() != -1) {
|
/*if (task.getProgress() != -1) {
|
||||||
drawString(calculateOffsetOnScale(ox + ITEM_WIDTH - 15, scale), calculateOffsetOnScale(y + 7, scale), task.getProgress() + "%");
|
drawString(calculateOffsetOnScale(ox + ITEM_WIDTH - 15, scale), calculateOffsetOnScale(y + 7, scale), task.getProgress() + "%");
|
||||||
}
|
}*/
|
||||||
|
|
||||||
GlStateManager.popMatrix();
|
GlStateManager.popMatrix();
|
||||||
|
|
||||||
if (inBounds(x + 2, y + 1, 16, 16, mouseX, mouseY) && !task.getStatus().trim().equals("")) {
|
/*if (inBounds(x + 2, y + 1, 16, 16, mouseX, mouseY) && !task.getStatus().trim().equals("")) {
|
||||||
lines = task.getStatus().split("\n");
|
lines = task.getStatus().split("\n");
|
||||||
|
|
||||||
for (int j = 0; j < lines.length; ++j) {
|
for (int j = 0; j < lines.length; ++j) {
|
||||||
@@ -136,7 +135,7 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
|
|
||||||
lines[j] = line;
|
lines[j] = line;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
x = ox;
|
x = ox;
|
||||||
y += ITEM_HEIGHT;
|
y += ITEM_HEIGHT;
|
||||||
@@ -144,10 +143,6 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
|
|
||||||
item++;
|
item++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lines != null) {
|
|
||||||
drawTooltip(mouseX, mouseY, Arrays.asList(lines));
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getRows() {
|
private int getRows() {
|
||||||
@@ -159,11 +154,9 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
super.actionPerformed(button);
|
super.actionPerformed(button);
|
||||||
|
|
||||||
if (button == cancelButton && itemSelected != -1) {
|
if (button == cancelButton && itemSelected != -1) {
|
||||||
/*ClientCraftingTask task = getTasks().get(itemSelected);
|
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, itemSelected));
|
||||||
|
|
||||||
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, task.getId(), task.getDepth()));*/
|
|
||||||
} else if (button == cancelAllButton && getTasks().size() > 0) {
|
} else if (button == cancelAllButton && getTasks().size() > 0) {
|
||||||
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, -1, 0));
|
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +180,7 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> getTasks() {
|
private List<ClientCraftingTask> getTasks() {
|
||||||
return Collections.emptyList();
|
return TileCraftingMonitor.TASKS.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,11 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
|
|||||||
public MessageCraftingMonitorCancel() {
|
public MessageCraftingMonitorCancel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id, int depth) {
|
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id) {
|
||||||
this.x = craftingMonitor.getPos().getX();
|
this.x = craftingMonitor.getPos().getX();
|
||||||
this.y = craftingMonitor.getPos().getY();
|
this.y = craftingMonitor.getPos().getY();
|
||||||
this.z = craftingMonitor.getPos().getZ();
|
this.z = craftingMonitor.getPos().getZ();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.depth = depth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -31,7 +30,6 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
|
|||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
id = buf.readInt();
|
id = buf.readInt();
|
||||||
depth = buf.readInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,7 +38,6 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
|
|||||||
buf.writeInt(y);
|
buf.writeInt(y);
|
||||||
buf.writeInt(z);
|
buf.writeInt(z);
|
||||||
buf.writeInt(id);
|
buf.writeInt(id);
|
||||||
buf.writeInt(depth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,7 +48,7 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
|
|||||||
TileCraftingMonitor monitor = (TileCraftingMonitor) tile;
|
TileCraftingMonitor monitor = (TileCraftingMonitor) tile;
|
||||||
|
|
||||||
if (monitor.isConnected()) {
|
if (monitor.isConnected()) {
|
||||||
monitor.getNetwork().getItemGridHandler().onCraftingCancelRequested(message.id, message.depth);
|
monitor.getNetwork().getItemGridHandler().onCraftingCancelRequested(message.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/main/java/refinedstorage/tile/ClientCraftingTask.java
Executable file
21
src/main/java/refinedstorage/tile/ClientCraftingTask.java
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
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.TASKS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,35 @@
|
|||||||
package refinedstorage.tile;
|
package refinedstorage.tile;
|
||||||
|
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
|
import refinedstorage.tile.data.ITileDataProducer;
|
||||||
|
import refinedstorage.tile.data.RefinedStorageSerializers;
|
||||||
|
import refinedstorage.tile.data.TileDataParameter;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
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>() {
|
||||||
|
@Override
|
||||||
|
public List<ClientCraftingTask> getValue(TileCraftingMonitor tile) {
|
||||||
|
if (tile.connected) {
|
||||||
|
List<ClientCraftingTask> tasks = tile.network.getCraftingTasks().stream().map(t -> new ClientCraftingTask(
|
||||||
|
t.getPattern().getOutputs().get(0),
|
||||||
|
t.getQuantity()
|
||||||
|
)).collect(Collectors.toList());
|
||||||
|
|
||||||
|
return tasks;
|
||||||
|
} else {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
public TileCraftingMonitor() {
|
||||||
|
dataManager.addParameter(TASKS);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage() {
|
||||||
return RefinedStorage.INSTANCE.config.craftingMonitorUsage;
|
return RefinedStorage.INSTANCE.config.craftingMonitorUsage;
|
||||||
|
|||||||
@@ -6,6 +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.tile.ClientNode;
|
import refinedstorage.tile.ClientNode;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -44,6 +45,36 @@ public final class RefinedStorageSerializers {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static final DataSerializer<List<ClientCraftingTask>> CLIENT_CRAFTING_TASK_SERIALIZER = new DataSerializer<List<ClientCraftingTask>>() {
|
||||||
|
@Override
|
||||||
|
public void write(PacketBuffer buf, List<ClientCraftingTask> tasks) {
|
||||||
|
buf.writeInt(tasks.size());
|
||||||
|
|
||||||
|
for (ClientCraftingTask task : tasks) {
|
||||||
|
ByteBufUtils.writeItemStack(buf, task.getOutput());
|
||||||
|
buf.writeInt(task.getQuantity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ClientCraftingTask> read(PacketBuffer buf) {
|
||||||
|
List<ClientCraftingTask> tasks = new ArrayList<>();
|
||||||
|
|
||||||
|
int size = buf.readInt();
|
||||||
|
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
tasks.add(new ClientCraftingTask(ByteBufUtils.readItemStack(buf), buf.readInt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataParameter<List<ClientCraftingTask>> createKey(int id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static final DataSerializer<FluidStack> FLUID_STACK_SERIALIZER = new DataSerializer<FluidStack>() {
|
public static final DataSerializer<FluidStack> FLUID_STACK_SERIALIZER = new DataSerializer<FluidStack>() {
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketBuffer buf, FluidStack value) {
|
public void write(PacketBuffer buf, FluidStack value) {
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.8 KiB |
Reference in New Issue
Block a user