@@ -16,8 +16,47 @@ if not rs then recipes[def.input][def.tech] = { def } else rs[#rs+1] = def end + end; + register_metal = function(def) + local parts = sorcery.data.metals[def.metal].parts + local out = ItemStack(def.output) + for _, ty in pairs {'ingot', 'block', 'fragment'} do + local pt = parts[ty] + local ptc = sorcery.itemclass.get(pt, 'metal') + if ptc and ptc.value then + if def.mass <= ptc.value then + local mass + local vfc = ptc.value / def.mass + if math.floor(vfc) ~= vfc then + for i = 1, 50 do + local v = vfc * i + if math.floor(v) == v then + mass = i + vfc = v + break + end + end + else + mass = 1 + end + if not mass then + log.err('tried to register a lathe metal recipe for',def.output,'but the mass ratio',vfc,'for part',ty,'has too many digits to the right of the decimal place') + return false + end + sorcery.lathe.register { + input = pt, mass = mass; + tech = def.tech, cost = def.cost; + output = { + name = out:get_name(); + count = out:get_count() * vfc; + }; + leftover = def.leftover; + } + end + end + end end; tooltech = function(tool) if type(tool) ~= 'string' then tool = tool:get_name() end for g,t in pairs(sorcery.lathe.tools) do @@ -49,9 +88,9 @@ lfac = (wmat and wmat.data.level or 1) / (tmat.data.maxlevel or tmat.data.level or 1) end local ch = 65535 / dur - local wear = 2 * (ch * rec.cost * ntimes * lfac); + local wear = (ch * rec.cost * ntimes * lfac) return { tool = tool, wkpc = wkpc; cost = rec.cost * ntimes; wear = wear; @@ -84,8 +123,16 @@ end local tech = sorcery.lathe.tooltech(tool) local rec = R[wkpc:get_name()][tech] + if not rec then + for g,v in pairs(s_wkpc:get_definition().groups) do + local gs = R['group:'..g..'='..tostring(v)] + local gg = R['group:'..g] + + rec = (gs and gs[tech]) or (gg and gg[tech]) + end + end tech = sorcery.lathe.techs[tech] -- fill in the preview slots local j = 1 @@ -155,9 +202,9 @@ i:set_size('preview', 8); m:set_string('formspec', [[ formspec_version[3] size[10.25,8] list[context;tool;1.25,1;1,1] - list[context;workpiece;2.75,1;1,1] + list[context;workpiece;3,1;1,1] list[context;preview;5.25,0.25;4,2] list[current_player;main;0.25,3;8,4] listring[current_player;main] listring[context;workpiece] @@ -176,8 +223,17 @@ if tech and (s_wkpc:is_empty() or (R[s_wkpc:get_name()] ~= nil and R[s_wkpc:get_name()][tech] ~= nil)) then return stack:get_count() end + for g,v in pairs(s_wkpc:get_definition().groups) do + local gs = R['group:'..g..'='..tostring(v)] + local gg = R['group:'..g] + + if (gs and gs[tech]) + or (gg and gg[tech]) then + return stack:get_count() + end + end elseif list == 'workpiece' then local s_tool = inv:get_stack('tool', 1) if R[stack:get_name()] then if s_tool:is_empty()