meh. crafting gets stuck if the output loops

This commit is contained in:
PrototypeTrousers
2022-03-27 00:04:53 -03:00
parent 8cc29734a2
commit 234b1c5dc6
4 changed files with 77 additions and 32 deletions
@@ -129,7 +129,7 @@ public class CraftingJob implements Runnable, ICraftingJob
public void reserve( CraftingTreeNode node, IAEItemStack stack )
{
checkUse( stack );
this.checkUse( stack );
reserved.put( node, stack );
}
@@ -156,6 +156,8 @@ public class CraftingJob implements Runnable, ICraftingJob
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
this.availableCheck = new MECraftingInventory( this.original, false, false, false );
this.reserved.values().forEach( availableCheck::reserve );
craftingTreeWatch.start();
this.getTree().request( craftingInventory, this.output.getStackSize(), this.actionSrc );
craftingTreeWatch.stop();
@@ -185,9 +187,11 @@ public class CraftingJob implements Runnable, ICraftingJob
if( actionSrc.player().isPresent() )
{
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
this.getTree().setSimulate();
this.availableCheck = new MECraftingInventory( this.original, false, false, false );
this.reserved.values().forEach( availableCheck::reserve );
craftingTreeWatch.reset().start();
this.getTree().request( craftingInventory, this.output.getStackSize(), this.actionSrc );
craftingTreeWatch.stop();
@@ -56,6 +56,7 @@ public class CraftingTreeNode
private final ArrayList<CraftingTreeProcess> nodes = new ArrayList<>();
private final boolean canEmit;
private CraftingTreeNode loopHead;
private int times;
private int bytes = 0;
private long missing = 0;
private long howManyEmitted = 0;
@@ -88,14 +89,6 @@ public class CraftingTreeNode
}
}
for( IAEItemStack i : details.getCondensedInputs() )
{
if( i.equals( job.getOutput() ) )
{
job.getNeededForLoop().add( i.copy().setStackSize( i.getStackSize() * times ) );
}
}
if( this.parent == null )
{
this.nodes.add( new CraftingTreeProcess( cc, job, details, times, this ) );
@@ -115,7 +108,7 @@ public class CraftingTreeNode
void reserveForNode()
{
if( loopHead == this )
if( this.equals( loopHead ) )
{
return;
}
@@ -152,6 +145,14 @@ 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<IAEItemStack> itemList = new ArrayList<>();
@@ -203,7 +204,16 @@ public class CraftingTreeNode
fuzz = fuzz.copy();
fuzz.setStackSize( l );
final IAEItemStack available = inv.extractItems( fuzz, Actionable.MODULATE, src );
final IAEItemStack available;
if( reserved != null )
{
available = reserved;
}
else
{
available = inv.extractItems( fuzz, Actionable.MODULATE, src );
}
if( available != null )
{
@@ -216,6 +226,11 @@ public class CraftingTreeNode
thingsUsed.add( is.copy() );
this.used.add( is );
}
else if( reserved != null )
{
thingsUsed.add( reserved.copy() );
this.used.add( reserved );
}
}
this.bytes += available.getStackSize();
@@ -231,28 +246,37 @@ public class CraftingTreeNode
}
else
{
final IAEItemStack available = inv.extractItems( this.what, Actionable.MODULATE, src );
final IAEItemStack available;
if( parent == null && this.what.equals( job.getOutput() ) )
{
available = null;
}
else if( reserved != null )
{
available = reserved;
}
else
{
available = inv.extractItems( this.what, Actionable.MODULATE, src );
}
if( available != null )
{
if( !this.exhausted )
{
IAEItemStack is;
if( reserved != null )
{
is = reserved;
}
else
{
is = this.job.checkUse( available );
}
final IAEItemStack is = this.job.checkUse( available );
if( is != null )
{
thingsUsed.add( is.copy() );
this.used.add( is );
}
else if( reserved != null )
{
thingsUsed.add( reserved.copy() );
this.used.add( reserved );
}
}
this.bytes += available.getStackSize();
@@ -349,6 +349,24 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
return true;
}
void ignore( final IAEItemStack what )
{
final IAEItemStack list = this.localCache.findPrecise( what );
if( list != null )
{
list.setStackSize( 0 );
}
}
void reserve( final IAEItemStack what )
{
final IAEItemStack list = this.localCache.findPrecise( what );
if( list != null )
{
list.decStackSize( what.getStackSize() );
}
}
private void addMissing( final IAEItemStack extra )
{
this.missingCache.add( extra );
@@ -283,16 +283,15 @@ public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack
{
if( this.cachedItemStack != null )
{
ItemStack currentCached = this.cachedItemStack;
this.cachedItemStack = null;
currentCached.setCount( Ints.saturatedCast( stackSize ) );
return currentCached;
if( Platform.itemComparisons().isSameItem( this.getDefinition(), this.cachedItemStack ) )
{
ItemStack currentCached = this.cachedItemStack;
this.cachedItemStack = null;
currentCached.setCount( Ints.saturatedCast( stackSize ) );
return currentCached;
}
}
ItemStack itemStack = this.createItemStack();
itemStack.setCount( Ints.saturatedCast( stackSize ) );
return itemStack;
return ItemHandlerHelper.copyStackWithSize( this.getDefinition(), Ints.saturatedCast( stackSize ) );
}
@Override