sorcery  Diff

Differences From Artifact [75f9e0d88f]:

To Artifact [525693d594]:


    13     13   		local recipes = sorcery.lathe.recipes
    14     14   		if not recipes[def.input] then recipes[def.input] = {} end
    15     15   		local rs = recipes[def.input][def.tech]
    16     16   		if not rs
    17     17   			then recipes[def.input][def.tech] = { def }
    18     18   			else rs[#rs+1] = def
    19     19   		end
           20  +	end;
           21  +	register_metal = function(def)
           22  +		local parts = sorcery.data.metals[def.metal].parts
           23  +		local out = ItemStack(def.output)
           24  +		for _, ty in pairs {'ingot', 'block', 'fragment'} do
           25  +			local pt = parts[ty] 
           26  +			local ptc = sorcery.itemclass.get(pt, 'metal')
           27  +			if ptc and ptc.value then
           28  +				if def.mass <= ptc.value then
           29  +					local mass
           30  +					local vfc = ptc.value / def.mass
           31  +					if math.floor(vfc) ~= vfc then
           32  +						for i = 1, 50 do
           33  +							local v = vfc * i
           34  +							if math.floor(v) == v then
           35  +								mass = i
           36  +								vfc = v
           37  +								break
           38  +							end
           39  +						end
           40  +					else
           41  +						mass = 1
           42  +					end
           43  +					if not mass then
           44  +						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')
           45  +						return false
           46  +					end
           47  +					sorcery.lathe.register {
           48  +						input = pt, mass = mass;
           49  +						tech = def.tech, cost = def.cost;
           50  +						output = {
           51  +							name = out:get_name();
           52  +							count = out:get_count() * vfc;
           53  +						};
           54  +						leftover = def.leftover;
           55  +					}
           56  +				end
           57  +			end
           58  +		end
    20     59   	end;
    21     60   	tooltech = function(tool)
    22     61   		if type(tool) ~= 'string' then tool = tool:get_name() end
    23     62   		for g,t in pairs(sorcery.lathe.tools) do
    24     63   			if minetest.get_item_group(tool, g) ~= 0 then
    25     64   				return t
    26     65   			end
................................................................................
    46     85   	local lfac = 1
    47     86   	if tmat then
    48     87   		local dur = tmat.data.durability or dur
    49     88   		lfac = (wmat and wmat.data.level or 1) /
    50     89   			(tmat.data.maxlevel or tmat.data.level or 1)
    51     90   	end
    52     91   	local ch = 65535 / dur
    53         -	local wear = 2 * (ch * rec.cost * ntimes * lfac);
           92  +	local wear = (ch * rec.cost * ntimes * lfac)
    54     93   	return {
    55     94   		tool = tool, wkpc = wkpc;
    56     95   		cost = rec.cost * ntimes;
    57     96   		wear = wear;
    58     97   		ntimes = ntimes;
    59     98   		tqty = ntimes * (rec.mass or 1), outn = outn;
    60     99   		tech = tech;
................................................................................
    81    120   	-- obey level restrictions. TODO honor Rend
    82    121   	if (wmat and wmat.data.level or 0) > (tmat and (tmat.data.maxlevel or tmat.data.level) or 0) then
    83    122   		return
    84    123   	end
    85    124   	
    86    125   	local tech = sorcery.lathe.tooltech(tool)
    87    126   	local rec = R[wkpc:get_name()][tech]
          127  +	if not rec then
          128  +		for g,v in pairs(s_wkpc:get_definition().groups) do
          129  +			local gs = R['group:'..g..'='..tostring(v)] 
          130  +			local gg = R['group:'..g] 
          131  +
          132  +			rec = (gs and gs[tech]) or (gg and gg[tech])
          133  +		end
          134  +	end
    88    135   	tech = sorcery.lathe.techs[tech]
    89    136   
    90    137   	-- fill in the preview slots
    91    138   	local j = 1
    92    139   	for i=1, inv:get_size 'preview'  do
    93    140   		local stk = ItemStack()
    94    141   		local os = rec[i] and ItemStack(rec[i].output)
................................................................................
   152    199   		local i = m:get_inventory()
   153    200   		i:set_size('workpiece', 1);
   154    201   		i:set_size('tool', 1);
   155    202   		i:set_size('preview', 8);
   156    203   		m:set_string('formspec', [[
   157    204   			formspec_version[3] size[10.25,8]
   158    205   			list[context;tool;1.25,1;1,1]
   159         -			list[context;workpiece;2.75,1;1,1]
          206  +			list[context;workpiece;3,1;1,1]
   160    207   			list[context;preview;5.25,0.25;4,2]
   161    208   			list[current_player;main;0.25,3;8,4]
   162    209   
   163    210   			listring[current_player;main] listring[context;workpiece]
   164    211   			listring[current_player;main] listring[context;tool]
   165    212   			listring[current_player;main] listring[context;preview]
   166    213   			listring[current_player;main]
................................................................................
   173    220   		if list == 'tool' then
   174    221   			local s_wkpc = inv:get_stack('workpiece', 1)
   175    222   			local tech = sorcery.lathe.tooltech(stack)
   176    223   			if tech and (s_wkpc:is_empty()
   177    224   			or (R[s_wkpc:get_name()]       ~= nil and
   178    225   				R[s_wkpc:get_name()][tech] ~= nil))
   179    226   					then return stack:get_count() end
          227  +			for g,v in pairs(s_wkpc:get_definition().groups) do
          228  +				local gs = R['group:'..g..'='..tostring(v)] 
          229  +				local gg = R['group:'..g] 
          230  +
          231  +				if (gs and gs[tech])
          232  +				or (gg and gg[tech]) then
          233  +					return stack:get_count()
          234  +				end
          235  +			end
   180    236   		elseif list == 'workpiece' then
   181    237   			local s_tool = inv:get_stack('tool', 1)
   182    238   			if R[stack:get_name()] then
   183    239   				if s_tool:is_empty()
   184    240   				or R[stack:get_name()][sorcery.lathe.tooltech(s_tool)]
   185    241   					then return stack:get_count() end
   186    242   			end