delay container item return when simulating crafting tree

This commit is contained in:
PrototypeTrousers
2022-03-04 21:30:26 -03:00
parent b3bfbd0b58
commit 993be652c9
4 changed files with 27 additions and 5 deletions
@@ -92,7 +92,7 @@ public class CraftingJob implements Runnable, ICraftingJob
final ICraftingGrid cc = grid.getCache( ICraftingGrid.class ); final ICraftingGrid cc = grid.getCache( ICraftingGrid.class );
final GridStorageCache sg = grid.getCache( IStorageGrid.class ); final GridStorageCache sg = grid.getCache( IStorageGrid.class );
this.original = new MECraftingInventory( sg.getExtractableList() ); this.original = new MECraftingInventory( sg.getExtractableList( actionSrc ) );
this.setTree( this.getCraftingTree( cc, what ) ); this.setTree( this.getCraftingTree( cc, what ) );
this.availableCheck = null; this.availableCheck = null;
@@ -199,6 +199,11 @@ public class CraftingTreeNode
final IAEItemStack available = inv.extractItems( madeWhat, Actionable.MODULATE, src ); final IAEItemStack available = inv.extractItems( madeWhat, Actionable.MODULATE, src );
for( IAEItemStack i : pro.getReturnedContainers() )
{
inv.injectItems( i, Actionable.MODULATE, src );
}
if( available != null ) if( available != null )
{ {
this.bytes += available.getStackSize(); this.bytes += available.getStackSize();
@@ -19,11 +19,16 @@
package appeng.crafting; package appeng.crafting;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import appeng.api.config.FuzzyMode; import appeng.api.config.FuzzyMode;
import appeng.util.item.AEItemStack; import appeng.util.item.AEItemStack;
import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.objects.Object2LongArrayMap; import it.unimi.dsi.fastutil.objects.Object2LongArrayMap;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
@@ -51,6 +56,7 @@ public class CraftingTreeProcess
private long crafts = 0; private long crafts = 0;
private IItemList<IAEItemStack> containerItems; private IItemList<IAEItemStack> containerItems;
private boolean limitQty; private boolean limitQty;
private List<IAEItemStack> containerItemsList;
private long bytes = 0; private long bytes = 0;
public CraftingTreeProcess( final ICraftingGrid cc, final CraftingJob job, final ICraftingPatternDetails details, final CraftingTreeNode craftingTreeNode, final int depth ) public CraftingTreeProcess( final ICraftingGrid cc, final CraftingJob job, final ICraftingPatternDetails details, final CraftingTreeNode craftingTreeNode, final int depth )
@@ -70,6 +76,7 @@ public class CraftingTreeProcess
if( containerItems == null ) if( containerItems == null )
{ {
containerItems = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList(); containerItems = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
containerItemsList = new ArrayList<>();
} }
containerItems.add( part ); containerItems.add( part );
this.limitQty = true; this.limitQty = true;
@@ -240,8 +247,9 @@ public class CraftingTreeProcess
part = part.copy(); part = part.copy();
// use the first slot... // use the first slot...
this.nodes.put( new CraftingTreeNode( cc, job, part, this, x, depth + 1 ), wantedSize ); this.nodes.put( new CraftingTreeNode( cc, job, part, this, x, depth + 1 ), wantedSize );
wantedSize = 0;
} }
if( !isPartContainer || wantedSize == 0 ) if( !isPartContainer && wantedSize == 0 )
{ {
break; break;
} }
@@ -298,7 +306,7 @@ public class CraftingTreeProcess
if( o != null ) if( o != null )
{ {
this.bytes++; this.bytes++;
inv.injectItems( o, Actionable.MODULATE, src ); containerItemsList.add( o );
} }
} }
} }
@@ -315,6 +323,15 @@ public class CraftingTreeProcess
this.crafts += amountOfTimes; this.crafts += amountOfTimes;
} }
public List<IAEItemStack> getReturnedContainers()
{
if( containerItemsList == null )
{
return Collections.emptyList();
}
return containerItemsList;
}
void dive( final CraftingJob job ) void dive( final CraftingJob job )
{ {
job.addTask( this.getAmountCrafted( this.parent.getStack( 1 ) ), this.crafts, this.details, this.depth ); job.addTask( this.getAmountCrafted( this.parent.getStack( 1 ) ), this.crafts, this.details, this.depth );
+2 -2
View File
@@ -173,11 +173,11 @@ public class GridStorageCache implements IStorageGrid
return (IMEMonitor<T>) this.storageMonitors.get( channel ); return (IMEMonitor<T>) this.storageMonitors.get( channel );
} }
public MECraftingInventory getExtractableList() public MECraftingInventory getExtractableList( IActionSource src )
{ {
if( localCache == null ) if( localCache == null )
{ {
localCache = new MECraftingInventory( getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), new BaseActionSource(), false, false, false ); localCache = new MECraftingInventory( getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), src, false, false, false );
} }
return localCache; return localCache;
} }