diff --git a/src/main/java/appeng/crafting/CraftingTreeNode.java b/src/main/java/appeng/crafting/CraftingTreeNode.java index 2cc3313cb..25039036f 100644 --- a/src/main/java/appeng/crafting/CraftingTreeNode.java +++ b/src/main/java/appeng/crafting/CraftingTreeNode.java @@ -145,14 +145,6 @@ public class CraftingTreeNode this.what.setStackSize( l ); - if( parent != null ) - { - if( this.what.equals( job.getOutput() ) ) - { - job.getNeededForLoop().add( this.what.copy() ); - } - } - if( this.getSlot() >= 0 && this.parent != null && this.parent.details.isCraftable() ) { Collection itemList = new ArrayList<>(); diff --git a/src/main/java/appeng/crafting/CraftingTreeProcess.java b/src/main/java/appeng/crafting/CraftingTreeProcess.java index d0d9a1cdd..b5a18b981 100644 --- a/src/main/java/appeng/crafting/CraftingTreeProcess.java +++ b/src/main/java/appeng/crafting/CraftingTreeProcess.java @@ -170,6 +170,11 @@ public class CraftingTreeProcess { final IAEItemStack stack = entry.getKey().request( inv, hasContainerItem ? 1 : entry.getValue(), src ); + if( stack.equals( job.getOutput() ) ) + { + job.getNeededForLoop().add( stack.copy() ); + } + if( stack.getItem().hasContainerItem( stack.getDefinition() ) ) { final ItemStack is = Platform.getContainerItem( stack.createItemStack() ); diff --git a/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java index ae57be47c..47aad499f 100644 --- a/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java +++ b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java @@ -287,17 +287,28 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU if( this.finalOutput.equals( what ) ) { - IAEItemStack isLoop = neededForLoop.findPrecise( finalOutput ); - if( isLoop != null && isLoop.getStackSize() > 0 ) - { - isLoop.decStackSize( what.getStackSize() ); - return this.inventory.injectItems( what, type, src ); - } - IAEItemStack leftover = what; - this.finalOutput.decStackSize( what.getStackSize() ); + if( isLoop != null && isLoop.getStackSize() > 0 ) + { + if( isLoop.getStackSize() >= what.getStackSize() ) + { + leftover = this.inventory.injectItems( what.copy(), type, src ); + isLoop.decStackSize( what.getStackSize() ); + } + else + { + leftover = this.inventory.injectItems( what.copy().setStackSize( what.getStackSize() - isLoop.getStackSize() ), type, src ); + isLoop.decStackSize( what.getStackSize() - isLoop.getStackSize() ); + } + if( leftover == null ) + { + return null; + } + } + + this.finalOutput.decStackSize( leftover.getStackSize() ); if( this.myLastLink != null ) { @@ -327,17 +338,28 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU if( this.finalOutput.equals( insert ) ) { - IAEItemStack isLoop = neededForLoop.findPrecise( finalOutput ); - if( isLoop != null && isLoop.getStackSize() > 0 ) - { - isLoop.decStackSize( insert.getStackSize() ); - return this.inventory.injectItems( insert, type, src ); - } - IAEItemStack leftover = input; - this.finalOutput.decStackSize( insert.getStackSize() ); + if( isLoop != null && isLoop.getStackSize() > 0 ) + { + if( isLoop.getStackSize() >= insert.getStackSize() ) + { + leftover = this.inventory.injectItems( insert.copy(), type, src ); + isLoop.decStackSize( insert.getStackSize() ); + } + else + { + leftover = this.inventory.injectItems( insert.copy().setStackSize( insert.getStackSize() - isLoop.getStackSize() ), type, src ); + isLoop.decStackSize( insert.getStackSize() - isLoop.getStackSize() ); + } + if( leftover == null ) + { + return null; + } + } + + this.finalOutput.decStackSize( leftover.getStackSize() ); if( this.myLastLink != null ) {