sorcery  Diff

Differences From Artifact [e643a56c3c]:

To Artifact [aae72d93b8]:


1
2
3
4
5
6


7
8
9
10
11
12
13
..
51
52
53
54
55
56
57



























58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
...
219
220
221
222
223
224
225














226

227
228
229
230
231
232
233
...
254
255
256
257
258
259
260










261
262
263

264
265
266
267
268
269
270
...
400
401
402
403
404
405
406



407
408
409
410
411
412
413
...
464
465
466
467
468
469
470

471
472
473
474
475
476
477
-- by use of the enchanter, it is possible to reveal a random
-- recipe and enscribe it on a sheet of paper. these sheets of
-- paper can then bound together into books, combining like
-- recipes

sorcery.cookbook = {}


local constants = {
	-- do not show recipes for items in these groups
	exclude_groups = {
	};
	exclude_names = {
		'stairs';
		'slab';
................................................................................
	return {}
end
local modofname = function(id)
	local sep = string.find(id,':')
	if sep == nil then return nil end -- uh oh
	return string.sub(id, 1, sep - 1)
end



























local pick_builtin = function(kind) return function(restrict)
	-- ow ow ow ow ow ow ow
	local names = {}
	for k in pairs(minetest.registered_items) do
		local rec = minetest.get_craft_recipe(k)
		if rec.items ~= nil and (rec.method == kind or (rec.method == 'shapeless' and kind == 'normal')) then -- is this last bit necessary?
			local excluded = false
			for _,n in pairs(constants.exclude_names) do
				if string.find(k,n) ~= nil then
					excluded = true break end
			end
			if not excluded then for _,g in pairs(constants.exclude_groups) do
				if minetest.get_item_group(k, g) > 0 then
					excluded = true break end
			end end
			local props = minetest.registered_items[k]._sorcery
			local module = modofname(k)
			if not (excluded
				or sorcery.lib.tbl.has(constants.blacklist_mods,module)
				or (props and props.recipe and props.recipe.secret)
				or (restrict and (
				    (restrict.mod   and module ~= restrict.mod)
				 or (restrict.group and (minetest.get_item_group(k, restrict.group) == 0))
			))) then names[#names + 1] = k end
		end
	end
	return names[math.random(#names)]
end end
local find_builtin = function(method,kind)
	return function(out)
		local rec = {}
................................................................................
		chance = 4;
		slots = {
			{0,0};
			{0,1};
		};
		pick = function(restrict)
			-- TODO make sure affinity restrictions match














			return sorcery.register.infusions.db[math.random(#sorcery.register.infusions.db)].output

		end;
		title = function(output)
			for _,i in pairs(sorcery.register.infusions.db) do
				if i.output == output then
					if i._proto and i._proto.name
						then return i._proto.name
						else break end
................................................................................
		name = 'Milling Guide';
		node = 'sorcery:mill';
		booksuf = 'Manual';
		chance = 1;
		w = 1, h = 2;
		pick = function(restrict)
			cache:populate_grindables()










			local i = cache.grindables[math.random(#cache.grindables)]
			local pd = sorcery.itemclass.get(i, 'grindable')
			return pd.powder

		end;
		props = props_builtin;
		slots = {
			{0,1},
			{0,0};
		};
		find = function(out)
................................................................................
		end
		if kind == nil then -- oh well, we tried
			local rks = sorcery.lib.tbl.keys(recipe_kinds)
			kind = rks[math.random(#rks)]
		end
	end




	return recipe_kinds[kind].pick(restrict), kind
end

local render_recipe = function(kind,ingredients,result,notes_right)
	local k = recipe_kinds[kind]
	local t = ''
	local props = k.props(result)
................................................................................
	local ing = rec.find(out)
	return render_recipe(kind,ing,out,notes_right), rec.w, rec.h
end

sorcery.cookbook.setrecipe = function(stack,k,r,restrict)
	local meta = stack:get_meta()
	if not r then r,k = sorcery.cookbook.pickrecipe(k,restrict) end

	local t = recipe_kinds[k]
	meta:set_string('recipe_kind', k)
	meta:set_string('recipe_name', r)
	meta:set_string('description',
		(t.title and t.title(r) or desc_builtin(r)) .. ' ' .. t.name)
end







>
>







 







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






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>







 







>
>
>
>
>
>
>
>
>
>
|
|
|
>







 







>
>
>







 







>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
99
100
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
...
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
...
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
...
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
-- by use of the enchanter, it is possible to reveal a random
-- recipe and enscribe it on a sheet of paper. these sheets of
-- paper can then bound together into books, combining like
-- recipes

sorcery.cookbook = {}
local log = sorcery.logger('cookbook')

local constants = {
	-- do not show recipes for items in these groups
	exclude_groups = {
	};
	exclude_names = {
		'stairs';
		'slab';
................................................................................
	return {}
end
local modofname = function(id)
	local sep = string.find(id,':')
	if sep == nil then return nil end -- uh oh
	return string.sub(id, 1, sep - 1)
end
local item_restrict_eval = function(name, restrict)
	for _,n in pairs(constants.exclude_names) do
		if string.find(name,n) ~= nil then
			return false
		end
	end
	for _,g in pairs(constants.exclude_groups) do
		if minetest.get_item_group(name, g) > 0 then
			return false
		end
	end

	local props = minetest.registered_items[name]._sorcery
	local module = modofname(name)

	return not (excluded
		or sorcery.lib.tbl.has(constants.blacklist_mods,module)
		or (props and props.recipe and props.recipe.secret)
		or (restrict and (
			(restrict.pred and restrict.pred {
				mod = module, item = name, props = props
			} ~= true)
		 or (restrict.mod   and module ~= restrict.mod)
		 or (restrict.group and (minetest.get_item_group(name, restrict.group) == 0))
	))) 
end

local pick_builtin = function(kind) return function(restrict)
	-- ow ow ow ow ow ow ow
	local names = {}
	for k in pairs(minetest.registered_items) do
		local rec = minetest.get_craft_recipe(k)
		if rec.items ~= nil and (rec.method == kind or (rec.method == 'shapeless' and kind == 'normal')) then -- is this last bit necessary?

















			if item_restrict_eval(k, restrict) then names[#names + 1] = k end
		end
	end
	return names[math.random(#names)]
end end
local find_builtin = function(method,kind)
	return function(out)
		local rec = {}
................................................................................
		chance = 4;
		slots = {
			{0,0};
			{0,1};
		};
		pick = function(restrict)
			-- TODO make sure affinity restrictions match
			if restrict then
				local t = {}
				for _, i in pairs(sorcery.register.infusions.db) do
					if item_restrict_eval(i.output, restrict) and not (
						-- conditions which cause failure of restriction test
						(restrict.ipred and restrict.ipred {
							mod = module;
							infusion = i;
							output = i.output;
						} ~= true)
					) then t[#t+1] = i.output end
				end
				return select(2, sorcery.lib.tbl.pick(t))
			else
				return sorcery.register.infusions.db[math.random(#sorcery.register.infusions.db)].output
			end
		end;
		title = function(output)
			for _,i in pairs(sorcery.register.infusions.db) do
				if i.output == output then
					if i._proto and i._proto.name
						then return i._proto.name
						else break end
................................................................................
		name = 'Milling Guide';
		node = 'sorcery:mill';
		booksuf = 'Manual';
		chance = 1;
		w = 1, h = 2;
		pick = function(restrict)
			cache:populate_grindables()
			if restrict then
				local t = {}
				for _, i in pairs(cache.grindables) do
					local pd = sorcery.itemclass.get(i, 'grindable')
					if item_restrict_eval(pd.powder, restrict) then
						t[#t+1] = pd.powder
					end
				end
				return select(2, sorcery.lib.tbl.pick(t))
			else
				local gd = cache.grindables[math.random(#cache.grindables)]
				local pd = sorcery.itemclass.get(gd, 'grindable')
				return pd.powder
			end
		end;
		props = props_builtin;
		slots = {
			{0,1},
			{0,0};
		};
		find = function(out)
................................................................................
		end
		if kind == nil then -- oh well, we tried
			local rks = sorcery.lib.tbl.keys(recipe_kinds)
			kind = rks[math.random(#rks)]
		end
	end

	if not recipe_kinds[kind] then
		log.fatalf('attempted to pick recipe of unknown kind "%s"', kind)
	end
	return recipe_kinds[kind].pick(restrict), kind
end

local render_recipe = function(kind,ingredients,result,notes_right)
	local k = recipe_kinds[kind]
	local t = ''
	local props = k.props(result)
................................................................................
	local ing = rec.find(out)
	return render_recipe(kind,ing,out,notes_right), rec.w, rec.h
end

sorcery.cookbook.setrecipe = function(stack,k,r,restrict)
	local meta = stack:get_meta()
	if not r then r,k = sorcery.cookbook.pickrecipe(k,restrict) end
	if not r then return false end
	local t = recipe_kinds[k]
	meta:set_string('recipe_kind', k)
	meta:set_string('recipe_name', r)
	meta:set_string('description',
		(t.title and t.title(r) or desc_builtin(r)) .. ' ' .. t.name)
end