Merge branch 'craftingtree-tweaks' into AE2-Omnifactory
This commit is contained in:
@@ -150,6 +150,7 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
|||||||
if( ccr.getCpu() == c )
|
if( ccr.getCpu() == c )
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,16 +50,19 @@ import appeng.hooks.TickHandler;
|
|||||||
|
|
||||||
public class CraftingJob implements Runnable, ICraftingJob
|
public class CraftingJob implements Runnable, ICraftingJob
|
||||||
{
|
{
|
||||||
private static final String LOG_CRAFTING_JOB = "CraftingJob (%s) issued by %s requesting [%s] using %s bytes took %s ms";
|
private static final String LOG_CRAFTING_JOB = "CraftingJob (%s) issued by %s requesting [%s] using %s bytes took %s us";
|
||||||
private static final String LOG_MACHINE_SOURCE_DETAILS = "Machine[object=%s, %s]";
|
private static final String LOG_MACHINE_SOURCE_DETAILS = "Machine[object=%s, %s]";
|
||||||
|
|
||||||
private final MECraftingInventory original;
|
private final MECraftingInventory original;
|
||||||
private final World world;
|
private final World world;
|
||||||
private final IItemList<IAEItemStack> crafting = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
private final IItemList<IAEItemStack> crafting = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||||
private final IItemList<IAEItemStack> missing = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
private final IItemList<IAEItemStack> missing = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||||
|
private final IItemList<IAEItemStack> usedWhileBuilding = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||||
|
|
||||||
private final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
|
private final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
|
||||||
private final Object monitor = new Object();
|
private final Object monitor = new Object();
|
||||||
private final Stopwatch watch = Stopwatch.createUnstarted();
|
private final Stopwatch tickSpreadingWatch = Stopwatch.createUnstarted();
|
||||||
|
private final Stopwatch craftingTreeWatch = Stopwatch.createUnstarted();
|
||||||
private CraftingTreeNode tree;
|
private CraftingTreeNode tree;
|
||||||
private final IAEItemStack output;
|
private final IAEItemStack output;
|
||||||
private boolean simulate = false;
|
private boolean simulate = false;
|
||||||
@@ -86,8 +89,7 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
final ICraftingGrid cc = grid.getCache( ICraftingGrid.class );
|
final ICraftingGrid cc = grid.getCache( ICraftingGrid.class );
|
||||||
final IStorageGrid sg = grid.getCache( IStorageGrid.class );
|
final IStorageGrid sg = grid.getCache( IStorageGrid.class );
|
||||||
this.original = new MECraftingInventory( sg
|
this.original = new MECraftingInventory( sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), actionSrc, false, false, false );
|
||||||
.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), actionSrc, false, false, false );
|
|
||||||
|
|
||||||
this.setTree( this.getCraftingTree( cc, what ) );
|
this.setTree( this.getCraftingTree( cc, what ) );
|
||||||
this.availableCheck = null;
|
this.availableCheck = null;
|
||||||
@@ -103,6 +105,16 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
this.availableCheck.injectItems( o, Actionable.MODULATE, this.actionSrc );
|
this.availableCheck.injectItems( o, Actionable.MODULATE, this.actionSrc );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IItemList<IAEItemStack> getUsedWhileBuilding()
|
||||||
|
{
|
||||||
|
return usedWhileBuilding;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IAEItemStack getOriginal( IAEItemStack request )
|
||||||
|
{
|
||||||
|
return original.getItemList().findPrecise( request );
|
||||||
|
}
|
||||||
|
|
||||||
IAEItemStack checkUse( final IAEItemStack available )
|
IAEItemStack checkUse( final IAEItemStack available )
|
||||||
{
|
{
|
||||||
return this.availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
|
return this.availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
|
||||||
@@ -139,7 +151,7 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
TickHandler.INSTANCE.registerCraftingSimulation( this.world, this );
|
TickHandler.INSTANCE.registerCraftingSimulation( this.world, this );
|
||||||
this.handlePausing();
|
this.handlePausing();
|
||||||
|
|
||||||
final Stopwatch timer = Stopwatch.createStarted();
|
craftingTreeWatch.start();
|
||||||
|
|
||||||
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
|
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
|
||||||
craftingInventory.ignore( this.output );
|
craftingInventory.ignore( this.output );
|
||||||
@@ -154,9 +166,8 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
AELog.crafting( s + " * " + ti.times + " = " + ( ti.perOp * ti.times ) );
|
AELog.crafting( s + " * " + ti.times + " = " + ( ti.perOp * ti.times ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logCraftingJob( "real", timer );
|
craftingTreeWatch.stop();
|
||||||
// if ( mode == Actionable.MODULATE )
|
this.logCraftingJob( "real", craftingTreeWatch );
|
||||||
// craftingInventory.moveItemsToStorage( storage );
|
|
||||||
}
|
}
|
||||||
catch( final CraftBranchFailure e )
|
catch( final CraftBranchFailure e )
|
||||||
{
|
{
|
||||||
@@ -164,23 +175,32 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final Stopwatch timer = Stopwatch.createStarted();
|
if( actionSrc.player().isPresent() )
|
||||||
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
|
|
||||||
craftingInventory.ignore( this.output );
|
|
||||||
|
|
||||||
this.availableCheck = new MECraftingInventory( this.original, false, false, false );
|
|
||||||
|
|
||||||
this.getTree().setSimulate();
|
|
||||||
this.getTree().request( craftingInventory, this.output.getStackSize(), this.actionSrc );
|
|
||||||
this.getTree().dive( this );
|
|
||||||
|
|
||||||
for( final String s : this.opsAndMultiplier.keySet() )
|
|
||||||
{
|
{
|
||||||
final TwoIntegers ti = this.opsAndMultiplier.get( s );
|
craftingTreeWatch.reset().start();
|
||||||
AELog.crafting( s + " * " + ti.times + " = " + ( ti.perOp * ti.times ) );
|
final MECraftingInventory craftingInventory = new MECraftingInventory( this.original, true, false, true );
|
||||||
}
|
craftingInventory.ignore( this.output );
|
||||||
|
|
||||||
this.logCraftingJob( "simulate", timer );
|
this.availableCheck = new MECraftingInventory( this.original, false, false, false );
|
||||||
|
|
||||||
|
this.getTree().setSimulate();
|
||||||
|
this.getTree().request( craftingInventory, this.output.getStackSize(), this.actionSrc );
|
||||||
|
this.getTree().dive( this );
|
||||||
|
|
||||||
|
for( final String s : this.opsAndMultiplier.keySet() )
|
||||||
|
{
|
||||||
|
final TwoIntegers ti = this.opsAndMultiplier.get( s );
|
||||||
|
AELog.crafting( s + " * " + ti.times + " = " + ( ti.perOp * ti.times ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
craftingTreeWatch.stop();
|
||||||
|
this.logCraftingJob( "simulate", craftingTreeWatch );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
craftingTreeWatch.stop();
|
||||||
|
this.logCraftingJob( "real", craftingTreeWatch );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch( final CraftBranchFailure e1 )
|
catch( final CraftBranchFailure e1 )
|
||||||
{
|
{
|
||||||
@@ -226,10 +246,11 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
this.incTime = 0;
|
this.incTime = 0;
|
||||||
synchronized ( this.monitor )
|
synchronized ( this.monitor )
|
||||||
{
|
{
|
||||||
if( this.watch.elapsed( TimeUnit.MICROSECONDS ) > this.time )
|
if( this.tickSpreadingWatch.elapsed( TimeUnit.MICROSECONDS ) > this.time )
|
||||||
{
|
{
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.watch.stop();
|
this.craftingTreeWatch.stop();
|
||||||
|
this.tickSpreadingWatch.stop();
|
||||||
this.monitor.notify();
|
this.monitor.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +284,7 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
|
|
||||||
this.availableCheck = null;
|
this.availableCheck = null;
|
||||||
|
|
||||||
synchronized( this.monitor )
|
synchronized ( this.monitor )
|
||||||
{
|
{
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.done = true;
|
this.done = true;
|
||||||
@@ -311,7 +332,7 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
/**
|
/**
|
||||||
* @return true if this needs more simulation
|
* @return true if this needs more simulation
|
||||||
*/
|
*/
|
||||||
public boolean simulateFor(final int milli)
|
public boolean simulateFor( final int milli )
|
||||||
{
|
{
|
||||||
this.time = milli;
|
this.time = milli;
|
||||||
|
|
||||||
@@ -323,8 +344,8 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
}
|
}
|
||||||
if( !this.actionSrc.player().isPresent() )
|
if( !this.actionSrc.player().isPresent() )
|
||||||
{
|
{
|
||||||
this.watch.reset();
|
this.tickSpreadingWatch.reset();
|
||||||
this.watch.start();
|
this.tickSpreadingWatch.start();
|
||||||
this.monitor.notify();
|
this.monitor.notify();
|
||||||
}
|
}
|
||||||
this.running = true;
|
this.running = true;
|
||||||
@@ -353,7 +374,7 @@ public class CraftingJob implements Runnable, ICraftingJob
|
|||||||
if( AELog.isCraftingLogEnabled() )
|
if( AELog.isCraftingLogEnabled() )
|
||||||
{
|
{
|
||||||
final String itemToOutput = this.output.toString();
|
final String itemToOutput = this.output.toString();
|
||||||
final long elapsedTime = timer.elapsed( TimeUnit.MILLISECONDS );
|
final long elapsedTime = timer.elapsed( TimeUnit.MICROSECONDS );
|
||||||
final String actionSource;
|
final String actionSource;
|
||||||
|
|
||||||
if( this.actionSrc.player().isPresent() )
|
if( this.actionSrc.player().isPresent() )
|
||||||
|
|||||||
@@ -88,6 +88,35 @@ public class CraftingTreeNode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CraftingTreeNode( final ICraftingGrid cc, final CraftingJob job, final IAEItemStack wat, final CraftingTreeProcess par, final int slot, final int depth, boolean available )
|
||||||
|
{
|
||||||
|
this.what = wat;
|
||||||
|
this.parent = par;
|
||||||
|
this.slot = slot;
|
||||||
|
this.world = job.getWorld();
|
||||||
|
this.job = job;
|
||||||
|
this.sim = false;
|
||||||
|
|
||||||
|
this.canEmit = cc.canEmitFor( this.what );
|
||||||
|
|
||||||
|
if( this.canEmit )
|
||||||
|
{
|
||||||
|
return; // if you can emit for something, you can't make it with patterns.
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !available )
|
||||||
|
{
|
||||||
|
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( details ) )
|
||||||
|
{
|
||||||
|
this.nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean notRecursive( final ICraftingPatternDetails details )
|
boolean notRecursive( final ICraftingPatternDetails details )
|
||||||
{
|
{
|
||||||
IAEItemStack[] o = details.getCondensedOutputs();
|
IAEItemStack[] o = details.getCondensedOutputs();
|
||||||
@@ -124,31 +153,8 @@ public class CraftingTreeNode
|
|||||||
final List<IAEItemStack> thingsUsed = new ArrayList<>();
|
final List<IAEItemStack> thingsUsed = new ArrayList<>();
|
||||||
|
|
||||||
this.what.setStackSize( l );
|
this.what.setStackSize( l );
|
||||||
IAEItemStack available = inv.extractItems( this.what, Actionable.MODULATE, src );
|
|
||||||
|
|
||||||
if( available != null )
|
if( this.getSlot() >= 0 && this.parent != null && this.parent.details.isCraftable() )
|
||||||
{
|
|
||||||
if( !this.exhausted )
|
|
||||||
{
|
|
||||||
final IAEItemStack is = this.job.checkUse( available );
|
|
||||||
|
|
||||||
if( is != null )
|
|
||||||
{
|
|
||||||
thingsUsed.add( is.copy() );
|
|
||||||
this.used.add( is );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bytes += available.getStackSize();
|
|
||||||
l -= available.getStackSize();
|
|
||||||
|
|
||||||
if( l == 0 )
|
|
||||||
{
|
|
||||||
return available;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if( this.getSlot() >= 0 && this.parent != null && this.parent.details.isCraftable() )
|
|
||||||
{
|
{
|
||||||
final Collection<IAEItemStack> itemList;
|
final Collection<IAEItemStack> itemList;
|
||||||
final IItemList<IAEItemStack> inventoryList = inv.getItemList();
|
final IItemList<IAEItemStack> inventoryList = inv.getItemList();
|
||||||
@@ -177,12 +183,12 @@ public class CraftingTreeNode
|
|||||||
|
|
||||||
for( IAEItemStack fuzz : itemList )
|
for( IAEItemStack fuzz : itemList )
|
||||||
{
|
{
|
||||||
if( this.parent.details.isValidItemForSlot( this.getSlot(), fuzz.copy().setStackSize( 1 ).createItemStack(), this.world ) )
|
if( this.parent.details.isValidItemForSlot( this.getSlot(), fuzz.copy().getCachedItemStack( 1 ), this.world ) )
|
||||||
{
|
{
|
||||||
fuzz = fuzz.copy();
|
fuzz = fuzz.copy();
|
||||||
fuzz.setStackSize( l );
|
fuzz.setStackSize( l );
|
||||||
|
|
||||||
available = inv.extractItems( fuzz, Actionable.MODULATE, src );
|
final IAEItemStack available = inv.extractItems( fuzz, Actionable.MODULATE, src );
|
||||||
|
|
||||||
if( available != null )
|
if( available != null )
|
||||||
{
|
{
|
||||||
@@ -208,6 +214,32 @@ public class CraftingTreeNode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
final IAEItemStack available = inv.extractItems( this.what, Actionable.MODULATE, src );
|
||||||
|
|
||||||
|
if( available != null )
|
||||||
|
{
|
||||||
|
if( !this.exhausted )
|
||||||
|
{
|
||||||
|
final IAEItemStack is = this.job.checkUse( available );
|
||||||
|
|
||||||
|
if( is != null )
|
||||||
|
{
|
||||||
|
thingsUsed.add( is.copy() );
|
||||||
|
this.used.add( is );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.bytes += available.getStackSize();
|
||||||
|
l -= available.getStackSize();
|
||||||
|
|
||||||
|
if( l == 0 )
|
||||||
|
{
|
||||||
|
return available;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( this.canEmit )
|
if( this.canEmit )
|
||||||
{
|
{
|
||||||
@@ -234,7 +266,7 @@ public class CraftingTreeNode
|
|||||||
|
|
||||||
madeWhat.setStackSize( l );
|
madeWhat.setStackSize( l );
|
||||||
|
|
||||||
available = inv.extractItems( madeWhat, Actionable.MODULATE, src );
|
final IAEItemStack available = inv.extractItems( madeWhat, Actionable.MODULATE, src );
|
||||||
|
|
||||||
if( available != null )
|
if( available != null )
|
||||||
{
|
{
|
||||||
@@ -264,7 +296,7 @@ public class CraftingTreeNode
|
|||||||
pro.request( subInv, 1, src );
|
pro.request( subInv, 1, src );
|
||||||
|
|
||||||
this.what.setStackSize( l );
|
this.what.setStackSize( l );
|
||||||
available = subInv.extractItems( this.what, Actionable.MODULATE, src );
|
final IAEItemStack available = subInv.extractItems( this.what, Actionable.MODULATE, src );
|
||||||
|
|
||||||
if( available != null )
|
if( available != null )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,10 +19,12 @@
|
|||||||
package appeng.crafting;
|
package appeng.crafting;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2LongArrayMap;
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
@@ -40,6 +42,7 @@ import appeng.api.storage.data.IItemList;
|
|||||||
import appeng.container.ContainerNull;
|
import appeng.container.ContainerNull;
|
||||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
|
||||||
public class CraftingTreeProcess
|
public class CraftingTreeProcess
|
||||||
@@ -48,7 +51,7 @@ public class CraftingTreeProcess
|
|||||||
private final CraftingTreeNode parent;
|
private final CraftingTreeNode parent;
|
||||||
final ICraftingPatternDetails details;
|
final ICraftingPatternDetails details;
|
||||||
private final CraftingJob job;
|
private final CraftingJob job;
|
||||||
private final Map<CraftingTreeNode, Long> nodes = new HashMap<>();
|
private final Object2LongArrayMap<CraftingTreeNode> nodes = new Object2LongArrayMap<>();
|
||||||
private final int depth;
|
private final int depth;
|
||||||
boolean possible = true;
|
boolean possible = true;
|
||||||
private World world;
|
private World world;
|
||||||
@@ -70,32 +73,15 @@ public class CraftingTreeProcess
|
|||||||
{
|
{
|
||||||
final IAEItemStack[] list = details.getInputs();
|
final IAEItemStack[] list = details.getInputs();
|
||||||
|
|
||||||
final InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
|
||||||
final IAEItemStack[] is = details.getInputs();
|
|
||||||
for( int x = 0; x < ic.getSizeInventory(); x++ )
|
|
||||||
{
|
|
||||||
ic.setInventorySlotContents( x, is[x] == null ? ItemStack.EMPTY : is[x].createItemStack() );
|
|
||||||
}
|
|
||||||
|
|
||||||
for( int x = 0; x < ic.getSizeInventory(); x++ )
|
|
||||||
{
|
|
||||||
final ItemStack g = ic.getStackInSlot( x );
|
|
||||||
if( !g.isEmpty() && g.getCount() > 1 )
|
|
||||||
{
|
|
||||||
this.fullSimulation = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||||
{
|
{
|
||||||
final ItemStack g = part.createItemStack();
|
|
||||||
|
|
||||||
boolean isAnInput = false;
|
boolean isAnInput = false;
|
||||||
for( final IAEItemStack a : details.getCondensedOutputs() )
|
for( final IAEItemStack a : details.getCondensedOutputs() )
|
||||||
{
|
{
|
||||||
if( !g.isEmpty() && a != null && a.equals( g ) )
|
if( a != null && a.equals( part ) )
|
||||||
{
|
{
|
||||||
isAnInput = true;
|
isAnInput = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,22 +90,30 @@ public class CraftingTreeProcess
|
|||||||
this.limitQty = true;
|
this.limitQty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( g.getItem().hasContainerItem( g ) )
|
if( part.getItem().hasContainerItem( part.getDefinition() ) )
|
||||||
{
|
{
|
||||||
this.limitQty = this.containerItems = true;
|
this.limitQty = this.containerItems = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean complicated = false;
|
if( this.containerItems )
|
||||||
|
|
||||||
if( this.containerItems || complicated )
|
|
||||||
{
|
{
|
||||||
for( int x = 0; x < list.length; x++ )
|
for( int x = 0; x < list.length; x++ )
|
||||||
{
|
{
|
||||||
final IAEItemStack part = list[x];
|
final IAEItemStack part = list[x];
|
||||||
if( part != null )
|
if( part != null )
|
||||||
{
|
{
|
||||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
job.getUsedWhileBuilding().addStorage( part );
|
||||||
|
IAEItemStack used = job.getUsedWhileBuilding().findPrecise( part );
|
||||||
|
if( job.getOriginal( part ) != null && used.getStackSize() <= job.getOriginal( part ).getStackSize() )
|
||||||
|
{
|
||||||
|
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1, true ), part.getStackSize() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,8 +127,17 @@ public class CraftingTreeProcess
|
|||||||
final IAEItemStack comparePart = list[x];
|
final IAEItemStack comparePart = list[x];
|
||||||
if( part != null && part.equals( comparePart ) )
|
if( part != null && part.equals( comparePart ) )
|
||||||
{
|
{
|
||||||
// use the first slot...
|
job.getUsedWhileBuilding().addStorage( part );
|
||||||
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
IAEItemStack used = job.getUsedWhileBuilding().findPrecise( part );
|
||||||
|
if( job.getOriginal( part ) != null && used.getStackSize() <= job.getOriginal( part ).getStackSize() )
|
||||||
|
{
|
||||||
|
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1, true ), part.getStackSize() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// use the first slot...
|
||||||
|
this.nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,14 +148,13 @@ public class CraftingTreeProcess
|
|||||||
{
|
{
|
||||||
for( final IAEItemStack part : details.getCondensedInputs() )
|
for( final IAEItemStack part : details.getCondensedInputs() )
|
||||||
{
|
{
|
||||||
final ItemStack g = part.createItemStack();
|
|
||||||
|
|
||||||
boolean isAnInput = false;
|
boolean isAnInput = false;
|
||||||
for( final IAEItemStack a : details.getCondensedOutputs() )
|
for( final IAEItemStack a : details.getCondensedOutputs() )
|
||||||
{
|
{
|
||||||
if( !g.isEmpty() && a != null && a.equals( g ) )
|
if( a != null && a.equals( part ) )
|
||||||
{
|
{
|
||||||
isAnInput = true;
|
isAnInput = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +192,7 @@ public class CraftingTreeProcess
|
|||||||
{
|
{
|
||||||
final InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
final InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||||
|
|
||||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.entrySet() )
|
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||||
{
|
{
|
||||||
final IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
final IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
||||||
final IAEItemStack stack = entry.getKey().request( inv, item.getStackSize(), src );
|
final IAEItemStack stack = entry.getKey().request( inv, item.getStackSize(), src );
|
||||||
@@ -214,7 +216,7 @@ public class CraftingTreeProcess
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// request and remove inputs...
|
// request and remove inputs...
|
||||||
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.entrySet() )
|
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||||
{
|
{
|
||||||
final IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
final IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
||||||
final IAEItemStack stack = entry.getKey().request( inv, item.getStackSize() * i, src );
|
final IAEItemStack stack = entry.getKey().request( inv, item.getStackSize() * i, src );
|
||||||
@@ -247,9 +249,9 @@ public class CraftingTreeProcess
|
|||||||
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 );
|
||||||
for( final CraftingTreeNode pro : this.nodes.keySet() )
|
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||||
{
|
{
|
||||||
pro.dive( job );
|
entry.getKey().dive( job );
|
||||||
}
|
}
|
||||||
|
|
||||||
job.addBytes( this.crafts * 8 + this.bytes );
|
job.addBytes( this.crafts * 8 + this.bytes );
|
||||||
@@ -286,9 +288,9 @@ public class CraftingTreeProcess
|
|||||||
this.crafts = 0;
|
this.crafts = 0;
|
||||||
this.bytes = 0;
|
this.bytes = 0;
|
||||||
|
|
||||||
for( final CraftingTreeNode pro : this.nodes.keySet() )
|
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||||
{
|
{
|
||||||
pro.setSimulate();
|
entry.getKey().setSimulate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,9 +298,9 @@ public class CraftingTreeProcess
|
|||||||
{
|
{
|
||||||
craftingCPUCluster.addCrafting( this.details, this.crafts );
|
craftingCPUCluster.addCrafting( this.details, this.crafts );
|
||||||
|
|
||||||
for( final CraftingTreeNode pro : this.nodes.keySet() )
|
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||||
{
|
{
|
||||||
pro.setJob( storage, craftingCPUCluster, src );
|
entry.getKey().setJob( storage, craftingCPUCluster, src );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,9 +313,9 @@ public class CraftingTreeProcess
|
|||||||
plan.addRequestable( i );
|
plan.addRequestable( i );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( final CraftingTreeNode pro : this.nodes.keySet() )
|
for( final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet() )
|
||||||
{
|
{
|
||||||
pro.getPlan( plan );
|
entry.getKey().getPlan( plan );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,8 +97,7 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
|||||||
this.injectedCache = null;
|
this.injectedCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.localCache = this.target
|
this.localCache = this.target.getAvailableItems( new ItemListIgnoreCrafting<>( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() ) );
|
||||||
.getAvailableItems( new ItemListIgnoreCrafting<>( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() ) );
|
|
||||||
|
|
||||||
this.par = parent;
|
this.par = parent;
|
||||||
}
|
}
|
||||||
@@ -140,7 +139,14 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
|||||||
this.localCache = new ItemListIgnoreCrafting<>( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
this.localCache = new ItemListIgnoreCrafting<>( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
||||||
for( final IAEItemStack is : target.getStorageList() )
|
for( final IAEItemStack is : target.getStorageList() )
|
||||||
{
|
{
|
||||||
this.localCache.add( target.extractItems( is, Actionable.SIMULATE, src ) );
|
if( src.player().isPresent() )
|
||||||
|
{
|
||||||
|
this.localCache.add( target.extractItems( is, Actionable.SIMULATE, src ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.localCache.add( is );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.par = null;
|
this.par = null;
|
||||||
@@ -321,7 +327,10 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
failed = true;
|
failed = true;
|
||||||
if( !src.player().isPresent() ) break;
|
if( !src.player().isPresent() )
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,8 +108,6 @@ import static gregtech.api.block.machines.BlockMachine.getMetaTileEntity;
|
|||||||
|
|
||||||
public class DualityInterface implements IGridTickable, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, IConfigManagerHost, ICraftingProvider, IUpgradeableHost
|
public class DualityInterface implements IGridTickable, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, IConfigManagerHost, ICraftingProvider, IUpgradeableHost
|
||||||
{
|
{
|
||||||
private final int[] failedCraftTriesSlot = {0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
public static final int NUMBER_OF_STORAGE_SLOTS = 9;
|
public static final int NUMBER_OF_STORAGE_SLOTS = 9;
|
||||||
public static final int NUMBER_OF_CONFIG_SLOTS = 9;
|
public static final int NUMBER_OF_CONFIG_SLOTS = 9;
|
||||||
public static final int NUMBER_OF_PATTERN_SLOTS = 36;
|
public static final int NUMBER_OF_PATTERN_SLOTS = 36;
|
||||||
@@ -970,21 +968,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||||||
{
|
{
|
||||||
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 && itemStack != null )
|
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 && itemStack != null )
|
||||||
{
|
{
|
||||||
if( this.failedCraftTriesSlot[x] <= 0 )
|
return this.craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, this.iHost.getTileEntity().getWorld(), this.gridProxy.getGrid(), this.gridProxy.getCrafting(), this.mySource );
|
||||||
{
|
|
||||||
boolean crafted = this.craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, this.iHost.getTileEntity().getWorld(), this.gridProxy.getGrid(), this.gridProxy.getCrafting(), this.mySource );
|
|
||||||
|
|
||||||
if( crafted )
|
|
||||||
{
|
|
||||||
this.failedCraftTriesSlot[x] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.failedCraftTriesSlot[x] += 2;
|
|
||||||
}
|
|
||||||
return crafted;
|
|
||||||
}
|
|
||||||
this.failedCraftTriesSlot[x] -= 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( final GridAccessException e )
|
catch( final GridAccessException e )
|
||||||
|
|||||||
@@ -544,22 +544,6 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||||||
|
|
||||||
if( res == null )
|
if( res == null )
|
||||||
{
|
{
|
||||||
if( details != null && details.isCraftable() )
|
|
||||||
{
|
|
||||||
for( final IAEItemStack ais : this.craftableItems.keySet() )
|
|
||||||
{
|
|
||||||
if( ais.getItem() == whatToCraft.getItem() && ( !ais.getItem().getHasSubtypes() || ais.getItemDamage() == whatToCraft.getItemDamage() ) )
|
|
||||||
{
|
|
||||||
// TODO: check if OK
|
|
||||||
// TODO: this is slightly hacky, but fine as long as we only deal with itemstacks
|
|
||||||
if( details.isValidItemForSlot( slotIndex, ais.asItemStackRepresentation(), world ) )
|
|
||||||
{
|
|
||||||
return this.craftableItems.get( ais );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ImmutableSet.of();
|
return ImmutableSet.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
package appeng.parts.automation;
|
package appeng.parts.automation;
|
||||||
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
@@ -72,8 +71,6 @@ import appeng.util.item.AEItemStack;
|
|||||||
|
|
||||||
public class PartExportBus extends PartSharedItemBus implements ICraftingRequester
|
public class PartExportBus extends PartSharedItemBus implements ICraftingRequester
|
||||||
{
|
{
|
||||||
private final int[] failedCraftTriesSlot = {0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/export_bus_base" );
|
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/export_bus_base" );
|
||||||
|
|
||||||
@PartModels
|
@PartModels
|
||||||
@@ -156,22 +153,8 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
|
|||||||
|
|
||||||
if( this.craftOnly() )
|
if( this.craftOnly() )
|
||||||
{
|
{
|
||||||
if( this.failedCraftTriesSlot[x] <= 0 )
|
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
|
||||||
{
|
|
||||||
|
|
||||||
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
|
|
||||||
|
|
||||||
if( this.didSomething )
|
|
||||||
{
|
|
||||||
this.failedCraftTriesSlot[x] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.failedCraftTriesSlot[x] += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.failedCraftTriesSlot[x] -= 1;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final long before = this.itemToSend;
|
final long before = this.itemToSend;
|
||||||
@@ -197,21 +180,7 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
|
|||||||
|
|
||||||
if( this.itemToSend == before && this.isCraftingEnabled() )
|
if( this.itemToSend == before && this.isCraftingEnabled() )
|
||||||
{
|
{
|
||||||
if( this.failedCraftTriesSlot[x] <= 0 )
|
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
|
||||||
{
|
|
||||||
|
|
||||||
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
|
|
||||||
|
|
||||||
if( this.didSomething )
|
|
||||||
{
|
|
||||||
this.failedCraftTriesSlot[x] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.failedCraftTriesSlot[x] += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.failedCraftTriesSlot[x] -= 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
|||||||
private String displayName;
|
private String displayName;
|
||||||
@SideOnly( Side.CLIENT )
|
@SideOnly( Side.CLIENT )
|
||||||
private List<String> tooltip;
|
private List<String> tooltip;
|
||||||
private WeakReference<ItemStack> cachedItemStack;
|
private ItemStack cachedItemStack;
|
||||||
|
|
||||||
private AEItemStack( final AEItemStack is )
|
private AEItemStack( final AEItemStack is )
|
||||||
{
|
{
|
||||||
@@ -66,6 +66,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
|||||||
this.setCountRequestable( is.getCountRequestable() );
|
this.setCountRequestable( is.getCountRequestable() );
|
||||||
this.sharedStack = is.sharedStack;
|
this.sharedStack = is.sharedStack;
|
||||||
this.oreReference = is.oreReference;
|
this.oreReference = is.oreReference;
|
||||||
|
this.cachedItemStack = is.cachedItemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AEItemStack( final AESharedItemStack is, long size )
|
private AEItemStack( final AESharedItemStack is, long size )
|
||||||
@@ -282,7 +283,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
|||||||
ItemStack currentCached = null;
|
ItemStack currentCached = null;
|
||||||
if( this.cachedItemStack != null )
|
if( this.cachedItemStack != null )
|
||||||
{
|
{
|
||||||
currentCached = this.cachedItemStack.get();
|
currentCached = this.cachedItemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack itemStack;
|
ItemStack itemStack;
|
||||||
@@ -304,7 +305,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
|||||||
@Override
|
@Override
|
||||||
public void setCachedItemStack( ItemStack itemStack )
|
public void setCachedItemStack( ItemStack itemStack )
|
||||||
{
|
{
|
||||||
this.cachedItemStack = new WeakReference<>( itemStack );
|
this.cachedItemStack = itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user