Make crafting monitor semi-functional again

This commit is contained in:
Raoul Van den Berge
2016-10-06 14:12:36 +02:00
parent af06c44b1e
commit 33053dbddb
9 changed files with 118 additions and 66 deletions

View File

@@ -60,7 +60,6 @@ public interface IItemGridHandler {
* Called when a player wants to cancel a crafting task.
*
* @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);
}

View File

@@ -6,6 +6,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import refinedstorage.RefinedStorage;
import refinedstorage.api.autocrafting.task.ICraftingTask;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.api.network.grid.IItemGridHandler;
@@ -162,30 +163,13 @@ public class ItemGridHandler implements IItemGridHandler {
}
@Override
public void onCraftingCancelRequested(int id, int depth) {
/*if (id >= 0 && id < network.getCraftingTasks().size()) {
ICraftingTask task = 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);
}
}
public void onCraftingCancelRequested(int id) {
if (id >= 0 && id < network.getCraftingTasks().size()) {
network.cancelCraftingTask(network.getCraftingTasks().get(id));
} else if (id == -1) {
for (ICraftingTask task : network.getCraftingTasks()) {
network.cancelCraftingTask(task);
}
}*/
}
}
}

View File

@@ -1,15 +1,16 @@
package refinedstorage.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import refinedstorage.RefinedStorage;
import refinedstorage.container.ContainerCraftingMonitor;
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
import refinedstorage.network.MessageCraftingMonitorCancel;
import refinedstorage.tile.ClientCraftingTask;
import refinedstorage.tile.TileCraftingMonitor;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
public class GuiCraftingMonitor extends GuiBase {
@@ -46,8 +47,8 @@ public class GuiCraftingMonitor extends GuiBase {
int cancelButtonWidth = 14 + fontRendererObj.getStringWidth(cancel);
int cancelAllButtonWidth = 14 + fontRendererObj.getStringWidth(cancelAll);
cancelButton = addButton(x + 7, y + 114, cancelButtonWidth, 20, cancel, false);
cancelAllButton = addButton(x + 7 + cancelButtonWidth + 4, y + 114, cancelAllButtonWidth, 20, cancelAll, false);
cancelButton = addButton(x + 7, y + 113, cancelButtonWidth, 20, cancel, false);
cancelAllButton = addButton(x + 7 + cancelButtonWidth + 4, y + 113, cancelAllButtonWidth, 20, cancelAll, false);
}
@Override
@@ -83,8 +84,6 @@ public class GuiCraftingMonitor extends GuiBase {
RenderHelper.enableGUIStandardItemLighting();
String[] lines = null;
int ox = 8;
int x = ox;
int y = 20;
@@ -92,7 +91,7 @@ public class GuiCraftingMonitor extends GuiBase {
itemSelectedX = -1;
itemSelectedY = -1;
/*for (int i = 0; i < VISIBLE_ROWS; ++i) {
for (int i = 0; i < VISIBLE_ROWS; ++i) {
if (item < getTasks().size()) {
ClientCraftingTask task = getTasks().get(item);
@@ -101,9 +100,9 @@ public class GuiCraftingMonitor extends GuiBase {
itemSelectedY = y;
}
if (task.getDepth() > 0) {
/*if (task.getDepth() > 0) {
x += 16F - ((float) (task.getChildren() - task.getDepth()) / (float) task.getChildren() * 16F);
}
}*/
drawItem(x + 2, y + 1, task.getOutput());
@@ -112,15 +111,15 @@ public class GuiCraftingMonitor extends GuiBase {
GlStateManager.pushMatrix();
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() + "%");
}
}*/
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");
for (int j = 0; j < lines.length; ++j) {
@@ -136,7 +135,7 @@ public class GuiCraftingMonitor extends GuiBase {
lines[j] = line;
}
}
}*/
x = ox;
y += ITEM_HEIGHT;
@@ -144,10 +143,6 @@ public class GuiCraftingMonitor extends GuiBase {
item++;
}
if (lines != null) {
drawTooltip(mouseX, mouseY, Arrays.asList(lines));
}*/
}
private int getRows() {
@@ -159,11 +154,9 @@ public class GuiCraftingMonitor extends GuiBase {
super.actionPerformed(button);
if (button == cancelButton && itemSelected != -1) {
/*ClientCraftingTask task = getTasks().get(itemSelected);
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, task.getId(), task.getDepth()));*/
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, itemSelected));
} 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() {
return Collections.emptyList();
private List<ClientCraftingTask> getTasks() {
return TileCraftingMonitor.TASKS.getValue();
}
}

View File

@@ -17,12 +17,11 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
public MessageCraftingMonitorCancel() {
}
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id, int depth) {
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id) {
this.x = craftingMonitor.getPos().getX();
this.y = craftingMonitor.getPos().getY();
this.z = craftingMonitor.getPos().getZ();
this.id = id;
this.depth = depth;
}
@Override
@@ -31,7 +30,6 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
y = buf.readInt();
z = buf.readInt();
id = buf.readInt();
depth = buf.readInt();
}
@Override
@@ -40,7 +38,6 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
buf.writeInt(y);
buf.writeInt(z);
buf.writeInt(id);
buf.writeInt(depth);
}
@Override
@@ -51,7 +48,7 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
TileCraftingMonitor monitor = (TileCraftingMonitor) tile;
if (monitor.isConnected()) {
monitor.getNetwork().getItemGridHandler().onCraftingCancelRequested(message.id, message.depth);
monitor.getNetwork().getItemGridHandler().onCraftingCancelRequested(message.id);
}
}
}

View 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;
}
}

View File

@@ -322,7 +322,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
public void updateCraftingMonitors() {
for (INetworkNode node : nodeGraph.all()) {
if (node instanceof TileCraftingMonitor) {
//((TileCraftingMonitor) node).dataManager.sendParameterToWatchers(TileCraftingMonitor.TASKS);
((TileCraftingMonitor) node).dataManager.sendParameterToWatchers(TileCraftingMonitor.TASKS);
}
}
}

View File

@@ -1,8 +1,35 @@
package refinedstorage.tile;
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 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
public int getEnergyUsage() {
return RefinedStorage.INSTANCE.config.craftingMonitorUsage;

View File

@@ -6,6 +6,7 @@ import net.minecraft.network.datasync.DataSerializer;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import refinedstorage.tile.ClientCraftingTask;
import refinedstorage.tile.ClientNode;
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>() {
@Override
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