Crafting stuff improvements
This commit is contained in:
@@ -98,6 +98,11 @@ public interface INetworkMaster {
|
|||||||
*/
|
*/
|
||||||
void cancelCraftingTask(@Nonnull ICraftingTask task);
|
void cancelCraftingTask(@Nonnull ICraftingTask task);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a sync packet to all crafting monitors with the crafting task status.
|
||||||
|
*/
|
||||||
|
void updateCraftingTasks();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A list of crafting patterns in this network, do NOT modify this list
|
* @return A list of crafting patterns in this network, do NOT modify this list
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ 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
|
* @param depth The child depth of this task to cancel
|
||||||
*/
|
*/
|
||||||
void onCraftingCancelRequested(int id, boolean child);
|
void onCraftingCancelRequested(int id, int depth);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ public class CraftingTaskNormal extends CraftingTask {
|
|||||||
satisfied[i] = true;
|
satisfied[i] = true;
|
||||||
|
|
||||||
took.add(received);
|
took.add(received);
|
||||||
|
|
||||||
|
network.updateCraftingTasks();
|
||||||
} else if (!childrenCreated[i]) {
|
} else if (!childrenCreated[i]) {
|
||||||
ICraftingPattern pattern = NetworkUtils.getPattern(network, input);
|
ICraftingPattern pattern = NetworkUtils.getPattern(network, input);
|
||||||
|
|
||||||
@@ -65,6 +67,8 @@ public class CraftingTaskNormal extends CraftingTask {
|
|||||||
|
|
||||||
childrenCreated[i] = true;
|
childrenCreated[i] = true;
|
||||||
|
|
||||||
|
network.updateCraftingTasks();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,15 +142,26 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingCancelRequested(int id, boolean child) {
|
public void onCraftingCancelRequested(int id, int depth) {
|
||||||
if (id >= 0 && id < network.getCraftingTasks().size()) {
|
if (id >= 0 && id < network.getCraftingTasks().size()) {
|
||||||
ICraftingTask task = network.getCraftingTasks().get(id);
|
ICraftingTask task = network.getCraftingTasks().get(id);
|
||||||
|
|
||||||
if (child) {
|
if (depth == 0) {
|
||||||
task.getChild().onCancelled(network);
|
|
||||||
task.setChild(null);
|
|
||||||
} else {
|
|
||||||
network.cancelCraftingTask(task);
|
network.cancelCraftingTask(task);
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < depth; ++i) {
|
||||||
|
if (task == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
task = task.getChild();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (task != null) {
|
||||||
|
cancelCraftingTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
network.updateCraftingTasks();
|
||||||
}
|
}
|
||||||
} else if (id == -1) {
|
} else if (id == -1) {
|
||||||
for (ICraftingTask task : network.getCraftingTasks()) {
|
for (ICraftingTask task : network.getCraftingTasks()) {
|
||||||
@@ -158,4 +169,15 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: Broken!
|
||||||
|
private void cancelCraftingTask(ICraftingTask task) {
|
||||||
|
task.onCancelled(network);
|
||||||
|
|
||||||
|
if (task.getChild() != null) {
|
||||||
|
cancelCraftingTask(task.getChild());
|
||||||
|
|
||||||
|
task.setChild(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,9 +158,9 @@ public class GuiCraftingMonitor extends GuiBase {
|
|||||||
if (button == cancelButton && itemSelected != -1) {
|
if (button == cancelButton && itemSelected != -1) {
|
||||||
ClientCraftingTask task = getTasks().get(itemSelected);
|
ClientCraftingTask task = getTasks().get(itemSelected);
|
||||||
|
|
||||||
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, task.getId(), task.isChild()));
|
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, false));
|
RefinedStorage.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, -1, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,17 +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;
|
private int depth;
|
||||||
|
|
||||||
public MessageCraftingMonitorCancel() {
|
public MessageCraftingMonitorCancel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id, boolean child) {
|
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id, int depth) {
|
||||||
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;
|
this.depth = depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -31,7 +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();
|
depth = buf.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,7 +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);
|
buf.writeInt(depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,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, message.child);
|
monitor.getNetwork().getItemGridHandler().onCraftingCancelRequested(message.id, message.depth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,18 +6,18 @@ 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;
|
||||||
|
private int depth;
|
||||||
|
|
||||||
// Used server-side while sending
|
// Used server-side while sending
|
||||||
private ItemStack[] outputs;
|
private ItemStack[] outputs;
|
||||||
private ClientCraftingTask child;
|
private ClientCraftingTask child;
|
||||||
|
|
||||||
public ClientCraftingTask(ItemStack output, int id, String status, boolean isChild) {
|
public ClientCraftingTask(ItemStack output, int id, String status, int depth) {
|
||||||
this.output = output;
|
this.output = output;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.isChild = isChild;
|
this.depth = depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientCraftingTask(String status, ItemStack[] outputs, ICraftingTask child) {
|
public ClientCraftingTask(String status, ItemStack[] outputs, ICraftingTask child) {
|
||||||
@@ -46,7 +46,7 @@ public class ClientCraftingTask {
|
|||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isChild() {
|
public int getDepth() {
|
||||||
return isChild;
|
return depth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,17 +261,19 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
Iterator<ICraftingTask> craftingTaskIterator = craftingTasks.iterator();
|
Iterator<ICraftingTask> craftingTaskIterator = craftingTasks.iterator();
|
||||||
|
|
||||||
while (craftingTaskIterator.hasNext()) {
|
while (craftingTaskIterator.hasNext()) {
|
||||||
craftingTasksChanged = true;
|
|
||||||
|
|
||||||
ICraftingTask task = craftingTaskIterator.next();
|
ICraftingTask task = craftingTaskIterator.next();
|
||||||
|
|
||||||
if (task.getChild() != null) {
|
if (task.getChild() != null) {
|
||||||
if (updateCraftingTask(task.getChild())) {
|
if (updateCraftingTask(task.getChild())) {
|
||||||
task.setChild(null);
|
task.setChild(null);
|
||||||
|
|
||||||
|
craftingTasksChanged = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (updateCraftingTask(task)) {
|
if (updateCraftingTask(task)) {
|
||||||
craftingTaskIterator.remove();
|
craftingTaskIterator.remove();
|
||||||
|
|
||||||
|
craftingTasksChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -323,7 +325,8 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
return container != null && ticks % container.getSpeed() == 0 && task.update(worldObj, this);
|
return container != null && ticks % container.getSpeed() == 0 && task.update(worldObj, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCraftingTasks() {
|
@Override
|
||||||
|
public void updateCraftingTasks() {
|
||||||
markDirty();
|
markDirty();
|
||||||
|
|
||||||
for (INetworkNode node : nodeGraph.all()) {
|
for (INetworkNode node : nodeGraph.all()) {
|
||||||
|
|||||||
@@ -80,7 +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) {
|
||||||
readTask(buf, i, false, tasks);
|
readTask(buf, i, 0, tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.reverse(tasks);
|
Collections.reverse(tasks);
|
||||||
@@ -88,17 +88,17 @@ public final class RefinedStorageSerializers {
|
|||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readTask(PacketBuffer buf, int i, boolean isChild, List<ClientCraftingTask> tasks) {
|
private void readTask(PacketBuffer buf, int i, int depth, List<ClientCraftingTask> tasks) {
|
||||||
String status = ByteBufUtils.readUTF8String(buf);
|
String status = ByteBufUtils.readUTF8String(buf);
|
||||||
|
|
||||||
int outputs = buf.readInt();
|
int outputs = buf.readInt();
|
||||||
|
|
||||||
for (int j = 0; j < outputs; ++j) {
|
for (int j = 0; j < outputs; ++j) {
|
||||||
tasks.add(new ClientCraftingTask(ByteBufUtils.readItemStack(buf), i, status, isChild));
|
tasks.add(new ClientCraftingTask(ByteBufUtils.readItemStack(buf), i, status, depth));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf.readBoolean()) {
|
if (buf.readBoolean()) {
|
||||||
readTask(buf, i, true, tasks);
|
readTask(buf, i, depth + 1, tasks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user