@@ -17,7 +17,7 @@ public class RecursiveCraft : Mod
1717 {
1818 public static Dictionary < int , List < Recipe > > RecipeByResult ;
1919 public static Dictionary < Recipe , RecipeInfo > RecipeCache ;
20- public static CompoundRecipe CurrentCompound ;
20+ public static CompoundRecipe CompoundRecipe ;
2121
2222 public static int DepthSearch ;
2323 public static bool InventoryWasOpen ;
@@ -28,7 +28,6 @@ public override void Load()
2828 ILRecipe . FindRecipes += ApplyRecursiveSearch ;
2929 OnMain . DrawInventory += EditFocusRecipe ;
3030 OnMain . Update += ApplyKey ;
31- On . Terraria . Recipe . Create += CraftCompoundRecipe ;
3231 RecipeByResult = new Dictionary < int , List < Recipe > > ( ) ;
3332 RecipeCache = new Dictionary < Recipe , RecipeInfo > ( ) ;
3433
@@ -46,18 +45,19 @@ public override void Unload()
4645 ILRecipe . FindRecipes -= ApplyRecursiveSearch ;
4746 OnMain . DrawInventory -= EditFocusRecipe ;
4847 OnMain . Update -= ApplyKey ;
49- On . Terraria . Recipe . Create -= CraftCompoundRecipe ;
5048 RecipeByResult = null ;
5149 RecipeCache = null ;
5250 Hotkeys = null ;
5351
54- if ( CurrentCompound != null )
55- Main . recipe [ CurrentCompound . RecipeId ] = CurrentCompound . OverridenRecipe ;
56- CurrentCompound = null ;
52+ if ( CompoundRecipe . OverridenRecipe != null )
53+ Main . recipe [ CompoundRecipe . RecipeId ] = CompoundRecipe . OverridenRecipe ;
54+ CompoundRecipe = null ;
5755 }
5856
5957 public override void PostAddRecipes ( )
6058 {
59+ CompoundRecipe = new CompoundRecipe ( this ) ;
60+
6161 foreach ( Recipe recipe in Main . recipe )
6262 {
6363 int type = recipe . createItem . type ;
@@ -71,21 +71,6 @@ public override void PostAddRecipes()
7171 }
7272 }
7373
74- public static void CraftCompoundRecipe ( On . Terraria . Recipe . orig_Create orig , Recipe self )
75- {
76- if ( CurrentCompound != null && self == CurrentCompound . CurrentRecipe )
77- {
78- CurrentCompound . BeforeCraft ( ) ;
79- orig ( self ) ;
80- CurrentCompound . OnCraft ( ) ;
81- Recipe . FindRecipes ( ) ;
82- }
83- else
84- {
85- orig ( self ) ;
86- }
87- }
88-
8974 public void ApplyKey ( OnMain . orig_Update orig , Main self , GameTime gameTime )
9075 {
9176 if ( InventoryWasOpen != Main . playerInventory )
@@ -131,17 +116,17 @@ public void ApplyKey(OnMain.orig_Update orig, Main self, GameTime gameTime)
131116
132117 public static void EditFocusRecipe ( OnMain . orig_DrawInventory orig , Main self )
133118 {
134- if ( CurrentCompound != null ) Main . recipe [ CurrentCompound . RecipeId ] = CurrentCompound . OverridenRecipe ;
119+ if ( CompoundRecipe . OverridenRecipe != null ) Main . recipe [ CompoundRecipe . RecipeId ] = CompoundRecipe . OverridenRecipe ;
135120 int i = Main . availableRecipe [ Main . focusRecipe ] ;
136121 Recipe recipe = Main . recipe [ i ] ;
137122 if ( RecipeCache . TryGetValue ( recipe , out RecipeInfo recipeInfo ) )
138123 {
139- CurrentCompound = new CompoundRecipe ( i , recipeInfo ) ;
140- Main . recipe [ i ] = CurrentCompound . CurrentRecipe ;
124+ CompoundRecipe . Apply ( i , recipeInfo ) ;
125+ Main . recipe [ i ] = CompoundRecipe ;
141126 }
142127 else
143128 {
144- CurrentCompound = null ;
129+ CompoundRecipe . OverridenRecipe = null ;
145130 }
146131
147132 orig ( self ) ;
@@ -179,7 +164,9 @@ public static void RecursiveSearch(Dictionary<int, int> inventory)
179164 CraftingSource craftingSource = new PlayerAsCraftingSource ( ) ;
180165 for ( int n = 0 ; n < Recipe . maxRecipes && Main . recipe [ n ] . createItem . type != ItemID . None ; n ++ )
181166 {
182- Recipe recipe = CurrentCompound ? . RecipeId == n ? CurrentCompound . OverridenRecipe : Main . recipe [ n ] ;
167+ Recipe recipe = Main . recipe [ n ] ;
168+ if ( recipe is CompoundRecipe compoundRecipe )
169+ recipe = compoundRecipe . OverridenRecipe ;
183170 RecipeInfo recipeInfo = FindIngredientsForRecipe ( inventory , craftingSource , recipe ) ;
184171 if ( recipeInfo != null )
185172 {
@@ -258,7 +245,7 @@ public static int AmountOfDoableRecipe(ref Dictionary<int, int> inventoryToUse,
258245 int trueIngredientsNeeded = trueTimeCraft * ingredient . stack ;
259246 if ( recipe . alchemy && craftingSource . AlchemyTable )
260247 for ( int i = 0 ; i < trueTimeCraft ; i ++ )
261- if ( Main . rand . Next ( 3 ) == 0 )
248+ if ( Main . rand . Next ( 3 ) == 0 )
262249 trueIngredientsNeeded -= ingredient . stack ;
263250
264251 #region UseIngredients
0 commit comments