Crafting is virtually working 100%

This commit is contained in:
AlgorithmX2
2014-06-22 02:00:38 -05:00
parent 65e9e272c4
commit ff9a10b926
14 changed files with 323 additions and 68 deletions
+58 -14
View File
@@ -4,25 +4,32 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import appeng.api.AEApi;
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.container.ContainerNull;
import appeng.me.cache.CraftingCache;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.util.Platform;
import cpw.mods.fml.common.FMLCommonHandler;
public class CraftingTreeProcess
{
World world;
CraftingTreeNode parent;
ICraftingPatternDetails details;
CraftingJob job;
long crafts = 0;
boolean damageable;
boolean fullsimulation;
final private int depth;
@@ -34,19 +41,36 @@ public class CraftingTreeProcess
this.details = details;
this.job = job;
this.depth = depth;
world = job.getWorld();
if ( details.isCraftable() )
{
IAEItemStack list[] = details.getInputs();
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
IAEItemStack[] is = details.getInputs();
for (int x = 0; x < ic.getSizeInventory(); x++)
ic.setInventorySlotContents( x, is[x] == null ? null : is[x].getItemStack() );
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) world ), details.getOutput( ic, world ), ic );
for (int x = 0; x < ic.getSizeInventory(); x++)
{
ItemStack g = ic.getStackInSlot( x );
if ( g != null && g.stackSize > 1 )
fullsimulation = true;
}
for (int x = 0; x < list.length; x++)
{
IAEItemStack part = list[x];
if ( part != null )
{
ItemStack is = part.getItemStack();
if ( is.getItem().hasContainerItem( is ) )
ItemStack g = part.getItemStack();
if ( g.getItem().hasContainerItem( g ) )
damageable = true;
nodes.put( new CraftingTreeNode( cc, job, part.copy(), this, x, depth + 1 ), part.getStackSize() );
}
}
@@ -67,7 +91,7 @@ public class CraftingTreeProcess
long getTimes(long remaining, long stackSize)
{
if ( damageable )
if ( damageable || fullsimulation )
return 1;
return (remaining / stackSize) + (remaining % stackSize != 0 ? 1 : 0);
}
@@ -92,21 +116,41 @@ public class CraftingTreeProcess
if ( Thread.interrupted() )
throw new InterruptedException();
// request and remove inputs...
for (Entry<CraftingTreeNode, Long> entry : nodes.entrySet())
if ( fullsimulation )
{
IAEItemStack item = entry.getKey().getStack( entry.getValue() );
IAEItemStack stack = entry.getKey().request( inv, item.getStackSize() * i, src );
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
if ( damageable )
for (Entry<CraftingTreeNode, Long> entry : nodes.entrySet())
{
ItemStack is = stack.getItemStack();
if ( stack.getItem().hasContainerItem( is ) )
{
is = stack.getItem().getContainerItem( is );
if ( is.isItemStackDamageable() && is.getItemDamage() == is.getMaxDamage() )
is = null;
IAEItemStack item = entry.getKey().getStack( entry.getValue() );
IAEItemStack stack = entry.getKey().request( inv, item.getStackSize(), src );
ic.setInventorySlotContents( entry.getKey().slot, stack.getItemStack() );
}
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) world ), details.getOutput( ic, world ), ic );
for (int x = 0; x < ic.getSizeInventory(); x++)
{
ItemStack is = ic.getStackInSlot( x );
is = Platform.getContainerItem( is );
IAEItemStack o = AEApi.instance().storage().createItemStack( is );
if ( o != null )
inv.injectItems( o, Actionable.MODULATE, src );
}
}
else
{
// request and remove inputs...
for (Entry<CraftingTreeNode, Long> entry : nodes.entrySet())
{
IAEItemStack item = entry.getKey().getStack( entry.getValue() );
IAEItemStack stack = entry.getKey().request( inv, item.getStackSize() * i, src );
if ( damageable )
{
ItemStack is = Platform.getContainerItem( stack.getItemStack() );
IAEItemStack o = AEApi.instance().storage().createItemStack( is );
if ( o != null )
inv.injectItems( o, Actionable.MODULATE, src );