diff --git a/crafting/CraftingJob.java b/crafting/CraftingJob.java index aef1ec4f9..4709e9d94 100644 --- a/crafting/CraftingJob.java +++ b/crafting/CraftingJob.java @@ -55,6 +55,11 @@ public class CraftingJob implements Runnable, ICraftingJob availableCheck = null; } + public void refund(IAEItemStack o) + { + availableCheck.injectItems( o, Actionable.MODULATE, this.actionSrc ); + } + public IAEItemStack checkUse(IAEItemStack available) { return availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc ); diff --git a/crafting/CraftingTreeNode.java b/crafting/CraftingTreeNode.java index 984e14e07..6b1edddd1 100644 --- a/crafting/CraftingTreeNode.java +++ b/crafting/CraftingTreeNode.java @@ -1,6 +1,8 @@ package appeng.crafting; import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; import net.minecraft.world.World; import appeng.api.AEApi; @@ -83,6 +85,8 @@ public class CraftingTreeNode { job.handlepausing(); + List thingsUsed = new LinkedList(); + what.setStackSize( l ); if ( slot >= 0 && parent != null && parent.details.isCraftable() ) { @@ -97,7 +101,11 @@ public class CraftingTreeNode if ( available != null ) { if ( !exhausted ) - used.add( job.checkUse( available ) ); + { + IAEItemStack is = job.checkUse( available ); + thingsUsed.add( is.copy() ); + used.add( is ); + } bytes += available.getStackSize(); l -= available.getStackSize(); @@ -115,7 +123,11 @@ public class CraftingTreeNode if ( available != null ) { if ( !exhausted ) - used.add( job.checkUse( available ) ); + { + IAEItemStack is = job.checkUse( available ); + thingsUsed.add( is.copy() ); + used.add( is ); + } bytes += available.getStackSize(); l -= available.getStackSize(); @@ -160,13 +172,14 @@ public class CraftingTreeNode { MECraftingInventory subInv = new MECraftingInventory( inv, true, true, true ); pro.request( subInv, 1, src ); - subInv.commit( src ); what.setStackSize( l ); - IAEItemStack available = inv.extractItems( what, Actionable.MODULATE, src ); + IAEItemStack available = subInv.extractItems( what, Actionable.MODULATE, src ); if ( available != null ) { + subInv.commit( src ); + bytes += available.getStackSize(); l -= available.getStackSize(); @@ -193,6 +206,13 @@ public class CraftingTreeNode return rv; } + for (IAEItemStack o : thingsUsed) + { + job.refund( o.copy() ); + o.setStackSize( -o.getStackSize() ); + used.add( o ); + } + throw new CraftBranchFailure( what, l ); }