sorcery  Diff

Differences From Artifact [e0a46e6a8e]:

To Artifact [b21ad56f71]:


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
..
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
..
77
78
79
80
81
82
83

















84






85
86
87
88
89
90
91
92
...
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351


352
353
354
355
356
357
358
359
360
361
362
363
364








365
366
367
368
369
370
371
...
459
460
461
462
463
464
465

466
467
468
469
470


471
472
473

474











475
476
477
478
479
480
481
...
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509

sorcery.cookbook = {}
local constants = {
	-- do not show recipes for items in these groups
	exclude_groups = {
	};
	exclude_names = {
		'_stairs';
		'_slab';
		'slope_';
	};
	-- do not show recipes from this namespace
	blacklist_mods = {
		'group'; -- WHY IS THIS NECESSARY
		'moreblocks'; -- too much noise
	};

	recipes_per_cookbook_page = 3;














}

local slot3x3 = {
	{0,0}, {1,0}, {2,0};
	{0,1}, {1,1}, {2,1};
	{0,2}, {1,2}, {2,2};
}
................................................................................
	-- 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(p,n) then
					excluded = true break end
			end
			if not excluded then for _,g in pairs(constants.exclude_groups) do
				if minetest.get_item_group(p, 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)
................................................................................
		local col = (j-1) % w
		if i.items[j] then
			rec[1 + (row * 3) + col] = i.items[j]
		end
	end
	return rec
end

















local desc_builtin = function(i)






	local desc = minetest.registered_items[i].description
	if not desc then return 'Peculiar Item' end

	local eol = string.find(desc,'\n')
	if not eol then return desc else return string.sub(desc,1,eol-1) end
end;

local bookadjs = { -- sets are in reverse order!
................................................................................
		local x, y = k.slots[i][1], k.slots[i][2]
		if ingredients[i] and ingredients[i] ~= '' then
			local tt
			if k.indesc then tt = k.indesc(ingredients[i]) else tt = desc_builtin(ingredients[i]) end
			t = t .. string.format([[
				item_image[%f,%f;1,1;%s]
				tooltip[%f,%f;1,1;%s]
			]], x,y, minetest.formspec_escape(ingredients[i]),
			    x,y, minetest.formspec_escape(tt))
		else
			if k.drawslots == nil or k.drawslots then
				t = string.format('box[%f,%f;0.1,0.1;#00000060]',x+0.45,y+0.45) .. t
			end
		end
	end
................................................................................

dungeon_loot.register {
	name = 'sorcery:recipe';
	chance = 0.9;
	count = {1,7};
}

minetest.register_craft { type = 'fuel', recipe = 'sorcery:recipe', burntime = 3 }
minetest.register_craft {
	type = 'cooking';
	recipe = 'sorcery:recipe';
	output = 'sorcery:ash';
	cooktime = 3;
}

default.register_craft_metadata_copy('default:paper','sorcery:recipe')


-- default.register_craft_metadata_copy('default:book','sorcery:cookbook')

for i=1,8 do
	local rcp = {}
	for i=1,i do rcp[i] = 'sorcery:recipe' end
	rcp[#rcp+1]='default:book' minetest.register_craft {
		type = 'shapeless', recipe = rcp, output = 'sorcery:cookbook';
	}
	rcp[#rcp]='sorcery:cookbook' minetest.register_craft {
		type = 'shapeless', recipe = rcp, output = 'sorcery:cookbook';
	}
end










local m = sorcery.lib.marshal
local encbook, decbook = m.transcoder {
	pages = m.g.array(8, m.g.struct {
		kind = m.t.str;
		name = m.t.str;
	})
................................................................................
	end

	uinv:set_stack('main',idx,stack)
	bookform(stack,user)
end)

minetest.register_on_craft(function(stack,player,grid,inv)

	if stack:get_name() ~= 'sorcery:cookbook' then return nil end

	local oldbook
	local topic, onetopic = nil, true
	local recipes = {}


	for _,s in pairs(grid) do
		if s:get_name() == 'sorcery:recipe' then
			recipes[#recipes+1] = s

		elseif s:get_name() == 'sorcery:cookbook' then oldbook = s end











	end

	oldbook = oldbook or stack
	local bookmeta = oldbook:get_meta()
	local newbook = not bookmeta:contains('cookbook')
	local book = bookprops(oldbook)

................................................................................

	if topic and newbook then
		if not onetopic then topic = nil end
		bookmeta:set_string('description',namebook(topic,player:get_player_name()))
		bookmeta:set_string('owner',player:get_player_name())
	end

	print('new book',bookmeta:get_string('description'))
	print('new book',dump(book))
	bookmeta:set_string('cookbook', sorcery.lib.str.meta_armor(encbook(book),true))
	return oldbook
end)

if minetest.get_modpath('books') then
	-- make our own placeable cookbook somehow
end







|
|
|








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







 







|



|







 







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







 







|







 







<
<
<
<
<
<
<
<

>
>













>
>
>
>
>
>
>
>







 







>





>
>
|


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







 







<
<







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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
...
373
374
375
376
377
378
379








380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
...
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
...
548
549
550
551
552
553
554


555
556
557
558
559
560
561

sorcery.cookbook = {}
local constants = {
	-- do not show recipes for items in these groups
	exclude_groups = {
	};
	exclude_names = {
		'stairs';
		'slab';
		'slope';
	};
	-- do not show recipes from this namespace
	blacklist_mods = {
		'group'; -- WHY IS THIS NECESSARY
		'moreblocks'; -- too much noise
	};

	recipes_per_cookbook_page = 3;

	group_ids = {
		wood   = { caption = 'Any Wood',   cnitem = 'default:wood'   };
		tree   = { caption = 'Any Tree',   cnitem = 'default:tree'   };
		leaves = { caption = 'Any Leaves', cnitem = 'default:leaves' };
		stone  = { caption = 'Any Stone',  cnitem = 'default:stone'  };
		dye    = { caption = 'Any Dye',    cnitem = 'dye:black'      };
		bone   = { caption = 'Any Bone',   cnitem = 'bonemeal:bone'  };
		vessel = { caption = 'Any Bottle', cnitem = 'vessels:glass_bottle' };
		flower = { caption = 'Any Flower', cnitem = 'flowers:rose' };
		mushroom = { caption = 'Any Mushroom', cnitem = 'flowers:mushroom_brown' };
		water_bucket = { caption = 'Water Bucket', cnitem = 'bucket:bucket_water' };
		sorcery_ley_cable = { caption = 'Cable', cnitem = 'sorcery:cable_vidrium' };
	};
}

local slot3x3 = {
	{0,0}, {1,0}, {2,0};
	{0,1}, {1,1}, {2,1};
	{0,2}, {1,2}, {2,2};
}
................................................................................
	-- 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)
................................................................................
		local col = (j-1) % w
		if i.items[j] then
			rec[1 + (row * 3) + col] = i.items[j]
		end
	end
	return rec
end
local function group_eval(i)
	if string.sub(i,1,6) == 'group:' then
		local g = string.sub(i,7)
		if constants.group_ids[g] then
			return constants.group_ids[g].cnitem,
			       constants.group_ids[g].caption
		end
		for i,v in pairs(minetest.registered_items) do
			if minetest.get_item_group(i, g) > 0 then
				return i, v.description
			end
		end
		return i
	end
	return i
end
local function desc_builtin(i)
	local desc
	i, desc = group_eval(i)
	-- print('describing ',i,dump(minetest.registered_items[i]))
	if not minetest.registered_items[i] then
		minetest.log('WARNING: unknown item in recipe ' .. i)
		return 'Unknown Item'
	end
	if not desc then desc = minetest.registered_items[i].description end
	if not desc then return 'Peculiar Item' end

	local eol = string.find(desc,'\n')
	if not eol then return desc else return string.sub(desc,1,eol-1) end
end;

local bookadjs = { -- sets are in reverse order!
................................................................................
		local x, y = k.slots[i][1], k.slots[i][2]
		if ingredients[i] and ingredients[i] ~= '' then
			local tt
			if k.indesc then tt = k.indesc(ingredients[i]) else tt = desc_builtin(ingredients[i]) end
			t = t .. string.format([[
				item_image[%f,%f;1,1;%s]
				tooltip[%f,%f;1,1;%s]
			]], x,y, minetest.formspec_escape(group_eval(ingredients[i])),
			    x,y, minetest.formspec_escape(tt))
		else
			if k.drawslots == nil or k.drawslots then
				t = string.format('box[%f,%f;0.1,0.1;#00000060]',x+0.45,y+0.45) .. t
			end
		end
	end
................................................................................

dungeon_loot.register {
	name = 'sorcery:recipe';
	chance = 0.9;
	count = {1,7};
}









default.register_craft_metadata_copy('default:paper','sorcery:recipe')
-- this seems bugged; it doesn't like it when its item shows up in another
-- recipe. so we'll do it manually :/
-- default.register_craft_metadata_copy('default:book','sorcery:cookbook')

for i=1,8 do
	local rcp = {}
	for i=1,i do rcp[i] = 'sorcery:recipe' end
	rcp[#rcp+1]='default:book' minetest.register_craft {
		type = 'shapeless', recipe = rcp, output = 'sorcery:cookbook';
	}
	rcp[#rcp]='sorcery:cookbook' minetest.register_craft {
		type = 'shapeless', recipe = rcp, output = 'sorcery:cookbook';
	}
end

minetest.register_craft {
	type = 'shapeless';
	recipe = {
		'sorcery:cookbook';
		'default:book';
	};
	output = 'sorcery:cookbook';
};

local m = sorcery.lib.marshal
local encbook, decbook = m.transcoder {
	pages = m.g.array(8, m.g.struct {
		kind = m.t.str;
		name = m.t.str;
	})
................................................................................
	end

	uinv:set_stack('main',idx,stack)
	bookform(stack,user)
end)

minetest.register_on_craft(function(stack,player,grid,inv)
	-- god this is messy. i'm sorry. minetest made me do it
	if stack:get_name() ~= 'sorcery:cookbook' then return nil end

	local oldbook
	local topic, onetopic = nil, true
	local recipes = {}
	local copybook = false
	local obindex
	for i,s in pairs(grid) do
		if s:get_name() == 'sorcery:recipe' then
			recipes[#recipes+1] = s
		elseif s:get_name() == 'default:book' then copybook = true
		elseif s:get_name() == 'sorcery:cookbook' then oldbook = s obindex = i end
	end

	if #recipes == 0 and copybook and oldbook then
		inv:set_stack('craft',obindex,oldbook)
		local newmeta = stack:get_meta()
		local copy = function(field)
			newmeta:set_string(field,oldbook:get_meta():get_string(field))
		end
		copy('cookbook') copy('description')
		newmeta:set_string('owner',player:get_player_name())
		return stack
	end

	oldbook = oldbook or stack
	local bookmeta = oldbook:get_meta()
	local newbook = not bookmeta:contains('cookbook')
	local book = bookprops(oldbook)

................................................................................

	if topic and newbook then
		if not onetopic then topic = nil end
		bookmeta:set_string('description',namebook(topic,player:get_player_name()))
		bookmeta:set_string('owner',player:get_player_name())
	end



	bookmeta:set_string('cookbook', sorcery.lib.str.meta_armor(encbook(book),true))
	return oldbook
end)

if minetest.get_modpath('books') then
	-- make our own placeable cookbook somehow
end