sorcery  Diff

Differences From Artifact [75f9e0d88f]:

To Artifact [525693d594]:


13
14
15
16
17
18
19







































20
21
22
23
24
25
26
..
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
81
82
83
84
85
86
87








88
89
90
91
92
93
94
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
...
173
174
175
176
177
178
179









180
181
182
183
184
185
186
		local recipes = sorcery.lathe.recipes
		if not recipes[def.input] then recipes[def.input] = {} end
		local rs = recipes[def.input][def.tech]
		if not rs
			then recipes[def.input][def.tech] = { def }
			else rs[#rs+1] = def
		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
				return t
			end
................................................................................
	local lfac = 1
	if tmat then
		local dur = tmat.data.durability or dur
		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);
	return {
		tool = tool, wkpc = wkpc;
		cost = rec.cost * ntimes;
		wear = wear;
		ntimes = ntimes;
		tqty = ntimes * (rec.mass or 1), outn = outn;
		tech = tech;
................................................................................
	-- obey level restrictions. TODO honor Rend
	if (wmat and wmat.data.level or 0) > (tmat and (tmat.data.maxlevel or tmat.data.level) or 0) then
		return
	end
	
	local tech = sorcery.lathe.tooltech(tool)
	local rec = R[wkpc:get_name()][tech]








	tech = sorcery.lathe.techs[tech]

	-- fill in the preview slots
	local j = 1
	for i=1, inv:get_size 'preview'  do
		local stk = ItemStack()
		local os = rec[i] and ItemStack(rec[i].output)
................................................................................
		local i = m:get_inventory()
		i:set_size('workpiece', 1);
		i:set_size('tool', 1);
		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;preview;5.25,0.25;4,2]
			list[current_player;main;0.25,3;8,4]

			listring[current_player;main] listring[context;workpiece]
			listring[current_player;main] listring[context;tool]
			listring[current_player;main] listring[context;preview]
			listring[current_player;main]
................................................................................
		if list == 'tool' then
			local s_wkpc = inv:get_stack('workpiece', 1)
			local tech = sorcery.lathe.tooltech(stack)
			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









		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
			end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
..
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
...
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
		local recipes = sorcery.lathe.recipes
		if not recipes[def.input] then recipes[def.input] = {} end
		local rs = recipes[def.input][def.tech]
		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
			if minetest.get_item_group(tool, g) ~= 0 then
				return t
			end
................................................................................
	local lfac = 1
	if tmat then
		local dur = tmat.data.durability or dur
		lfac = (wmat and wmat.data.level or 1) /
			(tmat.data.maxlevel or tmat.data.level or 1)
	end
	local ch = 65535 / dur
	local wear = (ch * rec.cost * ntimes * lfac)
	return {
		tool = tool, wkpc = wkpc;
		cost = rec.cost * ntimes;
		wear = wear;
		ntimes = ntimes;
		tqty = ntimes * (rec.mass or 1), outn = outn;
		tech = tech;
................................................................................
	-- obey level restrictions. TODO honor Rend
	if (wmat and wmat.data.level or 0) > (tmat and (tmat.data.maxlevel or tmat.data.level) or 0) then
		return
	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
	for i=1, inv:get_size 'preview'  do
		local stk = ItemStack()
		local os = rec[i] and ItemStack(rec[i].output)
................................................................................
		local i = m:get_inventory()
		i:set_size('workpiece', 1);
		i:set_size('tool', 1);
		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;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]
			listring[current_player;main] listring[context;tool]
			listring[current_player;main] listring[context;preview]
			listring[current_player;main]
................................................................................
		if list == 'tool' then
			local s_wkpc = inv:get_stack('workpiece', 1)
			local tech = sorcery.lathe.tooltech(stack)
			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()
				or R[stack:get_name()][sorcery.lathe.tooltech(s_tool)]
					then return stack:get_count() end
			end