@@ -89,6 +89,38 @@ def format_crafting_recipe_from_data(context: Context, buffer: List[str], identi
8989 ))
9090
9191
92+ def extract_items_from_ingredient (data : Any ) -> List [str ]:
93+ """
94+ Recursively extract item/tag names from an ingredient.
95+ Returns a list of item names (e.g., ['minecraft:stone'] or ['#minecraft:planks'])
96+ """
97+ if 'item' in data :
98+ return [data ['item' ]]
99+ elif 'tag' in data :
100+ return ['#' + data ['tag' ]]
101+ elif 'type' in data and data ['type' ] in ('tfc:not_rotten' , 'tfc:has_trait' , 'tfc:lacks_trait' ):
102+ # These types wrap another ingredient
103+ if 'ingredient' in data :
104+ return extract_items_from_ingredient (data ['ingredient' ])
105+ else :
106+ # If no nested ingredient, return empty (just a filter)
107+ return []
108+ elif 'type' in data and (data ['type' ] == 'tfc:and' or data ['type' ] == 'neoforge:compound' ):
109+ # Recursively extract from all children
110+ items = []
111+ for child in data ['children' ]:
112+ items .extend (extract_items_from_ingredient (child ))
113+ return items
114+ elif isinstance (data , list ):
115+ items = []
116+ for item in data :
117+ items .extend (extract_items_from_ingredient (item ))
118+ return items
119+ else :
120+ # Unknown format, return empty
121+ return []
122+
123+
92124def format_ingredient (context : Context , data : Any ) -> Tuple [str , str | None ]:
93125 if 'item' in data :
94126 return item_loader .get_item_image (context , data ['item' ])
@@ -105,17 +137,23 @@ def format_ingredient(context: Context, data: Any) -> Tuple[str, str | None]:
105137 # Handle any fluid using the fluid bucket image with colorization
106138 return fluid_loader .get_fluid_bucket_image (context , data ['fluid' ])
107139 elif 'type' in data and (data ['type' ] == 'tfc:and' or data ['type' ] == 'neoforge:compound' ):
108- csvstring = ''
109- for i in data ['children' ]:
110- if 'item' in i :
111- csvstring += ',' + str (i ['item' ])
112- return item_loader .get_item_image (context , csvstring )
113- elif isinstance (data , List ):
114- csvstring = ''
115- for i in data :
116- if 'item' in i :
117- csvstring += ',' + str (i ['item' ])
118- return item_loader .get_item_image (context , csvstring )
140+ # Extract all item/tag names from children recursively
141+ items = extract_items_from_ingredient (data )
142+ if items :
143+ csvstring = ',' .join (items )
144+ return item_loader .get_item_image (context , csvstring )
145+ else :
146+ # Fallback to placeholder
147+ return ('../../_images/placeholder_64.png' , None )
148+ elif isinstance (data , list ):
149+ # Extract all item/tag names from list recursively
150+ items = extract_items_from_ingredient (data )
151+ if items :
152+ csvstring = ',' .join (items )
153+ return item_loader .get_item_image (context , csvstring )
154+ else :
155+ # Fallback to placeholder
156+ return ('../../_images/placeholder_64.png' , None )
119157 else :
120158 util .error ('Unsupported ingredient: %s' % str (data ))
121159
0 commit comments