Pattern registration still a work in progress.

This commit is contained in:
AlgorithmX2 2014-05-19 23:13:43 -05:00
parent fa1feff8f0
commit db8c29a9b4
2 changed files with 31 additions and 20 deletions

View file

@ -24,7 +24,7 @@ import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.crafting.ICraftingProvider;
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.events.MECraftingPatternUpdate;
import appeng.api.networking.events.MENetworkCraftingPatternChange;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.MachineSource;
import appeng.api.networking.ticking.IGridTickable;
@ -81,7 +81,10 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
public void updateCraftingList()
{
Boolean accountedFor[] = new Boolean[patterns.getSizeInventory()];
Boolean accountedFor[] = new Boolean[] { false, false, false, false, false, false, false, false, false }; // 9...
assert (accountedFor.length == patterns.getSizeInventory());
if ( craftingList != null )
{
Iterator<ICraftingPatternDetails> i = craftingList.iterator();
@ -109,6 +112,15 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
if ( accountedFor[x] == false )
addToCraftingList( patterns.getStackInSlot( x ) );
}
try
{
gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, gridProxy.getNode() ) );
}
catch (GridAccessException e)
{
// :P
}
}
public void addToCraftingList(ItemStack is)
@ -460,16 +472,7 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
if ( inv == config )
readConfig();
else if ( inv == patterns )
{
try
{
gridProxy.getGrid().postEvent( new MECraftingPatternUpdate( this ) );
}
catch (GridAccessException e)
{
// :P
}
}
updateCraftingList();
else if ( inv == storage && slot >= 0 )
{
boolean had = hasWorkToDo();
@ -704,8 +707,11 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
@Override
public void provideCrafting(ICraftingProviderHelper craftingTracker)
{
for (ICraftingPatternDetails details : craftingList)
craftingTracker.addCraftingOption( this, details );
if ( craftingList != null )
{
for (ICraftingPatternDetails details : craftingList)
craftingTracker.addCraftingOption( this, details );
}
}
}

View file

@ -114,9 +114,6 @@ public class PatternHelper implements ICraftingPatternDetails
isCrafting = encodedValue.getBoolean( "crafting" );
patternItem = is;
if ( isCrafting == false )
throw new RuntimeException( "Only crafting recipes supported." );
List<IAEItemStack> in = new ArrayList();
List<IAEItemStack> out = new ArrayList();
@ -134,15 +131,17 @@ public class PatternHelper implements ICraftingPatternDetails
testFrame.setInventorySlotContents( x, gs );
}
standardRecipe = Platform.findMatchingRecipe( crafting, w );
correctOutput = standardRecipe.getCraftingResult( crafting );
if ( isCrafting )
{
standardRecipe = Platform.findMatchingRecipe( crafting, w );
correctOutput = standardRecipe.getCraftingResult( crafting );
out.add( AEApi.instance().storage().createItemStack( correctOutput ) );
}
else
{
standardRecipe = null;
correctOutput = null;
for (int x = 0; x < outTag.tagCount(); x++)
{
ItemStack gs = ItemStack.loadItemStackFromNBT( inTag.getCompoundTagAt( x ) );
@ -158,6 +157,9 @@ public class PatternHelper implements ICraftingPatternDetails
public boolean isValidItemForSlot(int slotIndex, ItemStack i, World w)
{
if ( isCrafting == false )
throw new RuntimeException( "Only crafting recipes supported." );
TestStatus result = getStatus( slotIndex, i );
switch (result)
@ -209,6 +211,9 @@ public class PatternHelper implements ICraftingPatternDetails
@Override
public ItemStack getOutput(InventoryCrafting craftingInv, World w)
{
if ( isCrafting == false )
throw new RuntimeException( "Only crafting recipes supported." );
for (int x = 0; x < craftingInv.getSizeInventory(); x++)
{
if ( !isValidItemForSlot( x, craftingInv.getStackInSlot( x ), w ) )