}
ICraftingPatternDetails details = e.getKey();
if ( canCraft( details, details.getCondensedInputs() ) )
{
InventoryCrafting ic = null;
for (ICraftingMedium m : cc.getMediums( e.getKey() ))
{
if ( e.getValue().value <= 0 )
continue;
if ( !m.isBusy() )
{
if ( ic == null )
{
IAEItemStack[] input = details.getInputs();
double sum = 0;
for (IAEItemStack anInput : input)
{
if ( anInput != null )
{
sum += anInput.getStackSize();
}
}
// power...
if ( eg.extractAEPower( sum, Actionable.MODULATE, PowerMultiplier.CONFIG ) < sum - 0.01 )
continue;
ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
boolean found = false;
for (int x = 0; x < input.length; x++)
{
if ( input[x] != null )
{
found = false;
if ( details.isCraftable() )
{
for (IAEItemStack fuzz : inventory.getItemList().findFuzzy( input[x], FuzzyMode.IGNORE_ALL ))
{
fuzz = fuzz.copy();
fuzz.setStackSize( input[x].getStackSize() );
if ( details.isValidItemForSlot( x, fuzz.getItemStack(), getWorld() ) )
{
IAEItemStack ais = inventory.extractItems( fuzz, Actionable.MODULATE, machineSrc );
ItemStack is = ais == null ? null : ais.getItemStack();
if ( is != null )
{
postChange( AEItemStack.create( is ), machineSrc );
ic.setInventorySlotContents( x, is );
found = true;
break;
}
}
}
}
else
{
IAEItemStack ais = inventory.extractItems( input[x].copy(), Actionable.MODULATE, machineSrc );
ItemStack is = ais == null ? null : ais.getItemStack();
if ( is != null )
{
postChange( input[x], machineSrc );
ic.setInventorySlotContents( x, is );
if ( is.stackSize == input[x].getStackSize() )
{
found = true;
continue;
}
}
}
if ( !found )
break;
}
}
if ( !found )
{
// put stuff back..
for (int x = 0; x < ic.getSizeInventory(); x++)
{
ItemStack is = ic.getStackInSlot( x );
if ( is != null )
inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, machineSrc );
}
ic = null;
break;
}
}
if ( m.pushPattern( details, ic ) )
{
somethingChanged = true;
remainingOperations--;
for (IAEItemStack out : details.getCondensedOutputs())
{
postChange( out, machineSrc );
waitingFor.add( out.copy() );
postCraftingStatusChange( out.copy() );
}
if ( details.isCraftable() )
{
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) getWorld() ),
details.getOutput( ic, getWorld() ), ic );
for (int x = 0; x < ic.getSizeInventory(); x++)
{
ItemStack output = Platform.getContainerItem( ic.getStackInSlot( x ) );
if ( output != null )
{
IAEItemStack cItem = AEItemStack.create( output );
postChange( cItem, machineSrc );
waitingFor.add( cItem );
postCraftingStatusChange( cItem );
}
}
}
ic = null; // hand off complete!
markDirty();
e.getValue().value--;
if ( e.getValue().value <= 0 )
continue;
if ( remainingOperations == 0 )
return;
}
}
}
if ( ic != null )
{
// put stuff back..
for (int x = 0; x < ic.getSizeInventory(); x++)
{
ItemStack is = ic.getStackInSlot( x );
if ( is != null )
{
inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, machineSrc );
}
}