Crafting stuff improvements
This commit is contained in:
@@ -98,6 +98,11 @@ public interface INetworkMaster {
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -52,7 +52,7 @@ public interface IItemGridHandler {
|
||||
* Called when a player wants to cancel a crafting task.
|
||||
*
|
||||
* @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;
|
||||
|
||||
took.add(received);
|
||||
|
||||
network.updateCraftingTasks();
|
||||
} else if (!childrenCreated[i]) {
|
||||
ICraftingPattern pattern = NetworkUtils.getPattern(network, input);
|
||||
|
||||
@@ -65,6 +67,8 @@ public class CraftingTaskNormal extends CraftingTask {
|
||||
|
||||
childrenCreated[i] = true;
|
||||
|
||||
network.updateCraftingTasks();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,15 +142,26 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftingCancelRequested(int id, boolean child) {
|
||||
public void onCraftingCancelRequested(int id, int depth) {
|
||||
if (id >= 0 && id < network.getCraftingTasks().size()) {
|
||||
ICraftingTask task = network.getCraftingTasks().get(id);
|
||||
|
||||
if (child) {
|
||||
task.getChild().onCancelled(network);
|
||||
task.setChild(null);
|
||||
} else {
|
||||
if (depth == 0) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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 z;
|
||||
private int id;
|
||||
private boolean child;
|
||||
private int depth;
|
||||
|
||||
public MessageCraftingMonitorCancel() {
|
||||
}
|
||||
|
||||
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id, boolean child) {
|
||||
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id, int depth) {
|
||||
this.x = craftingMonitor.getPos().getX();
|
||||
this.y = craftingMonitor.getPos().getY();
|
||||
this.z = craftingMonitor.getPos().getZ();
|
||||
this.id = id;
|
||||
this.child = child;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,7 +31,7 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
id = buf.readInt();
|
||||
child = buf.readBoolean();
|
||||
depth = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,7 +40,7 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeInt(id);
|
||||
buf.writeBoolean(child);
|
||||
buf.writeInt(depth);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,7 +51,7 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
|
||||
TileCraftingMonitor monitor = (TileCraftingMonitor) tile;
|
||||
|
||||
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 {
|
||||
private ItemStack output;
|
||||
private int id;
|
||||
private boolean isChild;
|
||||
private String status;
|
||||
private int depth;
|
||||
|
||||
// Used server-side while sending
|
||||
private ItemStack[] outputs;
|
||||
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.id = id;
|
||||
this.status = status;
|
||||
this.isChild = isChild;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public ClientCraftingTask(String status, ItemStack[] outputs, ICraftingTask child) {
|
||||
@@ -46,7 +46,7 @@ public class ClientCraftingTask {
|
||||
return child;
|
||||
}
|
||||
|
||||
public boolean isChild() {
|
||||
return isChild;
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,17 +261,19 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
Iterator<ICraftingTask> craftingTaskIterator = craftingTasks.iterator();
|
||||
|
||||
while (craftingTaskIterator.hasNext()) {
|
||||
craftingTasksChanged = true;
|
||||
|
||||
ICraftingTask task = craftingTaskIterator.next();
|
||||
|
||||
if (task.getChild() != null) {
|
||||
if (updateCraftingTask(task.getChild())) {
|
||||
task.setChild(null);
|
||||
|
||||
craftingTasksChanged = true;
|
||||
}
|
||||
} else {
|
||||
if (updateCraftingTask(task)) {
|
||||
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);
|
||||
}
|
||||
|
||||
private void updateCraftingTasks() {
|
||||
@Override
|
||||
public void updateCraftingTasks() {
|
||||
markDirty();
|
||||
|
||||
for (INetworkNode node : nodeGraph.all()) {
|
||||
|
||||
@@ -80,7 +80,7 @@ public final class RefinedStorageSerializers {
|
||||
List<ClientCraftingTask> tasks = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
readTask(buf, i, false, tasks);
|
||||
readTask(buf, i, 0, tasks);
|
||||
}
|
||||
|
||||
Collections.reverse(tasks);
|
||||
@@ -88,17 +88,17 @@ public final class RefinedStorageSerializers {
|
||||
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);
|
||||
|
||||
int outputs = buf.readInt();
|
||||
|
||||
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()) {
|
||||
readTask(buf, i, true, tasks);
|
||||
readTask(buf, i, depth + 1, tasks);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user