diff --git a/crafting/CraftingTreeNode.java b/crafting/CraftingTreeNode.java index 1d07cf3c9..55dbe6129 100644 --- a/crafting/CraftingTreeNode.java +++ b/crafting/CraftingTreeNode.java @@ -44,7 +44,8 @@ public class CraftingTreeNode boolean sim; - public CraftingTreeNode(ICraftingGrid cc, CraftingJob job, IAEItemStack wat, CraftingTreeProcess par, int slot, int depth) { + public CraftingTreeNode(ICraftingGrid cc, CraftingJob job, IAEItemStack wat, CraftingTreeProcess par, int slot, int depth) + { what = wat; parent = par; this.slot = slot; @@ -206,7 +207,8 @@ public class CraftingTreeNode if ( available != null ) { - subInv.commit( src ); + if ( !subInv.commit( src ) ) + throw new CraftBranchFailure( what, l ); bytes += available.getStackSize(); l -= available.getStackSize(); diff --git a/crafting/MECraftingInventory.java b/crafting/MECraftingInventory.java index c44c465ae..edb418fc0 100644 --- a/crafting/MECraftingInventory.java +++ b/crafting/MECraftingInventory.java @@ -153,18 +153,59 @@ public class MECraftingInventory implements IMEInventory return StorageChannel.ITEMS; } - public void commit(BaseActionSource src) + public boolean commit(BaseActionSource src) { + IItemList added = AEApi.instance().storage().createItemList(); + IItemList pulled = AEApi.instance().storage().createItemList(); + boolean failed = false; + + if ( logExtracted ) + { + for (IAEItemStack extra : extractedCache) + { + IAEItemStack result = null; + pulled.add( result = target.extractItems( extra, Actionable.MODULATE, src ) ); + + if ( result == null || result.getStackSize() != extra.getStackSize() ) + { + failed = true; + break; + } + } + } + + if ( failed ) + { + for (IAEItemStack is : pulled) + target.injectItems( is, Actionable.MODULATE, src ); + + return false; + } + if ( logInjections ) { for (IAEItemStack injec : injectedCache) - target.injectItems( injec, Actionable.MODULATE, src ); + { + IAEItemStack result = null; + added.add( result = target.injectItems( injec, Actionable.MODULATE, src ) ); + + if ( result != null ) + { + failed = true; + break; + } + } } - if ( logExtracted ) + if ( failed ) { - for (IAEItemStack extra : extractedCache) - target.extractItems( extra, Actionable.MODULATE, src ); + for (IAEItemStack is : added) + target.extractItems( is, Actionable.MODULATE, src ); + + for (IAEItemStack is : pulled) + target.injectItems( is, Actionable.MODULATE, src ); + + return false; } if ( logMissing && par != null ) @@ -172,6 +213,8 @@ public class MECraftingInventory implements IMEInventory for (IAEItemStack extra : missingCache) par.addMissing( extra ); } + + return true; } public void addMissing(IAEItemStack extra) diff --git a/me/cluster/implementations/CraftingCPUCluster.java b/me/cluster/implementations/CraftingCPUCluster.java index 8eaa87d3b..030b0fd2e 100644 --- a/me/cluster/implementations/CraftingCPUCluster.java +++ b/me/cluster/implementations/CraftingCPUCluster.java @@ -198,7 +198,8 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU return inventory; } - public CraftingCPUCluster(WorldCoord _min, WorldCoord _max) { + public CraftingCPUCluster(WorldCoord _min, WorldCoord _max) + { min = _min; max = _max; } @@ -786,32 +787,39 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU { waitingFor.resetStatus(); ((CraftingJob) job).tree.setJob( ci, this, src ); - ci.commit( src ); - finalOutput = job.getOutput(); - waiting = false; - isComplete = false; - markDirty(); + if ( ci.commit( src ) ) + { + finalOutput = job.getOutput(); + waiting = false; + isComplete = false; + markDirty(); - updateCPU(); - String craftID = generateCraftingID(); + updateCPU(); + String craftID = generateCraftingID(); - myLastLink = new CraftingLink( generateLinkData( craftID, requestingMachine == null, false ), this ); + myLastLink = new CraftingLink( generateLinkData( craftID, requestingMachine == null, false ), this ); - if ( requestingMachine == null ) - return myLastLink; + if ( requestingMachine == null ) + return myLastLink; - ICraftingLink whatLink = new CraftingLink( generateLinkData( craftID, requestingMachine == null, true ), requestingMachine ); + ICraftingLink whatLink = new CraftingLink( generateLinkData( craftID, requestingMachine == null, true ), requestingMachine ); - submitLink( myLastLink ); - submitLink( whatLink ); + submitLink( myLastLink ); + submitLink( whatLink ); - IItemList list; - getListOfItem( list = AEApi.instance().storage().createItemList(), CraftingItemList.ALL ); + IItemList list; + getListOfItem( list = AEApi.instance().storage().createItemList(), CraftingItemList.ALL ); - for (IAEItemStack ge : list) - postChange( ge, machineSrc ); + for (IAEItemStack ge : list) + postChange( ge, machineSrc ); - return whatLink; + return whatLink; + } + else + { + tasks.clear(); + inventory.getItemList().resetStatus(); + } } catch (CraftBranchFailure e) {