Save child task
This commit is contained in:
@@ -39,6 +39,8 @@ public class CraftingTaskFactoryNormal implements ICraftingTaskFactory {
|
||||
}
|
||||
|
||||
task.setTook(took);
|
||||
|
||||
task.readChildNBT(tag);
|
||||
}
|
||||
|
||||
return task;
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package refinedstorage.apiimpl.autocrafting.task;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.tile.TileController;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class CraftingTask implements ICraftingTask {
|
||||
private static final String NBT_CHILD = "Child";
|
||||
|
||||
protected ICraftingTask child;
|
||||
|
||||
@Override
|
||||
@@ -25,4 +29,19 @@ public abstract class CraftingTask implements ICraftingTask {
|
||||
child.onCancelled(network);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
if (child != null) {
|
||||
tag.setTag(NBT_CHILD, child.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void readChildNBT(NBTTagCompound tag) {
|
||||
if (tag.hasKey(NBT_CHILD)) {
|
||||
child = TileController.readCraftingTask(tag.getCompoundTag(NBT_CHILD));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,8 @@ public class CraftingTaskNormal extends CraftingTask {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
writeBooleanArray(tag, NBT_SATISFIED, satisfied);
|
||||
writeBooleanArray(tag, NBT_CHILDREN, childrenCreated);
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
public static final String NBT_ENERGY_CAPACITY = "EnergyCapacity";
|
||||
|
||||
private static final String NBT_CRAFTING_TASKS = "CraftingTasks";
|
||||
private static final String NBT_CRAFTING_TASK_TYPE = "Type";
|
||||
public static final String NBT_CRAFTING_TASK_TYPE = "Type";
|
||||
|
||||
private static final Comparator<IItemStorage> ITEM_SIZE_COMPARATOR = (left, right) -> {
|
||||
if (left.getStored() == right.getStored()) {
|
||||
@@ -692,25 +692,33 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
NBTTagList taskList = tag.getTagList(NBT_CRAFTING_TASKS, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < taskList.tagCount(); ++i) {
|
||||
NBTTagCompound taskTag = taskList.getCompoundTagAt(i);
|
||||
ICraftingTask task = readCraftingTask(taskList.getCompoundTagAt(i));
|
||||
|
||||
CraftingPattern pattern = CraftingPattern.readFromNBT(taskTag.getCompoundTag(CraftingPattern.NBT));
|
||||
|
||||
if (pattern != null) {
|
||||
ICraftingTaskFactory factory = RefinedStorageAPI.CRAFTING_TASK_REGISTRY.getFactory(taskTag.getString(NBT_CRAFTING_TASK_TYPE));
|
||||
|
||||
if (factory != null) {
|
||||
ICraftingTask task = factory.create(taskTag, pattern);
|
||||
|
||||
if (task != null) {
|
||||
addCraftingTask(task);
|
||||
}
|
||||
}
|
||||
if (task != null) {
|
||||
addCraftingTask(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ICraftingTask readCraftingTask(NBTTagCompound tag) {
|
||||
CraftingPattern pattern = CraftingPattern.readFromNBT(tag.getCompoundTag(CraftingPattern.NBT));
|
||||
|
||||
if (pattern != null) {
|
||||
ICraftingTaskFactory factory = RefinedStorageAPI.CRAFTING_TASK_REGISTRY.getFactory(tag.getString(NBT_CRAFTING_TASK_TYPE));
|
||||
|
||||
if (factory != null) {
|
||||
ICraftingTask task = factory.create(tag, pattern);
|
||||
|
||||
if (task != null) {
|
||||
return task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
Reference in New Issue
Block a user