Fix crafting monitor to work with the new system
This commit is contained in:
@@ -5,6 +5,8 @@ import net.minecraft.world.World;
|
|||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a crafting task.
|
* Represents a crafting task.
|
||||||
*/
|
*/
|
||||||
@@ -17,12 +19,13 @@ public interface ICraftingTask {
|
|||||||
/**
|
/**
|
||||||
* @return The child task
|
* @return The child task
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
ICraftingTask getChild();
|
ICraftingTask getChild();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param child The child task
|
* @param child The child task
|
||||||
*/
|
*/
|
||||||
void setChild(ICraftingTask child);
|
void setChild(@Nullable ICraftingTask child);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world The world
|
* @param world The world
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ 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 for all tasks
|
* @param id The task ID, or -1 for all tasks
|
||||||
|
* @param child Whether to only cancel the child of this crafting task
|
||||||
*/
|
*/
|
||||||
void onCraftingCancelRequested(int id);
|
void onCraftingCancelRequested(int id, boolean child);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,19 @@ package refinedstorage.apiimpl.autocrafting.task;
|
|||||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public abstract class CraftingTask implements ICraftingTask {
|
public abstract class CraftingTask implements ICraftingTask {
|
||||||
protected ICraftingTask child;
|
protected ICraftingTask child;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public ICraftingTask getChild() {
|
public ICraftingTask getChild() {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setChild(ICraftingTask child) {
|
public void setChild(@Nullable ICraftingTask child) {
|
||||||
this.child = child;
|
this.child = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,9 +142,16 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingCancelRequested(int id) {
|
public void onCraftingCancelRequested(int id, boolean child) {
|
||||||
if (id >= 0 && id < network.getCraftingTasks().size()) {
|
if (id >= 0 && id < network.getCraftingTasks().size()) {
|
||||||
network.cancelCraftingTask(network.getCraftingTasks().get(id));
|
ICraftingTask task = network.getCraftingTasks().get(id);
|
||||||
|
|
||||||
|
if (child) {
|
||||||
|
task.getChild().onCancelled(network);
|
||||||
|
task.setChild(null);
|
||||||
|
} else {
|
||||||
|
network.cancelCraftingTask(task);
|
||||||
|
}
|
||||||
} else if (id == -1) {
|
} else if (id == -1) {
|
||||||
for (ICraftingTask task : network.getCraftingTasks()) {
|
for (ICraftingTask task : network.getCraftingTasks()) {
|
||||||
network.cancelCraftingTask(task);
|
network.cancelCraftingTask(task);
|
||||||
|
|||||||
@@ -156,9 +156,11 @@ 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, getTasks().get(itemSelected).getId()));
|
ClientCraftingTask task = getTasks().get(itemSelected);
|
||||||
|
|
||||||
|
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, task.getId(), task.isChild()));
|
||||||
} else if (button == cancelAllButton && getTasks().size() > 0) {
|
} else if (button == cancelAllButton && getTasks().size() > 0) {
|
||||||
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, -1));
|
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, -1, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,15 +12,17 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
|
|||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
private int id;
|
private int id;
|
||||||
|
private boolean child;
|
||||||
|
|
||||||
public MessageCraftingMonitorCancel() {
|
public MessageCraftingMonitorCancel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id) {
|
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id, boolean child) {
|
||||||
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.child = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -29,6 +31,7 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
|
|||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
id = buf.readInt();
|
id = buf.readInt();
|
||||||
|
child = buf.readBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -37,6 +40,7 @@ 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.writeBoolean(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -47,7 +51,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);
|
monitor.getNetwork().getItemGridHandler().onCraftingCancelRequested(message.id, message.child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,29 @@
|
|||||||
package refinedstorage.tile;
|
package refinedstorage.tile;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
|
|
||||||
public class ClientCraftingTask {
|
public class ClientCraftingTask {
|
||||||
private ItemStack output;
|
private ItemStack output;
|
||||||
private int id;
|
private int id;
|
||||||
|
private boolean isChild;
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
// Used server-side while sending
|
// Used server-side while sending
|
||||||
private ItemStack[] outputs;
|
private ItemStack[] outputs;
|
||||||
|
private ClientCraftingTask child;
|
||||||
|
|
||||||
public ClientCraftingTask(ItemStack output, int id, String status) {
|
public ClientCraftingTask(ItemStack output, int id, String status, boolean isChild) {
|
||||||
this.output = output;
|
this.output = output;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
this.isChild = isChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientCraftingTask(String status, ItemStack[] outputs) {
|
public ClientCraftingTask(String status, ItemStack[] outputs, ICraftingTask child) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.outputs = outputs;
|
this.outputs = outputs;
|
||||||
|
this.child = child != null ? new ClientCraftingTask(child.getStatus(), child.getPattern().getOutputs(), child.getChild()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getOutput() {
|
public ItemStack getOutput() {
|
||||||
@@ -36,4 +41,12 @@ public class ClientCraftingTask {
|
|||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ClientCraftingTask getChild() {
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isChild() {
|
||||||
|
return isChild;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ public class TileCraftingMonitor extends TileNode {
|
|||||||
if (tile.connected) {
|
if (tile.connected) {
|
||||||
List<ClientCraftingTask> tasks = tile.network.getCraftingTasks().stream().map(t -> new ClientCraftingTask(
|
List<ClientCraftingTask> tasks = tile.network.getCraftingTasks().stream().map(t -> new ClientCraftingTask(
|
||||||
t.getStatus(),
|
t.getStatus(),
|
||||||
t.getPattern().getOutputs()
|
t.getPattern().getOutputs(),
|
||||||
|
t.getChild()
|
||||||
)).collect(Collectors.toList());
|
)).collect(Collectors.toList());
|
||||||
|
|
||||||
return tasks;
|
return tasks;
|
||||||
|
|||||||
@@ -53,13 +53,23 @@ public final class RefinedStorageSerializers {
|
|||||||
buf.writeInt(tasks.size());
|
buf.writeInt(tasks.size());
|
||||||
|
|
||||||
for (ClientCraftingTask task : tasks) {
|
for (ClientCraftingTask task : tasks) {
|
||||||
ByteBufUtils.writeUTF8String(buf, task.getStatus());
|
writeTask(buf, task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buf.writeInt(task.getOutputs().length);
|
private void writeTask(PacketBuffer buf, ClientCraftingTask task) {
|
||||||
|
ByteBufUtils.writeUTF8String(buf, task.getStatus());
|
||||||
|
|
||||||
for (ItemStack output : task.getOutputs()) {
|
buf.writeInt(task.getOutputs().length);
|
||||||
ByteBufUtils.writeItemStack(buf, output);
|
|
||||||
}
|
for (ItemStack output : task.getOutputs()) {
|
||||||
|
ByteBufUtils.writeItemStack(buf, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.writeBoolean(task.getChild() != null);
|
||||||
|
|
||||||
|
if (task.getChild() != null) {
|
||||||
|
writeTask(buf, task.getChild());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,13 +80,7 @@ public final class RefinedStorageSerializers {
|
|||||||
List<ClientCraftingTask> tasks = new ArrayList<>();
|
List<ClientCraftingTask> tasks = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
String info = ByteBufUtils.readUTF8String(buf);
|
readTask(buf, i, false, tasks);
|
||||||
|
|
||||||
int outputs = buf.readInt();
|
|
||||||
|
|
||||||
for (int j = 0; j < outputs; ++j) {
|
|
||||||
tasks.add(new ClientCraftingTask(ByteBufUtils.readItemStack(buf), i, info));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.reverse(tasks);
|
Collections.reverse(tasks);
|
||||||
@@ -84,6 +88,20 @@ public final class RefinedStorageSerializers {
|
|||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void readTask(PacketBuffer buf, int i, boolean isChild, List<ClientCraftingTask> tasks) {
|
||||||
|
String status = ByteBufUtils.readUTF8String(buf);
|
||||||
|
|
||||||
|
int outputs = buf.readInt();
|
||||||
|
|
||||||
|
for (int j = 0; j < outputs; ++j) {
|
||||||
|
tasks.add(new ClientCraftingTask(ByteBufUtils.readItemStack(buf), i, status, isChild));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf.readBoolean()) {
|
||||||
|
readTask(buf, i, true, tasks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataParameter<List<ClientCraftingTask>> createKey(int id) {
|
public DataParameter<List<ClientCraftingTask>> createKey(int id) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user