Crafting Calculator mostly works now - is missing features however.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package appeng.crafting;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public class CraftBranchFailure extends Exception
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 654603652836724823L;
|
||||
|
||||
IAEItemStack missing;
|
||||
|
||||
public CraftBranchFailure(IAEItemStack what, long howMany) {
|
||||
super( "this should have been caught!" );
|
||||
missing = what.copy();
|
||||
missing.setStackSize( howMany );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package appeng.crafting;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public class CraftingCalculationFailure extends RuntimeException
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 654603652836724823L;
|
||||
|
||||
IAEItemStack missing;
|
||||
|
||||
public CraftingCalculationFailure(IAEItemStack what, long howMany) {
|
||||
super( "this should have been caught!" );
|
||||
missing = what.copy();
|
||||
missing.setStackSize( howMany );
|
||||
}
|
||||
}
|
||||
+34
-136
@@ -1,25 +1,22 @@
|
||||
package appeng.crafting;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.core.AELog;
|
||||
import appeng.me.cache.CraftingCache;
|
||||
import appeng.util.Platform;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.base.Stopwatch;
|
||||
|
||||
public class CraftingJob implements ICraftingParent
|
||||
public class CraftingJob
|
||||
{
|
||||
|
||||
IAEItemStack output;
|
||||
@@ -28,170 +25,71 @@ public class CraftingJob implements ICraftingParent
|
||||
|
||||
HashSet<IAEItemStack> prophecies;
|
||||
|
||||
Multimap<IAEItemStack, CraftingTask> bottom;
|
||||
CraftingTask top;
|
||||
|
||||
ICraftingHost jobHost;
|
||||
|
||||
public CraftingJob(ICraftingHost host, NBTTagCompound data) {
|
||||
jobHost = host;
|
||||
storage = AEApi.instance().storage().createItemList();
|
||||
prophecies = new HashSet();
|
||||
bottom = ArrayListMultimap.create();
|
||||
}
|
||||
|
||||
public CraftingJob(ICraftingHost host, IAEItemStack what, Actionable mode) throws CraftingMissingItemsException {
|
||||
public CraftingJob(ICraftingHost host, IAEItemStack what, Actionable mode) {
|
||||
jobHost = host;
|
||||
output = what.copy();
|
||||
storage = AEApi.instance().storage().createItemList();
|
||||
prophecies = new HashSet();
|
||||
bottom = ArrayListMultimap.create();
|
||||
|
||||
CraftingCache cc = host.getGrid().getCache( CraftingCache.class );
|
||||
IStorageGrid sg = host.getGrid().getCache( IStorageGrid.class );
|
||||
|
||||
IItemList<IAEItemStack> missing = AEApi.instance().storage().createItemList();
|
||||
|
||||
MECraftingInventory meci = new MECraftingInventory( sg.getItemInventory() );
|
||||
MECraftingInventory meci = new MECraftingInventory( sg.getItemInventory(), true, false, true );
|
||||
meci.ignore( what );
|
||||
|
||||
calculateCrafting( cc, this, meci, missing, what, mode );
|
||||
CraftingTreeNode tree = getCraftingTree( cc, what );
|
||||
|
||||
if ( !missing.isEmpty() )
|
||||
try
|
||||
{
|
||||
if ( mode == Actionable.MODULATE )
|
||||
{
|
||||
IMEInventory<IAEItemStack> netStorage = sg.getItemInventory();
|
||||
|
||||
Iterator<IAEItemStack> i = storage.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
IAEItemStack item = i.next();
|
||||
netStorage.injectItems( item, mode, host.getActionSrc() );
|
||||
}
|
||||
}
|
||||
|
||||
throw new CraftingMissingItemsException( missing );
|
||||
Stopwatch timer = Stopwatch.createStarted();
|
||||
tree.request( meci, what.getStackSize(), host.getActionSrc() );
|
||||
tree.dive( this );
|
||||
AELog.info( "-------------" + timer.elapsed( TimeUnit.MILLISECONDS ) + "ms" );
|
||||
// if ( mode == Actionable.MODULATE )
|
||||
// meci.moveItemsToStorage( storage );
|
||||
}
|
||||
catch (CraftBranchFailure e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
catch (CraftingCalculationFailure f)
|
||||
{
|
||||
AELog.error( f );
|
||||
}
|
||||
|
||||
if ( mode == Actionable.MODULATE )
|
||||
meci.moveItemsToStorage( storage );
|
||||
}
|
||||
|
||||
public void calculateCrafting(CraftingCache cc, ICraftingParent parent, IMEInventory<IAEItemStack> inv, IItemList<IAEItemStack> missing, IAEItemStack what,
|
||||
Actionable mode)
|
||||
private CraftingTreeNode getCraftingTree(CraftingCache cc, IAEItemStack what)
|
||||
{
|
||||
Set<ICraftingPatternDetails> patterns = cc.getCraftingFor( what );
|
||||
|
||||
for (ICraftingPatternDetails details : patterns)
|
||||
{
|
||||
IAEItemStack[] requirements = details.getCondencedInputs();
|
||||
if ( canMake( requirements, inv ) )
|
||||
{
|
||||
extractItems( requirements, inv, storage, missing );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (ICraftingPatternDetails details : patterns)
|
||||
{
|
||||
IAEItemStack[] requirements = details.getCondencedInputs();
|
||||
extractItems( requirements, inv, storage, missing );
|
||||
return;
|
||||
}
|
||||
return new CraftingTreeNode( cc, this, what, null, 0 );
|
||||
}
|
||||
|
||||
private void extractItems(IAEItemStack[] requirements, IMEInventory<IAEItemStack> inv, IItemList<IAEItemStack> dest, IItemList<IAEItemStack> missing)
|
||||
{
|
||||
for (IAEItemStack is : requirements)
|
||||
{
|
||||
IAEItemStack avail = inv.extractItems( is, Actionable.MODULATE, jobHost.getActionSrc() );
|
||||
|
||||
if ( avail == null )
|
||||
{
|
||||
missing.add( is );
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( avail.getStackSize() != is.getStackSize() )
|
||||
{
|
||||
IAEItemStack ais = avail.copy();
|
||||
ais.setStackSize( is.getStackSize() - avail.getStackSize() );
|
||||
missing.add( ais );
|
||||
}
|
||||
|
||||
dest.add( avail );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canMake(IAEItemStack[] requirements, IMEInventory<IAEItemStack> inv)
|
||||
{
|
||||
|
||||
for (IAEItemStack is : requirements)
|
||||
{
|
||||
IAEItemStack avail = inv.extractItems( is, Actionable.SIMULATE, jobHost.getActionSrc() );
|
||||
|
||||
if ( avail == null )
|
||||
return false;
|
||||
|
||||
if ( avail.getStackSize() != is.getStackSize() )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Collection<CraftingTask> getBottom()
|
||||
{
|
||||
return bottom.values();
|
||||
}
|
||||
|
||||
public IAEItemStack addProgress(IAEItemStack progress)
|
||||
{
|
||||
Collection<CraftingTask> task = bottom.get( progress );
|
||||
|
||||
if ( task == null )
|
||||
return progress;
|
||||
|
||||
Iterator<CraftingTask> i = task.iterator();
|
||||
|
||||
while (i.hasNext())
|
||||
{
|
||||
// adding to the first item..
|
||||
progress = i.next().addProgress( progress );
|
||||
|
||||
// if nothing remains return
|
||||
if ( progress == null )
|
||||
return null;
|
||||
|
||||
// if something remains continue..
|
||||
i = task.iterator();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound out)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChild(CraftingTask craftingTask)
|
||||
public void addTask(IAEItemStack what, int crafts, ICraftingPatternDetails details, int depth)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
if ( crafts > 0 )
|
||||
{
|
||||
AELog.info( "new task: " + Platform.getItemDisplayName( what ) + " x " + what.getStackSize() + " * " + crafts + " = "
|
||||
+ (what.getStackSize() * crafts) + " @ " + depth );
|
||||
}
|
||||
}
|
||||
|
||||
public ICraftingHost getHost()
|
||||
public void addMissing(IAEItemStack what)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends ICraftingParent> getSubJobs()
|
||||
{
|
||||
return Collections.singleton( top );
|
||||
AELog.info( "required material: " + Platform.getItemDisplayName( what ) + " x " + what.getStackSize() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package appeng.crafting;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public class CraftingMissingItemsException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -7517510681369528425L;
|
||||
|
||||
final public IItemList<IAEItemStack> missingItems;
|
||||
|
||||
public CraftingMissingItemsException( IItemList<IAEItemStack> missing )
|
||||
{
|
||||
missingItems = missing;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package appeng.crafting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.items.misc.ItemEncodedPattern;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class CraftingTask implements ICraftingParent
|
||||
{
|
||||
|
||||
final IAEItemStack task;
|
||||
|
||||
final ICraftingPatternDetails process;
|
||||
|
||||
final List<CraftingTask> subtasks;
|
||||
final ICraftingParent parenttask;
|
||||
|
||||
final CraftingJob job;
|
||||
|
||||
public CraftingTask(IAEItemStack myTask, ICraftingPatternDetails pattern, ICraftingParent parent, CraftingJob craftingJob) {
|
||||
task = myTask;
|
||||
process = pattern;
|
||||
parenttask = parent;
|
||||
job = craftingJob;
|
||||
subtasks = new ArrayList();
|
||||
|
||||
// register as part of the bottom.
|
||||
job.bottom.put( task.copy(), this );
|
||||
}
|
||||
|
||||
public CraftingTask(NBTTagCompound c, ICraftingParent parent, CraftingJob craftingJob) {
|
||||
task = AEItemStack.loadItemStackFromNBT( c.getCompoundTag( "task" ) );
|
||||
ItemStack pattern = ItemStack.loadItemStackFromNBT( c.getCompoundTag( "pattern" ) );
|
||||
|
||||
if ( pattern == null || !(pattern.getItem() instanceof ItemEncodedPattern) )
|
||||
throw new RuntimeException( "Failed to load crafting job" );
|
||||
|
||||
ItemEncodedPattern iep = (ItemEncodedPattern) pattern.getItem();
|
||||
process = iep.getPatternForItem( pattern, craftingJob.getHost().getWorld() );
|
||||
|
||||
subtasks = new ArrayList();
|
||||
parenttask = parent;
|
||||
job = craftingJob;
|
||||
}
|
||||
|
||||
public IAEItemStack addProgress(IAEItemStack progress)
|
||||
{
|
||||
long amt = progress.getStackSize();
|
||||
long mine = task.getStackSize();
|
||||
|
||||
if ( amt >= mine )
|
||||
{
|
||||
parenttask.removeChild( this );
|
||||
|
||||
task.reset();
|
||||
job.bottom.remove( task, this );
|
||||
|
||||
progress = progress.copy();
|
||||
progress.decStackSize( mine );
|
||||
return progress;
|
||||
}
|
||||
else
|
||||
{
|
||||
task.decStackSize( amt );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addSubTask(CraftingTask task)
|
||||
{
|
||||
boolean wasEmpty = subtasks.isEmpty();
|
||||
|
||||
subtasks.add( task );
|
||||
|
||||
if ( wasEmpty )
|
||||
job.bottom.remove( task, this );
|
||||
}
|
||||
|
||||
public void removeChild(CraftingTask craftingTask)
|
||||
{
|
||||
subtasks.remove( craftingTask );
|
||||
if ( subtasks.isEmpty() )
|
||||
{
|
||||
job.bottom.put( task.copy(), this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends ICraftingParent> getSubJobs()
|
||||
{
|
||||
return subtasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound out)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package appeng.crafting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.me.cache.CraftingCache;
|
||||
|
||||
public class CraftingTreeNode
|
||||
{
|
||||
|
||||
// parent node.
|
||||
private CraftingTreeProcess parent;
|
||||
|
||||
// what item is this?
|
||||
private IAEItemStack what;
|
||||
|
||||
// what are the crafting patterns for this?
|
||||
private ArrayList<CraftingTreeProcess> nodes = new ArrayList();
|
||||
|
||||
boolean cannotUse = false;
|
||||
int missing = 0;
|
||||
|
||||
public CraftingTreeNode(CraftingCache cc, CraftingJob job, IAEItemStack wat, CraftingTreeProcess par, int depth) {
|
||||
what = wat;
|
||||
parent = par;
|
||||
|
||||
for (ICraftingPatternDetails details : cc.getCraftingFor( what ))// in order.
|
||||
{
|
||||
if ( notRecurive( details ) )
|
||||
nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1 ) );
|
||||
}
|
||||
}
|
||||
|
||||
public IAEItemStack getStack(long size)
|
||||
{
|
||||
IAEItemStack is = what.copy();
|
||||
is.setStackSize( size );
|
||||
return is;
|
||||
}
|
||||
|
||||
boolean notRecurive(ICraftingPatternDetails details)
|
||||
{
|
||||
IAEItemStack[] o = details.getOutputs();
|
||||
for (IAEItemStack i : o)
|
||||
if ( i.equals( what ) )
|
||||
return true;
|
||||
|
||||
if ( parent == null )
|
||||
return false;
|
||||
|
||||
return parent.notRecurive( details );
|
||||
}
|
||||
|
||||
private long getTimes(long remaining, long stackSize)
|
||||
{
|
||||
return (remaining / stackSize) + (remaining % stackSize != 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
public void request(MECraftingInventory inv, long l, BaseActionSource src) throws CraftBranchFailure
|
||||
{
|
||||
what.setStackSize( l );
|
||||
IAEItemStack available = inv.extractItems( what, Actionable.MODULATE, src );
|
||||
|
||||
if ( available != null )
|
||||
l -= available.getStackSize();
|
||||
|
||||
if ( l == 0 )
|
||||
return;
|
||||
|
||||
if ( nodes.size() == 1 )
|
||||
{
|
||||
CraftingTreeProcess pro = nodes.get( 0 );
|
||||
|
||||
while (pro.possible && l > 0)
|
||||
{
|
||||
pro.request( inv, getTimes( l, pro.getAmountCrafted( what ).getStackSize() ), src );
|
||||
|
||||
what.setStackSize( l );
|
||||
available = inv.extractItems( what, Actionable.MODULATE, src );
|
||||
|
||||
if ( available != null )
|
||||
{
|
||||
l -= available.getStackSize();
|
||||
|
||||
if ( l <= 0 )
|
||||
return;
|
||||
}
|
||||
else
|
||||
pro.possible = false; // ;P
|
||||
}
|
||||
}
|
||||
else if ( nodes.size() > 1 )
|
||||
{
|
||||
for (CraftingTreeProcess pro : nodes)
|
||||
{
|
||||
try
|
||||
{
|
||||
while (pro.possible && l > 0)
|
||||
{
|
||||
MECraftingInventory subInv = new MECraftingInventory( inv );
|
||||
pro.request( subInv, 1, src );
|
||||
subInv.commit( src );
|
||||
|
||||
what.setStackSize( l );
|
||||
available = inv.extractItems( what, Actionable.MODULATE, src );
|
||||
|
||||
if ( available != null )
|
||||
{
|
||||
l -= available.getStackSize();
|
||||
|
||||
if ( l <= 0 )
|
||||
return;
|
||||
}
|
||||
else
|
||||
pro.possible = false; // ;P
|
||||
}
|
||||
}
|
||||
catch (CraftBranchFailure fail)
|
||||
{
|
||||
pro.possible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
missing += l;
|
||||
// throw new CraftBranchFailure( what, l );
|
||||
}
|
||||
|
||||
public void dive(CraftingJob job)
|
||||
{
|
||||
if ( missing > 0 )
|
||||
job.addMissing( getStack( missing ) );
|
||||
missing = 0;
|
||||
|
||||
for (CraftingTreeProcess pro : nodes)
|
||||
pro.dive( job );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package appeng.crafting;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.me.cache.CraftingCache;
|
||||
|
||||
public class CraftingTreeProcess
|
||||
{
|
||||
|
||||
CraftingTreeNode parent;
|
||||
ICraftingPatternDetails details;
|
||||
CraftingJob job;
|
||||
|
||||
int crafts = 0;
|
||||
final private int depth;
|
||||
|
||||
Map<CraftingTreeNode, Long> nodes = new HashMap();
|
||||
public boolean possible = true;
|
||||
|
||||
public CraftingTreeProcess(CraftingCache cc, CraftingJob job, ICraftingPatternDetails details, CraftingTreeNode craftingTreeNode, int depth) {
|
||||
parent = craftingTreeNode;
|
||||
this.details = details;
|
||||
this.job = job;
|
||||
this.depth = depth;
|
||||
|
||||
for (IAEItemStack part : details.getCondencedInputs())
|
||||
nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, depth + 1 ), part.getStackSize() );
|
||||
}
|
||||
|
||||
public boolean notRecurive(ICraftingPatternDetails details)
|
||||
{
|
||||
return parent.notRecurive( details );
|
||||
}
|
||||
|
||||
IAEItemStack getAmountCrafted(IAEItemStack what2)
|
||||
{
|
||||
for (IAEItemStack is : details.getCondencedOutputs())
|
||||
{
|
||||
if ( is.equals( what2 ) )
|
||||
{
|
||||
what2 = what2.copy();
|
||||
what2.setStackSize( is.getStackSize() );
|
||||
return what2;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException( "Crafting Tree construction failed." );
|
||||
}
|
||||
|
||||
public void request(MECraftingInventory inv, long i, BaseActionSource src) throws CraftBranchFailure
|
||||
{
|
||||
// request and remove inputs...
|
||||
for (Entry<CraftingTreeNode, Long> entry : nodes.entrySet())
|
||||
{
|
||||
IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
||||
entry.getKey().request( inv, item.getStackSize() * i, src );
|
||||
}
|
||||
|
||||
// assume its possible.
|
||||
|
||||
// add crafting results..
|
||||
for (IAEItemStack out : details.getCondencedOutputs())
|
||||
{
|
||||
IAEItemStack o = out.copy();
|
||||
o.setStackSize( o.getStackSize() * i );
|
||||
inv.injectItems( o, Actionable.MODULATE, src );
|
||||
}
|
||||
|
||||
crafts += i;
|
||||
}
|
||||
|
||||
public void dive(CraftingJob job)
|
||||
{
|
||||
job.addTask( getAmountCrafted( parent.getStack( 1 ) ), crafts, details, depth );
|
||||
for (CraftingTreeNode pro : nodes.keySet())
|
||||
pro.dive( job );
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package appeng.crafting;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface ICraftingParent
|
||||
{
|
||||
|
||||
Collection<? extends ICraftingParent> getSubJobs();
|
||||
|
||||
void writeToNBT(NBTTagCompound out);
|
||||
|
||||
void removeChild(CraftingTask craftingTask);
|
||||
|
||||
}
|
||||
@@ -11,14 +11,44 @@ import appeng.api.storage.data.IItemList;
|
||||
public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
{
|
||||
|
||||
final MECraftingInventory par;
|
||||
|
||||
final IMEInventory<IAEItemStack> target;
|
||||
final IItemList<IAEItemStack> localCache;
|
||||
|
||||
final boolean logExtracted;
|
||||
final IItemList<IAEItemStack> extractedCache;
|
||||
|
||||
public MECraftingInventory(IMEInventory<IAEItemStack> target) {
|
||||
this.target = target;
|
||||
final boolean logInjections;
|
||||
final IItemList<IAEItemStack> injectedCache;
|
||||
|
||||
final boolean logMissing;
|
||||
final IItemList<IAEItemStack> missingCache;
|
||||
|
||||
public MECraftingInventory(MECraftingInventory parrent) {
|
||||
this.target = parrent;
|
||||
this.logExtracted = parrent.logExtracted;
|
||||
this.logInjections = parrent.logInjections;
|
||||
this.logMissing = parrent.logMissing;
|
||||
|
||||
missingCache = AEApi.instance().storage().createItemList();
|
||||
extractedCache = AEApi.instance().storage().createItemList();
|
||||
injectedCache = AEApi.instance().storage().createItemList();
|
||||
localCache = target.getAvailableItems( AEApi.instance().storage().createItemList() );
|
||||
|
||||
par = parrent;
|
||||
}
|
||||
|
||||
public MECraftingInventory(IMEInventory<IAEItemStack> target, boolean logExtracted, boolean logInjections, boolean logMissing) {
|
||||
this.target = target;
|
||||
this.logExtracted = logExtracted;
|
||||
this.logInjections = logInjections;
|
||||
this.logMissing = logMissing;
|
||||
missingCache = AEApi.instance().storage().createItemList();
|
||||
extractedCache = AEApi.instance().storage().createItemList();
|
||||
injectedCache = AEApi.instance().storage().createItemList();
|
||||
localCache = target.getAvailableItems( AEApi.instance().storage().createItemList() );
|
||||
par = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,8 +57,14 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
if ( input == null )
|
||||
return null;
|
||||
|
||||
if ( mode == Actionable.SIMULATE )
|
||||
// AELog.info( mode.toString() + "Inject: " + input.toString() );
|
||||
|
||||
if ( mode == Actionable.MODULATE )
|
||||
{
|
||||
if ( logInjections )
|
||||
injectedCache.add( input );
|
||||
localCache.add( input );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -39,11 +75,13 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
if ( request == null )
|
||||
return null;
|
||||
|
||||
// AELog.info( mode.toString() + "Extract: " + request.toString() );
|
||||
|
||||
IAEItemStack list = localCache.findPrecise( request );
|
||||
if ( list == null || list.getStackSize() == 0 )
|
||||
return null;
|
||||
|
||||
if ( mode == Actionable.MODULATE )
|
||||
if ( mode == Actionable.MODULATE && logExtracted )
|
||||
extractedCache.add( request );
|
||||
|
||||
if ( list.getStackSize() >= request.getStackSize() )
|
||||
@@ -88,4 +126,34 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
|
||||
}
|
||||
|
||||
public void commit(BaseActionSource src)
|
||||
{
|
||||
if ( logInjections )
|
||||
{
|
||||
for (IAEItemStack injec : injectedCache)
|
||||
target.injectItems( injec, Actionable.MODULATE, src );
|
||||
}
|
||||
|
||||
if ( logExtracted )
|
||||
{
|
||||
for (IAEItemStack extra : extractedCache)
|
||||
target.extractItems( extra, Actionable.MODULATE, src );
|
||||
}
|
||||
|
||||
if ( logMissing && par != null )
|
||||
{
|
||||
for (IAEItemStack extra : missingCache)
|
||||
par.addMissing( extra );
|
||||
}
|
||||
}
|
||||
|
||||
public void addMissing(IAEItemStack extra)
|
||||
{
|
||||
missingCache.add( extra );
|
||||
}
|
||||
|
||||
public void ignore(IAEItemStack what)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user