This commit is contained in:
PrototypeTrousers
2022-03-05 00:03:19 -03:00
parent 447c6debab
commit c532b9c839
3 changed files with 40 additions and 36 deletions
@@ -67,6 +67,7 @@ public class CraftingJob implements Runnable, ICraftingJob
private final Stopwatch craftingTreeWatch = Stopwatch.createUnstarted();
private CraftingTreeNode tree;
private final IAEItemStack output;
private long expectedOutput;
private boolean simulate = false;
private MECraftingInventory availableCheck;
private long bytes = 0;
@@ -98,6 +99,16 @@ public class CraftingJob implements Runnable, ICraftingJob
this.availableCheck = null;
}
public long getExpectedOutput()
{
return expectedOutput;
}
public void incExpectedOutput( long amount )
{
this.expectedOutput += amount;
}
private CraftingTreeNode getCraftingTree( final ICraftingGrid cc, final IAEItemStack what )
{
return new CraftingTreeNode( cc, this, what, null, -1, 0 );
@@ -24,7 +24,6 @@ import java.util.Collection;
import java.util.List;
import appeng.api.config.FuzzyMode;
import com.google.common.collect.Lists;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
@@ -80,7 +79,7 @@ public class CraftingTreeNode
for( final ICraftingPatternDetails details : cc.getCraftingFor( this.what, this.parent == null ? null : this.parent.details, slot, this.world ) )// in
// order.
{
if( this.parent == null || this.parent.notRecursive() )
if( this.parent == null || job.getExpectedOutput() < job.getOutput().getStackSize() )
{
this.nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1 ) );
}
@@ -199,11 +198,6 @@ public class CraftingTreeNode
final IAEItemStack available = inv.extractItems( madeWhat, Actionable.MODULATE, src );
for( IAEItemStack i : pro.getReturnedContainers() )
{
inv.injectItems( i, Actionable.MODULATE, src );
}
if( available != null )
{
this.bytes += available.getStackSize();
@@ -234,11 +228,6 @@ public class CraftingTreeNode
this.what.setStackSize( l );
final IAEItemStack available = subInv.extractItems( this.what, Actionable.MODULATE, src );
for( IAEItemStack i : pro.getReturnedContainers() )
{
inv.injectItems( i, Actionable.MODULATE, src );
}
if( available != null )
{
if( !subInv.commit( src ) )
@@ -286,11 +275,6 @@ public class CraftingTreeNode
throw new CraftBranchFailure( this.what, l );
}
boolean notRecursive()
{
return this.parent == null || job.getUniques().findPrecise( this.what ) == null;
}
void dive( final CraftingJob job )
{
if( this.missing > 0 )
@@ -20,21 +20,18 @@ 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 appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.util.item.AEItemStack;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.objects.Object2LongArrayMap;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.security.IActionSource;
@@ -56,7 +53,7 @@ public class CraftingTreeProcess
private long crafts = 0;
private IItemList<IAEItemStack> containerItems;
private boolean limitQty;
private List<IAEItemStack> containerItemsList;
private final List<IAEItemStack> craftingResultList = new ArrayList<>();
private long bytes = 0;
public CraftingTreeProcess( final ICraftingGrid cc, final CraftingJob job, final ICraftingPatternDetails details, final CraftingTreeNode craftingTreeNode, final int depth )
@@ -76,13 +73,28 @@ public class CraftingTreeProcess
if( containerItems == null )
{
containerItems = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
containerItemsList = new ArrayList<>();
}
containerItems.add( part );
this.limitQty = true;
//break;
}
}
for( final IAEItemStack part : details.getCondensedOutputs() )
{
if( part.equals( job.getOutput() ) )
{
job.incExpectedOutput( part.getStackSize() );
}
}
for( final IAEItemStack part : details.getCondensedInputs() )
{
if( part.equals( job.getOutput() ) )
{
job.incExpectedOutput( -part.getStackSize() );
}
}
// this is minor different then below, this slot uses the pattern, but kinda fudges it.
for( IAEItemStack part : details.getCondensedInputs() )
{
@@ -275,11 +287,6 @@ public class CraftingTreeProcess
return this.containerItems;
}
boolean notRecursive()
{
return this.parent == null || this.parent.notRecursive();
}
long getTimes( final long remaining, final long stackSize )
{
if( this.limitQty )
@@ -306,7 +313,7 @@ public class CraftingTreeProcess
if( o != null )
{
this.bytes++;
containerItemsList.add( o );
craftingResultList.add( o );
}
}
}
@@ -318,18 +325,20 @@ public class CraftingTreeProcess
{
final IAEItemStack o = out.copy();
o.setStackSize( o.getStackSize() * amountOfTimes );
inv.injectItems( o, Actionable.MODULATE, src );
craftingResultList.add( o );
}
for( IAEItemStack i : craftingResultList )
{
inv.injectItems( i, Actionable.MODULATE, src );
}
this.crafts += amountOfTimes;
}
public List<IAEItemStack> getReturnedContainers()
public List<IAEItemStack> getCraftingResultList()
{
if( containerItemsList == null )
{
return Collections.emptyList();
}
return containerItemsList;
return craftingResultList;
}
void dive( final CraftingJob job )