1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
...
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
-- the math basically needs to be rewritten from scratch by someone who isn't
-- dyscalculic but
sorcery.lathe = {
techs = {
cut = {dmg = true};
intaglio = {consume = true};
};
tools = {
sword = 'cut', knife = 'cut', blade = 'cut';
};
recipes = {};
register = function(def)
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
................................................................................
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
................................................................................
}
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
end
end;
}
local R = sorcery.lathe.recipes
sorcery.lathe.get = function(pos,idx,howmany)
local inv = minetest.get_meta(pos):get_inventory()
local tool = inv:get_stack('tool',1)
................................................................................
allow_metadata_inventory_move = function() return 0 end;
allow_metadata_inventory_put = function(pos, list, idx, stack, user)
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 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
end
return 0
end;
allow_metadata_inventory_take = function(pos, list, idx, stack, user)
if list == 'preview' then
|
>
>
>
|
>
>
>
>
>
>
>
>
|
>
<
>
>
|
|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
|
|
>
>
|
>
|
>
|
>
>
>
|
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
..
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
-- 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;
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 = {
['group:sword'] = 'cut', ['group:knife'] = 'cut', ['group:blade'] = 'cut';
['group:sorcery_intaglio_powder'] = 'intaglio';
};
recipes = {};
register = function(def)
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
................................................................................
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
................................................................................
}
end
end
end
end;
tooltech = function(tool)
if type(tool) ~= 'string' then tool = tool:get_name() end
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
sorcery.lathe.get = function(pos,idx,howmany)
local inv = minetest.get_meta(pos):get_inventory()
local tool = inv:get_stack('tool',1)
................................................................................
allow_metadata_inventory_move = function() return 0 end;
allow_metadata_inventory_put = function(pos, list, idx, stack, user)
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 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
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() 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
end;
allow_metadata_inventory_take = function(pos, list, idx, stack, user)
if list == 'preview' then
|