@@ -45,9 +45,9 @@ {0,1}, {1,1}, {2,1}; {0,2}, {1,2}, {2,2}; } local props_builtin = function(item) - local props = minetest.registered_items[item]._sorcery + local props = minetest.registered_items[ItemStack(item):get_name()]._sorcery if props and props.recipe then return props.recipe end return {} @@ -152,12 +152,11 @@ end local function desc_builtin(i) local desc i, desc = group_eval(i) - -- print('describing ',i,dump(minetest.registered_items[i])) local s = ItemStack(i) if not minetest.registered_items[s:get_name()] then - minetest.log('WARNING: unknown item in recipe ' .. i) + log.warn('unknown item in recipe',i) return 'Unknown Item' end if not desc then desc = minetest.registered_items[s:get_name()].description end if not desc then return 'Peculiar Item' end @@ -196,8 +195,33 @@ end end end end; + + populate_lathe = function(cache) + if cache.lathe then return end + cache.lathe = { tools = {} } + for k in pairs(sorcery.lathe.techs) do cache.lathe.tools[k] = {} end + + for id, item in pairs(minetest.registered_tools) do + for group, tech in pairs(sorcery.lathe.tools) do + if minetest.get_item_group(id, group) ~= 0 then + local tt = cache.lathe.tools[tech] + local mat = sorcery.itemclass.get(id, 'material') + tt[#tt+1] = { + id = id; + ptr = item; + level = mat and mat.data and (mat.data.maxlevel or mat.data.level) or nil; + } + end + end + end + for _, tech in pairs(sorcery.lathe.tools) do + table.sort(cache.lathe.tools[tech], function(a,b) + return (a.level or 0) < (b.level or 0) + end) + end + end; } sorcery.cookbook.classes = { craft = { name = 'Crafting Guide'; @@ -330,8 +354,62 @@ return {v,''} -- !! end end end; + }; + lathe = { + name = 'Lathe'; + chance = 1; + node = 'sorcery:lathe'; + booksuf = 'Compendium'; + w = 2, h = 1; + slots = { {1,0}, {0,0} }; + apply_exclusions = true; + props = props_builtin; + find = function(out) + cache:populate_lathe() + local mat = sorcery.itemclass.get(out, 'material') + local level = 0 + if mat and mat.data and mat.data.level then + level = mat.data.level + end + for input,tqs in pairs(sorcery.lathe.recipes) do + for tech, defs in pairs(tqs) do + for _, def in pairs(defs) do + if ItemStack(def.output):get_name() == out then + local tool + if level > 0 then + for _,t in pairs(cache.lathe.tools[tech]) do + if (t.level or 0) >= level then + tool = t.id + break + end + end + else + tool = cache.lathe.tools[tech][1].id + end + if def.mass then input = input .. ' ' .. tostring(def.mass) end + local rec = {input, tool or ''} + return rec, {count = ItemStack(def.output):get_count()} + end + end + end + end + end; + pick = function(restrict) + local p = {} + for input,tqs in pairs(sorcery.lathe.recipes) do + for tech, defs in pairs(tqs) do + for _, def in pairs(defs) do + local nm = ItemStack(def.output):get_name() + if item_restrict_eval(nm, restrict) then + p[#p+1] = nm + end + end + end + end + return select(2, sorcery.lib.tbl.pick(p)) + end; }; enchant = { name = 'Enchantment Matrix'; node = 'sorcery:enchanter'; @@ -507,9 +585,14 @@ end; local retrieve_recipe = function(kind,out,notes_right) local rec = recipe_kinds[kind] - local ing = rec.find(out) + local ing, props = rec.find(out) + if props then + if props.count then + out = out .. ' ' .. tostring(props.count) + end + end return render_recipe(kind,ing,out,notes_right), rec.w, rec.h end sorcery.cookbook.setrecipe = function(stack,k,r,restrict)