@@ -17,7 +17,7 @@ export function _build(Recipe: typeof PRecipe): CraftingFunc {
1717 target = item . count
1818 ) : { success : boolean ; itemsRequired : Item [ ] ; recipesToDo : Array < { recipeApplications : number ; recipe : PRecipe } > } {
1919 const id = item . id ;
20- const recipes = Recipe . find ( id , null ) ;
20+ let recipes = Recipe . find ( id , null ) ;
2121
2222 const availableItems = opts . availableItems ;
2323 const includeRecursion = opts . includeRecursion ?? false ;
@@ -34,6 +34,10 @@ export function _build(Recipe: typeof PRecipe): CraftingFunc {
3434 recipe : PRecipe ;
3535 } > = [ ] ;
3636
37+ // disregard recipes that combine the item itself back together, as that is pointless for our usecase.
38+ recipes = recipes . filter ( ( r ) => r . delta . slice ( 0 , - 1 ) . some ( ( e ) => e . id !== id ) ) ;
39+
40+
3741 if ( availableItems !== undefined ) {
3842 matchingItem = availableItems . find ( ( e ) => e . id === id && e . count >= target ) ;
3943 if ( matchingItem != null ) {
@@ -53,13 +57,18 @@ export function _build(Recipe: typeof PRecipe): CraftingFunc {
5357 return { success : false , itemsRequired : [ item ] , recipesToDo : [ ] } ;
5458 }
5559
56- seen . set ( id , item ) ;
60+ seen . set ( id , item ) ;
5761
58- recipeWanted = recipes . find ( ( r ) =>
59- r . delta . slice ( 0 , - 1 ) . every ( ( e ) => ( availableItems . find ( ( i ) => i . id === e . id ) ?. count ?? 0 ) >= - e . count )
62+ recipeWanted = recipes . find ( ( r ) => {
63+ if ( r . ingredients != null ) return r . ingredients . every ( e => ( availableItems . find ( i => i . id === e . id ) ?. count ?? 0 ) >= - e . count )
64+ else return r . delta . slice ( 0 , - 1 ) . every ( ( e ) => ( availableItems . find ( ( i ) => i . id === e . id ) ?. count ?? 0 ) >= - e . count )
65+ }
66+
6067 ) ;
6168
69+
6270 if ( recipeWanted != null ) {
71+
6372 } else {
6473 // since no recipes exist with all items available, search for the recipe with the most amount of items available inline
6574
@@ -141,10 +150,10 @@ export function _build(Recipe: typeof PRecipe): CraftingFunc {
141150 for ( const toDo of test . recipesToDo ) {
142151 for ( const ing of toDo . recipe . delta ) {
143152 const index = currentItems . findIndex ( ( e ) => e . id === ing . id ) ;
144- const num = ( currentItems [ index ] ?. count ?? 0 ) + ing . count * toDo . recipeApplications ;
145- if ( num < 0 ) { // this should never happen, but just in case.
146- return { success : false , itemsRequired : [ item ] , recipesToDo : [ ] } ;
147- }
153+ // const num = (currentItems[index]?.count ?? 0) + ing.count * toDo.recipeApplications;
154+ // if (num < 0) { // this should never happen, but just in case.
155+ // return { success: false, itemsRequired: [item], recipesToDo: [] };
156+ // }
148157 if ( index !== - 1 ) {
149158 currentItems [ index ] . count += ing . count * toDo . recipeApplications ;
150159 } else {
@@ -188,7 +197,7 @@ export function _build(Recipe: typeof PRecipe): CraftingFunc {
188197 }
189198 } else {
190199 // TODO : should be replaced by smelting recipe data
191- const found = recipes . find ( ( r ) => r . result . count >= 1 ) ;
200+ const found = recipes . find ( ( r ) => r . result . count > 1 ) ;
192201 recipeWanted = found ?? recipes [ 0 ] ;
193202
194203 if ( recipes . length == 0 || gettableItems . includes ( id ) ) {
@@ -257,6 +266,8 @@ export function _build(Recipe: typeof PRecipe): CraftingFunc {
257266
258267 const ret = _newCraft ( item , opts , seen ) ;
259268
269+ console . log ( 'internal' , ret )
270+
260271 const availableItems = opts . availableItems ;
261272
262273 const ret1 = ret as CraftingPlan ;
0 commit comments