Fix Crafting Dupe on Extraction, if extraction fails roll back and fail.

This commit is contained in:
AlgorithmX2 2014-09-18 20:30:26 -05:00
parent 2913d71acd
commit 73cda63a78
3 changed files with 79 additions and 26 deletions

View file

@ -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();

View file

@ -153,18 +153,59 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
return StorageChannel.ITEMS;
}
public void commit(BaseActionSource src)
public boolean commit(BaseActionSource src)
{
IItemList<IAEItemStack> added = AEApi.instance().storage().createItemList();
IItemList<IAEItemStack> 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<IAEItemStack>
for (IAEItemStack extra : missingCache)
par.addMissing( extra );
}
return true;
}
public void addMissing(IAEItemStack extra)

View file

@ -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<IAEItemStack> list;
getListOfItem( list = AEApi.instance().storage().createItemList(), CraftingItemList.ALL );
IItemList<IAEItemStack> 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)
{