@@ -1,13 +1,26 @@ -- the math basically needs to be rewritten from scratch by someone who isn't -- dyscalculic but +local L = sorcery.lib +local M = function(i) return sorcery.itemclass.get(i, 'material') end sorcery.lathe = { techs = { cut = {dmg = true}; - intaglio = {consume = true}; + intaglio = { + consume = true; + toolpred = function(tool) + if minetest.get_item_group(tool, 'sorcery_powder') == 0 then return false end + local cl = sorcery.itemclass.get(tool, 'metal') + return cl.data.hardness >= 3 + end; + validate = function(tool, wkpc) + return M(tool).data.hardness >= M(wkpc).data.hardness + end; + }; }; tools = { - sword = 'cut', knife = 'cut', blade = 'cut'; + ['group:sword'] = 'cut', ['group:knife'] = 'cut', ['group:blade'] = 'cut'; + ['group:sorcery_intaglio_powder'] = 'intaglio'; }; recipes = {}; register = function(def) local recipes = sorcery.lathe.recipes @@ -21,9 +34,9 @@ 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 pt = parts[ty] local ptc = sorcery.itemclass.get(pt, 'metal') if ptc and ptc.value then if def.mass <= ptc.value then local mass @@ -58,13 +71,25 @@ end end; tooltech = function(tool) if type(tool) ~= 'string' then tool = tool:get_name() end - for g,t in pairs(sorcery.lathe.tools) do - if minetest.get_item_group(tool, g) ~= 0 then + local ts = sorcery.lathe.tools + if ts[tool] then return ts[tool] end + + for id,t in pairs(ts) do + local q, g = L.str.beginswith(id, 'group:') + if q and minetest.get_item_group(tool, g) ~= 0 then return t end end + + for tech, t in pairs(sorcery.lathe.techs) do + if t.toolpred then + if t.toolpred(tool) then return tech end + end + end + + return nil end; } local R = sorcery.lathe.recipes @@ -219,27 +244,38 @@ local inv = minetest.get_meta(pos):get_inventory() if list == 'tool' then local s_wkpc = inv:get_stack('workpiece', 1) local tech = sorcery.lathe.tooltech(stack) + if not tech then return 0 end + local vdtr = sorcery.lathe.techs[tech].validate if tech and (s_wkpc:is_empty() - or (R[s_wkpc:get_name()] ~= nil and - R[s_wkpc:get_name()][tech] ~= nil)) + or (R[s_wkpc:get_name()] ~= nil and + R[s_wkpc:get_name()][tech] ~= nil and + (vdtr == nil or vdtr(stack,s_wkpc) ))) 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() + if vdtr == nil or vdtr(stack, s_wkpc) then + return stack:get_count() + end 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() - or R[stack:get_name()][sorcery.lathe.tooltech(s_tool)] - then return stack:get_count() end + if s_tool:is_empty() then return stack:get_count() end + + local tech = sorcery.lathe.tooltech(s_tool) + if tech and R[stack:get_name()][tech] then + local vdtr = sorcery.lathe.techs[tech].validate + if vdtr == nil or vdtr(s_tool, stack) then + return stack:get_count() + end + end end end return 0