Save child task
This commit is contained in:
		| @@ -39,6 +39,8 @@ public class CraftingTaskFactoryNormal implements ICraftingTaskFactory { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             task.setTook(took); |             task.setTook(took); | ||||||
|  |  | ||||||
|  |             task.readChildNBT(tag); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return task; |         return task; | ||||||
|   | |||||||
| @@ -1,11 +1,15 @@ | |||||||
| package refinedstorage.apiimpl.autocrafting.task; | package refinedstorage.apiimpl.autocrafting.task; | ||||||
|  |  | ||||||
|  | import net.minecraft.nbt.NBTTagCompound; | ||||||
| import refinedstorage.api.autocrafting.task.ICraftingTask; | import refinedstorage.api.autocrafting.task.ICraftingTask; | ||||||
| import refinedstorage.api.network.INetworkMaster; | import refinedstorage.api.network.INetworkMaster; | ||||||
|  | import refinedstorage.tile.TileController; | ||||||
|  |  | ||||||
| import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||||
|  |  | ||||||
| public abstract class CraftingTask implements ICraftingTask { | public abstract class CraftingTask implements ICraftingTask { | ||||||
|  |     private static final String NBT_CHILD = "Child"; | ||||||
|  |  | ||||||
|     protected ICraftingTask child; |     protected ICraftingTask child; | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @@ -25,4 +29,19 @@ public abstract class CraftingTask implements ICraftingTask { | |||||||
|             child.onCancelled(network); |             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 |     @Override | ||||||
|     public NBTTagCompound writeToNBT(NBTTagCompound tag) { |     public NBTTagCompound writeToNBT(NBTTagCompound tag) { | ||||||
|  |         super.writeToNBT(tag); | ||||||
|  |  | ||||||
|         writeBooleanArray(tag, NBT_SATISFIED, satisfied); |         writeBooleanArray(tag, NBT_SATISFIED, satisfied); | ||||||
|         writeBooleanArray(tag, NBT_CHILDREN, childrenCreated); |         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"; |     public static final String NBT_ENERGY_CAPACITY = "EnergyCapacity"; | ||||||
|  |  | ||||||
|     private static final String NBT_CRAFTING_TASKS = "CraftingTasks"; |     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) -> { |     private static final Comparator<IItemStorage> ITEM_SIZE_COMPARATOR = (left, right) -> { | ||||||
|         if (left.getStored() == right.getStored()) { |         if (left.getStored() == right.getStored()) { | ||||||
| @@ -692,15 +692,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR | |||||||
|             NBTTagList taskList = tag.getTagList(NBT_CRAFTING_TASKS, Constants.NBT.TAG_COMPOUND); |             NBTTagList taskList = tag.getTagList(NBT_CRAFTING_TASKS, Constants.NBT.TAG_COMPOUND); | ||||||
|  |  | ||||||
|             for (int i = 0; i < taskList.tagCount(); ++i) { |             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) { |                 if (task != null) { | ||||||
|                     addCraftingTask(task); |                     addCraftingTask(task); | ||||||
| @@ -708,8 +700,24 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     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 |     @Override | ||||||
|     public NBTTagCompound writeToNBT(NBTTagCompound tag) { |     public NBTTagCompound writeToNBT(NBTTagCompound tag) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Raoul Van den Berge
					Raoul Van den Berge