Compare commits

...

1 Commits

Author SHA1 Message Date
PrototypeTrousers c532b9c839 wip 2022-03-05 00:03:29 -03:00
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 final Stopwatch craftingTreeWatch = Stopwatch.createUnstarted();
private CraftingTreeNode tree; private CraftingTreeNode tree;
private final IAEItemStack output; private final IAEItemStack output;
private long expectedOutput;
private boolean simulate = false; private boolean simulate = false;
private MECraftingInventory availableCheck; private MECraftingInventory availableCheck;
private long bytes = 0; private long bytes = 0;
@@ -98,6 +99,16 @@ public class CraftingJob implements Runnable, ICraftingJob
this.availableCheck = null; 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 ) private CraftingTreeNode getCraftingTree( final ICraftingGrid cc, final IAEItemStack what )
{ {
return new CraftingTreeNode( cc, this, what, null, -1, 0 ); return new CraftingTreeNode( cc, this, what, null, -1, 0 );
@@ -24,7 +24,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import appeng.api.config.FuzzyMode; import appeng.api.config.FuzzyMode;
import com.google.common.collect.Lists;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World; 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 for( final ICraftingPatternDetails details : cc.getCraftingFor( this.what, this.parent == null ? null : this.parent.details, slot, this.world ) )// in
// order. // 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 ) ); 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 ); 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();
@@ -234,11 +228,6 @@ public class CraftingTreeNode
this.what.setStackSize( l ); this.what.setStackSize( l );
final IAEItemStack available = subInv.extractItems( this.what, Actionable.MODULATE, src ); 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( available != null )
{ {
if( !subInv.commit( src ) ) if( !subInv.commit( src ) )
@@ -286,11 +275,6 @@ public class CraftingTreeNode
throw new CraftBranchFailure( this.what, l ); throw new CraftBranchFailure( this.what, l );
} }
boolean notRecursive()
{
return this.parent == null || job.getUniques().findPrecise( this.what ) == null;
}
void dive( final CraftingJob job ) void dive( final CraftingJob job )
{ {
if( this.missing > 0 ) if( this.missing > 0 )
@@ -20,21 +20,18 @@ package appeng.crafting;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import appeng.api.config.Actionable;
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;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.crafting.ICraftingGrid; import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.security.IActionSource; import appeng.api.networking.security.IActionSource;
@@ -56,7 +53,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 final List<IAEItemStack> craftingResultList = new ArrayList<>();
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 )
@@ -76,13 +73,28 @@ 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;
//break; //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. // this is minor different then below, this slot uses the pattern, but kinda fudges it.
for( IAEItemStack part : details.getCondensedInputs() ) for( IAEItemStack part : details.getCondensedInputs() )
{ {
@@ -275,11 +287,6 @@ public class CraftingTreeProcess
return this.containerItems; return this.containerItems;
} }
boolean notRecursive()
{
return this.parent == null || this.parent.notRecursive();
}
long getTimes( final long remaining, final long stackSize ) long getTimes( final long remaining, final long stackSize )
{ {
if( this.limitQty ) if( this.limitQty )
@@ -306,7 +313,7 @@ public class CraftingTreeProcess
if( o != null ) if( o != null )
{ {
this.bytes++; this.bytes++;
containerItemsList.add( o ); craftingResultList.add( o );
} }
} }
} }
@@ -318,18 +325,20 @@ public class CraftingTreeProcess
{ {
final IAEItemStack o = out.copy(); final IAEItemStack o = out.copy();
o.setStackSize( o.getStackSize() * amountOfTimes ); 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; this.crafts += amountOfTimes;
} }
public List<IAEItemStack> getReturnedContainers() public List<IAEItemStack> getCraftingResultList()
{ {
if( containerItemsList == null ) return craftingResultList;
{
return Collections.emptyList();
}
return containerItemsList;
} }
void dive( final CraftingJob job ) void dive( final CraftingJob job )