Crafting calculator now supports damageable items, and ore dictionary stuff in primitive form.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package appeng.crafting;
|
package appeng.crafting;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -54,6 +55,13 @@ public class CraftingJob
|
|||||||
Stopwatch timer = Stopwatch.createStarted();
|
Stopwatch timer = Stopwatch.createStarted();
|
||||||
tree.request( meci, what.getStackSize(), host.getActionSrc() );
|
tree.request( meci, what.getStackSize(), host.getActionSrc() );
|
||||||
tree.dive( this );
|
tree.dive( this );
|
||||||
|
|
||||||
|
for (String s : opsAndMultiplier.keySet())
|
||||||
|
{
|
||||||
|
twoIntegers ti = opsAndMultiplier.get( s );
|
||||||
|
AELog.info( s + " * " + ti.times + " = " + (ti.perOp * ti.times) );
|
||||||
|
}
|
||||||
|
|
||||||
AELog.info( "-------------" + timer.elapsed( TimeUnit.MILLISECONDS ) + "ms" );
|
AELog.info( "-------------" + timer.elapsed( TimeUnit.MILLISECONDS ) + "ms" );
|
||||||
// if ( mode == Actionable.MODULATE )
|
// if ( mode == Actionable.MODULATE )
|
||||||
// meci.moveItemsToStorage( storage );
|
// meci.moveItemsToStorage( storage );
|
||||||
@@ -70,7 +78,7 @@ public class CraftingJob
|
|||||||
|
|
||||||
private CraftingTreeNode getCraftingTree(CraftingCache cc, IAEItemStack what)
|
private CraftingTreeNode getCraftingTree(CraftingCache cc, IAEItemStack what)
|
||||||
{
|
{
|
||||||
return new CraftingTreeNode( cc, this, what, null, 0 );
|
return new CraftingTreeNode( cc, this, what, null, -1, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound out)
|
public void writeToNBT(NBTTagCompound out)
|
||||||
@@ -78,18 +86,35 @@ public class CraftingJob
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTask(IAEItemStack what, int crafts, ICraftingPatternDetails details, int depth)
|
public void addTask(IAEItemStack what, long crafts, ICraftingPatternDetails details, int depth)
|
||||||
{
|
{
|
||||||
if ( crafts > 0 )
|
if ( crafts > 0 )
|
||||||
{
|
{
|
||||||
AELog.info( "new task: " + Platform.getItemDisplayName( what ) + " x " + what.getStackSize() + " * " + crafts + " = "
|
postOp( "new task: " + Platform.getItemDisplayName( what ) + " x " + what.getStackSize(), what.getStackSize(), crafts );
|
||||||
+ (what.getStackSize() * crafts) + " @ " + depth );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMissing(IAEItemStack what)
|
public void addMissing(IAEItemStack what)
|
||||||
{
|
{
|
||||||
AELog.info( "required material: " + Platform.getItemDisplayName( what ) + " x " + what.getStackSize() );
|
postOp( "required material: " + Platform.getItemDisplayName( what ), 1, what.getStackSize() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class twoIntegers
|
||||||
|
{
|
||||||
|
|
||||||
|
public long perOp = 0;
|
||||||
|
public long times = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
HashMap<String, twoIntegers> opsAndMultiplier = new HashMap();
|
||||||
|
|
||||||
|
private void postOp(String string, long stackSize, long crafts)
|
||||||
|
{
|
||||||
|
twoIntegers ti = opsAndMultiplier.get( string );
|
||||||
|
if ( ti == null )
|
||||||
|
opsAndMultiplier.put( string, ti = new twoIntegers() );
|
||||||
|
|
||||||
|
ti.perOp = stackSize;
|
||||||
|
ti.times += crafts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package appeng.crafting;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import net.minecraft.world.World;
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
|
import appeng.api.config.FuzzyMode;
|
||||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||||
import appeng.api.networking.security.BaseActionSource;
|
import appeng.api.networking.security.BaseActionSource;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
@@ -13,6 +15,10 @@ public class CraftingTreeNode
|
|||||||
|
|
||||||
// parent node.
|
// parent node.
|
||||||
private CraftingTreeProcess parent;
|
private CraftingTreeProcess parent;
|
||||||
|
private World world;
|
||||||
|
|
||||||
|
// what slot!
|
||||||
|
int slot;
|
||||||
|
|
||||||
// what item is this?
|
// what item is this?
|
||||||
private IAEItemStack what;
|
private IAEItemStack what;
|
||||||
@@ -21,16 +27,18 @@ public class CraftingTreeNode
|
|||||||
private ArrayList<CraftingTreeProcess> nodes = new ArrayList();
|
private ArrayList<CraftingTreeProcess> nodes = new ArrayList();
|
||||||
|
|
||||||
boolean cannotUse = false;
|
boolean cannotUse = false;
|
||||||
int missing = 0;
|
long missing = 0;
|
||||||
|
|
||||||
public CraftingTreeNode(CraftingCache cc, CraftingJob job, IAEItemStack wat, CraftingTreeProcess par, int depth) {
|
public CraftingTreeNode(CraftingCache cc, CraftingJob job, IAEItemStack wat, CraftingTreeProcess par, int slot, int depth) {
|
||||||
what = wat;
|
what = wat;
|
||||||
parent = par;
|
parent = par;
|
||||||
|
this.slot = slot;
|
||||||
|
this.world = job.jobHost.getWorld();
|
||||||
|
|
||||||
for (ICraftingPatternDetails details : cc.getCraftingFor( what ))// in order.
|
for (ICraftingPatternDetails details : cc.getCraftingFor( what ))// in order.
|
||||||
{
|
{
|
||||||
if ( notRecurive( details ) )
|
if ( notRecurive( details ) )
|
||||||
nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1 ) );
|
nodes.add( new CraftingTreeProcess( cc, job, details, this, depth + 1, world ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,21 +62,41 @@ public class CraftingTreeNode
|
|||||||
return parent.notRecurive( details );
|
return parent.notRecurive( details );
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getTimes(long remaining, long stackSize)
|
public IAEItemStack request(MECraftingInventory inv, long l, BaseActionSource src) throws CraftBranchFailure
|
||||||
{
|
|
||||||
return (remaining / stackSize) + (remaining % stackSize != 0 ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void request(MECraftingInventory inv, long l, BaseActionSource src) throws CraftBranchFailure
|
|
||||||
{
|
{
|
||||||
what.setStackSize( l );
|
what.setStackSize( l );
|
||||||
IAEItemStack available = inv.extractItems( what, Actionable.MODULATE, src );
|
if ( slot >= 0 && parent != null && parent.details.isCraftable() )
|
||||||
|
{
|
||||||
|
for (IAEItemStack fuzz : inv.getItemList().findFuzzy( what, FuzzyMode.IGNORE_ALL ))
|
||||||
|
{
|
||||||
|
if ( parent.details.isValidItemForSlot( slot, fuzz.getItemStack(), world ) )
|
||||||
|
{
|
||||||
|
fuzz = fuzz.copy();
|
||||||
|
fuzz.setStackSize( l );
|
||||||
|
IAEItemStack available = inv.extractItems( fuzz, Actionable.MODULATE, src );
|
||||||
|
|
||||||
if ( available != null )
|
if ( available != null )
|
||||||
l -= available.getStackSize();
|
{
|
||||||
|
l -= available.getStackSize();
|
||||||
|
|
||||||
if ( l == 0 )
|
if ( l == 0 )
|
||||||
return;
|
return available;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IAEItemStack available = inv.extractItems( what, Actionable.MODULATE, src );
|
||||||
|
|
||||||
|
if ( available != null )
|
||||||
|
{
|
||||||
|
l -= available.getStackSize();
|
||||||
|
|
||||||
|
if ( l == 0 )
|
||||||
|
return available;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( nodes.size() == 1 )
|
if ( nodes.size() == 1 )
|
||||||
{
|
{
|
||||||
@@ -76,17 +104,17 @@ public class CraftingTreeNode
|
|||||||
|
|
||||||
while (pro.possible && l > 0)
|
while (pro.possible && l > 0)
|
||||||
{
|
{
|
||||||
pro.request( inv, getTimes( l, pro.getAmountCrafted( what ).getStackSize() ), src );
|
pro.request( inv, pro.getTimes( l, pro.getAmountCrafted( what ).getStackSize() ), src );
|
||||||
|
|
||||||
what.setStackSize( l );
|
what.setStackSize( l );
|
||||||
available = inv.extractItems( what, Actionable.MODULATE, src );
|
IAEItemStack available = inv.extractItems( what, Actionable.MODULATE, src );
|
||||||
|
|
||||||
if ( available != null )
|
if ( available != null )
|
||||||
{
|
{
|
||||||
l -= available.getStackSize();
|
l -= available.getStackSize();
|
||||||
|
|
||||||
if ( l <= 0 )
|
if ( l <= 0 )
|
||||||
return;
|
return available;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pro.possible = false; // ;P
|
pro.possible = false; // ;P
|
||||||
@@ -105,14 +133,14 @@ public class CraftingTreeNode
|
|||||||
subInv.commit( src );
|
subInv.commit( src );
|
||||||
|
|
||||||
what.setStackSize( l );
|
what.setStackSize( l );
|
||||||
available = inv.extractItems( what, Actionable.MODULATE, src );
|
IAEItemStack available = inv.extractItems( what, Actionable.MODULATE, src );
|
||||||
|
|
||||||
if ( available != null )
|
if ( available != null )
|
||||||
{
|
{
|
||||||
l -= available.getStackSize();
|
l -= available.getStackSize();
|
||||||
|
|
||||||
if ( l <= 0 )
|
if ( l <= 0 )
|
||||||
return;
|
return available;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pro.possible = false; // ;P
|
pro.possible = false; // ;P
|
||||||
@@ -126,6 +154,7 @@ public class CraftingTreeNode
|
|||||||
}
|
}
|
||||||
|
|
||||||
missing += l;
|
missing += l;
|
||||||
|
return what;
|
||||||
// throw new CraftBranchFailure( what, l );
|
// throw new CraftBranchFailure( what, l );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||||
import appeng.api.networking.security.BaseActionSource;
|
import appeng.api.networking.security.BaseActionSource;
|
||||||
@@ -17,20 +20,43 @@ public class CraftingTreeProcess
|
|||||||
ICraftingPatternDetails details;
|
ICraftingPatternDetails details;
|
||||||
CraftingJob job;
|
CraftingJob job;
|
||||||
|
|
||||||
int crafts = 0;
|
long crafts = 0;
|
||||||
|
boolean damageable;
|
||||||
|
|
||||||
final private int depth;
|
final private int depth;
|
||||||
|
|
||||||
Map<CraftingTreeNode, Long> nodes = new HashMap();
|
Map<CraftingTreeNode, Long> nodes = new HashMap();
|
||||||
public boolean possible = true;
|
public boolean possible = true;
|
||||||
|
|
||||||
public CraftingTreeProcess(CraftingCache cc, CraftingJob job, ICraftingPatternDetails details, CraftingTreeNode craftingTreeNode, int depth) {
|
public CraftingTreeProcess(CraftingCache cc, CraftingJob job, ICraftingPatternDetails details, CraftingTreeNode craftingTreeNode, int depth, World world) {
|
||||||
parent = craftingTreeNode;
|
parent = craftingTreeNode;
|
||||||
this.details = details;
|
this.details = details;
|
||||||
this.job = job;
|
this.job = job;
|
||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
|
|
||||||
for (IAEItemStack part : details.getCondencedInputs())
|
if ( details.isCraftable() )
|
||||||
nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, depth + 1 ), part.getStackSize() );
|
{
|
||||||
|
IAEItemStack list[] = details.getInputs();
|
||||||
|
|
||||||
|
for (int x = 0; x < list.length; x++)
|
||||||
|
{
|
||||||
|
IAEItemStack part = list[x];
|
||||||
|
if ( part != null )
|
||||||
|
{
|
||||||
|
ItemStack is = part.getItemStack();
|
||||||
|
if ( is.getItem().hasContainerItem( is ) )
|
||||||
|
damageable = true;
|
||||||
|
nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (IAEItemStack part : details.getCondencedInputs())
|
||||||
|
{
|
||||||
|
nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, -1, depth + 1 ), part.getStackSize() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean notRecurive(ICraftingPatternDetails details)
|
public boolean notRecurive(ICraftingPatternDetails details)
|
||||||
@@ -38,6 +64,13 @@ public class CraftingTreeProcess
|
|||||||
return parent.notRecurive( details );
|
return parent.notRecurive( details );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long getTimes(long remaining, long stackSize)
|
||||||
|
{
|
||||||
|
if ( damageable )
|
||||||
|
return 1;
|
||||||
|
return (remaining / stackSize) + (remaining % stackSize != 0 ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
IAEItemStack getAmountCrafted(IAEItemStack what2)
|
IAEItemStack getAmountCrafted(IAEItemStack what2)
|
||||||
{
|
{
|
||||||
for (IAEItemStack is : details.getCondencedOutputs())
|
for (IAEItemStack is : details.getCondencedOutputs())
|
||||||
@@ -59,7 +92,22 @@ public class CraftingTreeProcess
|
|||||||
for (Entry<CraftingTreeNode, Long> entry : nodes.entrySet())
|
for (Entry<CraftingTreeNode, Long> entry : nodes.entrySet())
|
||||||
{
|
{
|
||||||
IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
IAEItemStack item = entry.getKey().getStack( entry.getValue() );
|
||||||
entry.getKey().request( inv, item.getStackSize() * i, src );
|
IAEItemStack stack = entry.getKey().request( inv, item.getStackSize() * i, src );
|
||||||
|
|
||||||
|
if ( damageable )
|
||||||
|
{
|
||||||
|
ItemStack is = stack.getItemStack();
|
||||||
|
if ( stack.getItem().hasContainerItem( is ) )
|
||||||
|
{
|
||||||
|
is = stack.getItem().getContainerItem( is );
|
||||||
|
if ( is.isItemStackDamageable() && is.getItemDamage() == is.getMaxDamage() )
|
||||||
|
is = null;
|
||||||
|
|
||||||
|
IAEItemStack o = AEApi.instance().storage().createItemStack( is );
|
||||||
|
if ( o != null )
|
||||||
|
inv.injectItems( o, Actionable.MODULATE, src );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// assume its possible.
|
// assume its possible.
|
||||||
|
|||||||
@@ -198,7 +198,10 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||||||
public boolean isValidItemForSlot(int slotIndex, ItemStack i, World w)
|
public boolean isValidItemForSlot(int slotIndex, ItemStack i, World w)
|
||||||
{
|
{
|
||||||
if ( isCrafting == false )
|
if ( isCrafting == false )
|
||||||
|
{
|
||||||
|
|
||||||
throw new RuntimeException( "Only crafting recipes supported." );
|
throw new RuntimeException( "Only crafting recipes supported." );
|
||||||
|
}
|
||||||
|
|
||||||
TestStatus result = getStatus( slotIndex, i );
|
TestStatus result = getStatus( slotIndex, i );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user