Index: cookbook.lua ================================================================== --- cookbook.lua +++ cookbook.lua @@ -44,11 +44,11 @@ {0,0}, {1,0}, {2,0}; {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 {} end @@ -151,14 +151,13 @@ return i 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 @@ -195,10 +194,35 @@ cache.grindables[#cache.grindables+1] = k 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'; node = 'xdecor:workbench'; @@ -329,10 +353,64 @@ end 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'; booksuf = 'Grimoire'; @@ -506,11 +584,16 @@ k.w+1.1, k.h/2 - 0.5, minetest.formspec_escape(ot)) 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) local meta = stack:get_meta() Index: data/metals.lua ================================================================== --- data/metals.lua +++ data/metals.lua @@ -233,10 +233,11 @@ fuel = 80; depth = 670; level = 1; no_tools = true; no_armor = true; + no_craftables = true; }; vidrium = { tone = {119,185,221}, alpha = 140; artificial = true; dye = 'cyan'; Index: metal.lua ================================================================== --- metal.lua +++ metal.lua @@ -82,48 +82,59 @@ } sorcery.data.metallookup[fragment] = { id = name; data = metal; value = 1; } - minetest.register_craftitem(screw, { - description = sorcery.lib.str.capitalize(name) .. ' Screw'; - inventory_image = sorcery.lib.image('sorcery_screw.png'):multiply(sorcery.lib.color(metal.tone)):render(); - groups = { metal = 1; sorcery_screw = 1; sorcery_tech_component = 1; }; - _sorcery = { - material = { - id = name, data = metal; - powder = powder; - grindcost = 2, grindvalue = 1; - value = 0.5; + sorcery.data.metallookup[disc] = { + id = name; data = metal; + value = 8/3; + } + if not metal.no_craftables then + sorcery.data.metallookup[screw] = { + id = name; data = metal; + value = 0.5; + } + minetest.register_craftitem(screw, { + description = sorcery.lib.str.capitalize(name) .. ' Screw'; + inventory_image = sorcery.lib.image('sorcery_screw.png'):multiply(sorcery.lib.color(metal.tone)):render(); + groups = { metal = 1; sorcery_screw = 1; sorcery_tech_component = 1; }; + _sorcery = { + material = { + id = name, data = metal; + powder = powder; + grindcost = 2, grindvalue = 1; + value = 0.5; + }; }; - }; - }) + }) + local reglathe = function(ty, sz) + sorcery.lathe.register { + input = ty; + output = {name = screw, count = sz * 2}; + tech = 'cut', cost = 1; + } + end + reglathe(fragment, 1) + reglathe(ingot, 4) + reglathe(block, 4 * 9) + end + minetest.register_craftitem(disc, { description = sorcery.lib.str.capitalize(name) .. ' Disc'; inventory_image = fmt('sorcery_disc_%s.png', name); groups = { metal = 1; sorcery_disc = 1; sorcery_tech_component = 1; }; _sorcery = { material = { id = name, data = metal; powder = powder; - grindvalue = (3*4) / 2; + grindcost = 3; + grindvalue = 2*4; value = 4 * (2/3); }; }; }) - local reglathe = function(ty, sz) - sorcery.lathe.register { - input = ty; - output = {name = screw, count = sz * 2}; - tech = 'cut', cost = 1; - } - end - reglathe(fragment, 1) - reglathe(ingot, 4) - reglathe(block, 4 * 9) - sorcery.lathe.register { input = ingot, mass = 2; output = {name = disc, count = 3}; tech = 'cut', cost = 5; }