diff --git a/helpers/DualityInterface.java b/helpers/DualityInterface.java index c6fa66984..d6eafc6a6 100644 --- a/helpers/DualityInterface.java +++ b/helpers/DualityInterface.java @@ -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 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 ); + } } } diff --git a/helpers/PatternHelper.java b/helpers/PatternHelper.java index 08e9cbfa9..70d7ccc3c 100644 --- a/helpers/PatternHelper.java +++ b/helpers/PatternHelper.java @@ -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 in = new ArrayList(); List 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 ) )