@@ -81,22 +81,43 @@ end end return names[math.random(#names)] end end -local find_builtin = function(out) - local rec = {} - local i = minetest.get_craft_recipe(out) - if i == nil or i.items == nil or #i.items == 0 then return nil end - local w = (i.width == 0) and 3 or i.width - -- for j=1,#i.items do - for j,item in pairs(i.items) do - local row = math.floor((j-1) / w) - local col = (j-1) % w - if i.items[j] then - rec[1 + (row * 3) + col] = i.items[j] +local find_builtin = function(method,kind) + return function(out) + local rec = {} + local crec = sorcery.lib.tbl.walk(minetest.registered_items[out],{'_sorcery','recipe','canonical',kind}) + local w=0, lst + if crec then + lst = {} + for i,v in pairs(crec) do + if #v > w then w = #v end + for j,n in pairs(v) do + lst[#lst+1] = n + end + end + else + -- WHY IS THIS INTERFACE SO CLUMSY + local all,i = minetest.get_all_craft_recipes(out), nil + for _,r in pairs(all) do + if r.method == method and r.items and #r.items>0 then + i = r break + end + end + if i == nil or i.items == nil or #i.items == 0 then return nil end + w = (i.width == 0) and 3 or i.width + lst = i.items + end + -- for j=1,#i.items do + for j,item in pairs(lst) do + local row = math.floor((j-1) / w) + local col = (j-1) % w + if item then + rec[1 + (row * 3) + col] = item + end end + return rec end - return rec end local function group_eval(i) if string.sub(i,1,6) == 'group:' then local g = string.sub(i,7) @@ -167,9 +188,9 @@ w = 3, h = 3; chance = 2; slots = slot3x3; pick = pick_builtin('normal'); - find = find_builtin; + find = find_builtin('normal','craft'); props = props_builtin; apply_exclusions = true; }; -- smelt = { @@ -183,9 +204,9 @@ w = 1, h = 1; chance = 3; slots = {{-0.2,0}}; pick = pick_builtin('cooking'); - find = find_builtin; + find = find_builtin('cooking','cook'); props = props_builtin; apply_exclusions = true; }; infuse = { @@ -359,17 +380,19 @@ local render_recipe = function(kind,ingredients,result,notes_right) local k = recipe_kinds[kind] local t = '' + local props = k.props(result) for i=1,#k.slots do + local ing = ingredients[i] local x, y = k.slots[i][1], k.slots[i][2] - if ingredients[i] and ingredients[i] ~= '' then + if ing and ing ~= '' then local tt - if k.indesc then tt = k.indesc(ingredients[i]) else tt = desc_builtin(ingredients[i]) end + if k.indesc then tt = k.indesc(ing) else tt = desc_builtin(ing) end t = t .. string.format([[ item_image[%f,%f;1,1;%s] tooltip[%f,%f;1,1;%s] - ]], x,y, minetest.formspec_escape(group_eval(ingredients[i])), + ]], x,y, minetest.formspec_escape(group_eval(ing)), x,y, minetest.formspec_escape(tt)) else if k.drawslots == nil or k.drawslots then t = string.format('box[%f,%f;0.1,0.1;#00000060]',x+0.45,y+0.45) .. t @@ -376,9 +399,8 @@ end end end local img, ot - local props = k.props(result) if props.note then local nx, ny, nw, nh if notes_right then nx = 5.25 ny = 0