From d91b8b6cccc04a7d6c931b5d90b88f387407bd8b Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Tue, 1 Jul 2014 20:53:32 -0500 Subject: [PATCH] Working on Crafting CPU Save / Restore Logic --- .../CraftingCPUCalculator.java | 2 + .../implementations/CraftingCPUCluster.java | 199 ++++++++++++++---- 2 files changed, 162 insertions(+), 39 deletions(-) diff --git a/me/cluster/implementations/CraftingCPUCalculator.java b/me/cluster/implementations/CraftingCPUCalculator.java index 7b71eaaac..f4af98246 100644 --- a/me/cluster/implementations/CraftingCPUCalculator.java +++ b/me/cluster/implementations/CraftingCPUCalculator.java @@ -64,6 +64,8 @@ public class CraftingCPUCalculator extends MBCalculator } } + c.done(); + Iterator i = c.getTiles(); while (i.hasNext()) { diff --git a/me/cluster/implementations/CraftingCPUCluster.java b/me/cluster/implementations/CraftingCPUCluster.java index 56475fde6..1126639db 100644 --- a/me/cluster/implementations/CraftingCPUCluster.java +++ b/me/cluster/implementations/CraftingCPUCluster.java @@ -8,12 +8,15 @@ import java.util.Map.Entry; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; import appeng.api.config.PowerMultiplier; +import appeng.api.implementations.ICraftingPatternItem; import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; @@ -23,6 +26,7 @@ import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.networking.energy.IEnergyGrid; import appeng.api.networking.events.MENetworkCraftingCpuChange; import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.security.MachineSource; import appeng.api.networking.storage.IBaseMonitor; import appeng.api.networking.storage.IStorageGrid; import appeng.api.storage.IMEInventory; @@ -46,6 +50,36 @@ import cpw.mods.fml.common.FMLCommonHandler; public class CraftingCPUCluster implements IAECluster, IBaseMonitor { + class TaskProgress + { + + long value; + + }; + + /** + * crafting job info + */ + MECraftingInventory inventory = new MECraftingInventory(); + IAEItemStack finalOutput; + + boolean waiting = false; + Map tasks = new HashMap(); + IItemList waitingFor = AEApi.instance().storage().createItemList(); + + // instance sate + private LinkedList tiles = new LinkedList(); + private LinkedList storage = new LinkedList(); + private LinkedList status = new LinkedList(); + + MachineSource machineSrc = null; + + int accelerator = 0; + public WorldCoord min; + public WorldCoord max; + public boolean isDestroyed = false; + private boolean isComplete = true; + private final HashMap, Object> listeners = new HashMap, Object>(); protected Iterator, Object>> getListeners() @@ -85,23 +119,6 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor tiles = new LinkedList(); - - int accelerator = 0; - private LinkedList storage = new LinkedList(); - private LinkedList status = new LinkedList(); - public void getListOfItem(IItemList list, CraftingItemList whichList) { switch (whichList) @@ -145,18 +162,6 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor tasks = new HashMap(); - IItemList waitingFor = AEApi.instance().storage().createItemList(); - @Override public Iterator getTiles() { @@ -205,6 +210,11 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor= input.getStackSize() ) { is.decStackSize( input.getStackSize() ); + markDirty(); // AELog.info( "Task: " + is.getStackSize() + " remaining : " + getRemainingTasks() + // " remaining : " @@ -279,6 +290,7 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor e : tasks.entrySet()) + { + NBTTagCompound item = writeItem( AEItemStack.create( e.getKey().getPattern() ) ); + item.setLong( "craftingProgress", e.getValue().value ); + list.appendTag( item ); + } + data.setTag( "tasks", list ); + + data.setTag( "waitingFor", writeList( waitingFor ) ); + } + + private IItemList readList(NBTTagList tag) + { + IItemList out = AEApi.instance().storage().createItemList(); + + for (int x = 0; x < tag.tagCount(); x++) + { + IAEItemStack ais = AEItemStack.loadItemStackFromNBT( tag.getCompoundTagAt( x ) ); + if ( ais != null ) + out.add( ais ); + } + + return out; + } + + private NBTTagList writeList(IItemList myList) + { + NBTTagList out = new NBTTagList(); + + for (IAEItemStack ais : myList) + out.appendTag( writeItem( ais ) ); + + return out; + } + + private NBTTagCompound writeItem(IAEItemStack finalOutput2) + { + NBTTagCompound out = new NBTTagCompound(); + + if ( finalOutput2 != null ) + finalOutput2.writeToNBT( out ); + + return out; + } + + public void done() + { + TileCraftingTile core = getCore(); + + core.isCoreBlock = true; + + if ( core.previousState != null ) + { + readFromNBT( core.previousState ); + core.previousState = null; + } + } + }