sorcery  Diff

Differences From Artifact [525693d594]:

To Artifact [2fbf5881b5]:


     1      1   -- the math basically needs to be rewritten from scratch by someone who isn't
     2      2   -- dyscalculic but 
            3  +local L = sorcery.lib
            4  +local M = function(i) return sorcery.itemclass.get(i, 'material') end
     3      5   sorcery.lathe = {
     4      6   	techs = {
     5      7   		cut = {dmg = true};
     6         -		intaglio = {consume = true};
            8  +		intaglio = {
            9  +			consume = true;
           10  +			toolpred = function(tool)
           11  +				if minetest.get_item_group(tool, 'sorcery_powder') == 0 then return false end
           12  +				local cl = sorcery.itemclass.get(tool, 'metal')
           13  +				return cl.data.hardness >= 3
           14  +			end;
           15  +			validate = function(tool, wkpc)
           16  +				return M(tool).data.hardness >= M(wkpc).data.hardness
           17  +			end;
           18  +		};
     7     19   	};
     8     20   	tools = {
     9         -		sword = 'cut', knife = 'cut', blade = 'cut';
           21  +		['group:sword'] = 'cut', ['group:knife'] = 'cut', ['group:blade'] = 'cut';
           22  +		['group:sorcery_intaglio_powder'] = 'intaglio';
    10     23   	};
    11     24   	recipes = {};
    12     25   	register = function(def)
    13     26   		local recipes = sorcery.lathe.recipes
    14     27   		if not recipes[def.input] then recipes[def.input] = {} end
    15     28   		local rs = recipes[def.input][def.tech]
    16     29   		if not rs
................................................................................
    18     31   			else rs[#rs+1] = def
    19     32   		end
    20     33   	end;
    21     34   	register_metal = function(def)
    22     35   		local parts = sorcery.data.metals[def.metal].parts
    23     36   		local out = ItemStack(def.output)
    24     37   		for _, ty in pairs {'ingot', 'block', 'fragment'} do
    25         -			local pt = parts[ty] 
           38  +			local pt = parts[ty]
    26     39   			local ptc = sorcery.itemclass.get(pt, 'metal')
    27     40   			if ptc and ptc.value then
    28     41   				if def.mass <= ptc.value then
    29     42   					local mass
    30     43   					local vfc = ptc.value / def.mass
    31     44   					if math.floor(vfc) ~= vfc then
    32     45   						for i = 1, 50 do
................................................................................
    55     68   					}
    56     69   				end
    57     70   			end
    58     71   		end
    59     72   	end;
    60     73   	tooltech = function(tool)
    61     74   		if type(tool) ~= 'string' then tool = tool:get_name() end
    62         -		for g,t in pairs(sorcery.lathe.tools) do
    63         -			if minetest.get_item_group(tool, g) ~= 0 then
           75  +		local ts = sorcery.lathe.tools
           76  +		if ts[tool] then return ts[tool] end
           77  +
           78  +		for id,t in pairs(ts) do
           79  +			local q, g = L.str.beginswith(id, 'group:')
           80  +			if q and minetest.get_item_group(tool, g) ~= 0 then
    64     81   				return t
    65     82   			end
    66     83   		end
           84  +
           85  +		for tech, t in pairs(sorcery.lathe.techs) do
           86  +			if t.toolpred then
           87  +				if t.toolpred(tool) then return tech end
           88  +			end
           89  +		end
           90  +
           91  +		return nil
    67     92   	end;
    68     93   }
    69     94   
    70     95   local R = sorcery.lathe.recipes
    71     96   sorcery.lathe.get = function(pos,idx,howmany)
    72     97   	local inv = minetest.get_meta(pos):get_inventory()
    73     98   	local tool = inv:get_stack('tool',1)
................................................................................
   216    241   
   217    242   	allow_metadata_inventory_move = function() return 0 end;
   218    243   	allow_metadata_inventory_put = function(pos, list, idx, stack, user)
   219    244   		local inv = minetest.get_meta(pos):get_inventory()
   220    245   		if list == 'tool' then
   221    246   			local s_wkpc = inv:get_stack('workpiece', 1)
   222    247   			local tech = sorcery.lathe.tooltech(stack)
          248  +			if not tech then return 0 end
          249  +			local vdtr = sorcery.lathe.techs[tech].validate
   223    250   			if tech and (s_wkpc:is_empty()
   224         -			or (R[s_wkpc:get_name()]       ~= nil and
   225         -				R[s_wkpc:get_name()][tech] ~= nil))
          251  +						or (R[s_wkpc:get_name()]       ~= nil and
          252  +							R[s_wkpc:get_name()][tech] ~= nil and
          253  +							(vdtr == nil or vdtr(stack,s_wkpc) )))
   226    254   					then return stack:get_count() end
   227    255   			for g,v in pairs(s_wkpc:get_definition().groups) do
   228    256   				local gs = R['group:'..g..'='..tostring(v)] 
   229    257   				local gg = R['group:'..g] 
   230    258   
   231    259   				if (gs and gs[tech])
   232    260   				or (gg and gg[tech]) then
   233         -					return stack:get_count()
          261  +					if vdtr == nil or vdtr(stack, s_wkpc) then
          262  +						return stack:get_count()
          263  +					end
   234    264   				end
   235    265   			end
   236    266   		elseif list == 'workpiece' then
   237    267   			local s_tool = inv:get_stack('tool', 1)
   238    268   			if R[stack:get_name()] then
   239         -				if s_tool:is_empty()
   240         -				or R[stack:get_name()][sorcery.lathe.tooltech(s_tool)]
   241         -					then return stack:get_count() end
          269  +				if s_tool:is_empty() then return stack:get_count() end
          270  +
          271  +				local tech = sorcery.lathe.tooltech(s_tool)
          272  +				if tech and R[stack:get_name()][tech] then
          273  +					local vdtr = sorcery.lathe.techs[tech].validate
          274  +					if vdtr == nil or vdtr(s_tool, stack) then
          275  +						return stack:get_count()
          276  +					end
          277  +				end
   242    278   			end
   243    279   		end
   244    280   
   245    281   		return 0
   246    282   	end;
   247    283   	allow_metadata_inventory_take = function(pos, list, idx, stack, user)
   248    284   		if list == 'preview' then