Differences From
Artifact [e0a46e6a8e]:
5 5
6 6 sorcery.cookbook = {}
7 7 local constants = {
8 8 -- do not show recipes for items in these groups
9 9 exclude_groups = {
10 10 };
11 11 exclude_names = {
12 - '_stairs';
13 - '_slab';
14 - 'slope_';
12 + 'stairs';
13 + 'slab';
14 + 'slope';
15 15 };
16 16 -- do not show recipes from this namespace
17 17 blacklist_mods = {
18 18 'group'; -- WHY IS THIS NECESSARY
19 19 'moreblocks'; -- too much noise
20 20 };
21 21
22 22 recipes_per_cookbook_page = 3;
23 +
24 + group_ids = {
25 + wood = { caption = 'Any Wood', cnitem = 'default:wood' };
26 + tree = { caption = 'Any Tree', cnitem = 'default:tree' };
27 + leaves = { caption = 'Any Leaves', cnitem = 'default:leaves' };
28 + stone = { caption = 'Any Stone', cnitem = 'default:stone' };
29 + dye = { caption = 'Any Dye', cnitem = 'dye:black' };
30 + bone = { caption = 'Any Bone', cnitem = 'bonemeal:bone' };
31 + vessel = { caption = 'Any Bottle', cnitem = 'vessels:glass_bottle' };
32 + flower = { caption = 'Any Flower', cnitem = 'flowers:rose' };
33 + mushroom = { caption = 'Any Mushroom', cnitem = 'flowers:mushroom_brown' };
34 + water_bucket = { caption = 'Water Bucket', cnitem = 'bucket:bucket_water' };
35 + sorcery_ley_cable = { caption = 'Cable', cnitem = 'sorcery:cable_vidrium' };
36 + };
23 37 }
24 38
25 39 local slot3x3 = {
26 40 {0,0}, {1,0}, {2,0};
27 41 {0,1}, {1,1}, {2,1};
28 42 {0,2}, {1,2}, {2,2};
29 43 }
................................................................................
43 57 -- ow ow ow ow ow ow ow
44 58 local names = {}
45 59 for k in pairs(minetest.registered_items) do
46 60 local rec = minetest.get_craft_recipe(k)
47 61 if rec.items ~= nil and (rec.method == kind or (rec.method == 'shapeless' and kind == 'normal')) then -- is this last bit necessary?
48 62 local excluded = false
49 63 for _,n in pairs(constants.exclude_names) do
50 - if string.find(p,n) then
64 + if string.find(k,n) ~= nil then
51 65 excluded = true break end
52 66 end
53 67 if not excluded then for _,g in pairs(constants.exclude_groups) do
54 - if minetest.get_item_group(p, g) > 0 then
68 + if minetest.get_item_group(k, g) > 0 then
55 69 excluded = true break end
56 70 end end
57 71 local props = minetest.registered_items[k]._sorcery
58 72 local module = modofname(k)
59 73 if not (excluded
60 74 or sorcery.lib.tbl.has(constants.blacklist_mods,module)
61 75 or (props and props.recipe and props.recipe.secret)
................................................................................
77 91 local col = (j-1) % w
78 92 if i.items[j] then
79 93 rec[1 + (row * 3) + col] = i.items[j]
80 94 end
81 95 end
82 96 return rec
83 97 end
84 -local desc_builtin = function(i)
85 - local desc = minetest.registered_items[i].description
98 +local function group_eval(i)
99 + if string.sub(i,1,6) == 'group:' then
100 + local g = string.sub(i,7)
101 + if constants.group_ids[g] then
102 + return constants.group_ids[g].cnitem,
103 + constants.group_ids[g].caption
104 + end
105 + for i,v in pairs(minetest.registered_items) do
106 + if minetest.get_item_group(i, g) > 0 then
107 + return i, v.description
108 + end
109 + end
110 + return i
111 + end
112 + return i
113 +end
114 +local function desc_builtin(i)
115 + local desc
116 + i, desc = group_eval(i)
117 + -- print('describing ',i,dump(minetest.registered_items[i]))
118 + if not minetest.registered_items[i] then
119 + minetest.log('WARNING: unknown item in recipe ' .. i)
120 + return 'Unknown Item'
121 + end
122 + if not desc then desc = minetest.registered_items[i].description end
86 123 if not desc then return 'Peculiar Item' end
87 124
88 125 local eol = string.find(desc,'\n')
89 126 if not eol then return desc else return string.sub(desc,1,eol-1) end
90 127 end;
91 128
92 129 local bookadjs = { -- sets are in reverse order!
................................................................................
264 301 local x, y = k.slots[i][1], k.slots[i][2]
265 302 if ingredients[i] and ingredients[i] ~= '' then
266 303 local tt
267 304 if k.indesc then tt = k.indesc(ingredients[i]) else tt = desc_builtin(ingredients[i]) end
268 305 t = t .. string.format([[
269 306 item_image[%f,%f;1,1;%s]
270 307 tooltip[%f,%f;1,1;%s]
271 - ]], x,y, minetest.formspec_escape(ingredients[i]),
308 + ]], x,y, minetest.formspec_escape(group_eval(ingredients[i])),
272 309 x,y, minetest.formspec_escape(tt))
273 310 else
274 311 if k.drawslots == nil or k.drawslots then
275 312 t = string.format('box[%f,%f;0.1,0.1;#00000060]',x+0.45,y+0.45) .. t
276 313 end
277 314 end
278 315 end
................................................................................
336 373
337 374 dungeon_loot.register {
338 375 name = 'sorcery:recipe';
339 376 chance = 0.9;
340 377 count = {1,7};
341 378 }
342 379
343 -minetest.register_craft { type = 'fuel', recipe = 'sorcery:recipe', burntime = 3 }
344 -minetest.register_craft {
345 - type = 'cooking';
346 - recipe = 'sorcery:recipe';
347 - output = 'sorcery:ash';
348 - cooktime = 3;
349 -}
350 -
351 380 default.register_craft_metadata_copy('default:paper','sorcery:recipe')
381 +-- this seems bugged; it doesn't like it when its item shows up in another
382 +-- recipe. so we'll do it manually :/
352 383 -- default.register_craft_metadata_copy('default:book','sorcery:cookbook')
353 384
354 385 for i=1,8 do
355 386 local rcp = {}
356 387 for i=1,i do rcp[i] = 'sorcery:recipe' end
357 388 rcp[#rcp+1]='default:book' minetest.register_craft {
358 389 type = 'shapeless', recipe = rcp, output = 'sorcery:cookbook';
359 390 }
360 391 rcp[#rcp]='sorcery:cookbook' minetest.register_craft {
361 392 type = 'shapeless', recipe = rcp, output = 'sorcery:cookbook';
362 393 }
363 394 end
364 395
396 +minetest.register_craft {
397 + type = 'shapeless';
398 + recipe = {
399 + 'sorcery:cookbook';
400 + 'default:book';
401 + };
402 + output = 'sorcery:cookbook';
403 +};
365 404
366 405 local m = sorcery.lib.marshal
367 406 local encbook, decbook = m.transcoder {
368 407 pages = m.g.array(8, m.g.struct {
369 408 kind = m.t.str;
370 409 name = m.t.str;
371 410 })
................................................................................
459 498 end
460 499
461 500 uinv:set_stack('main',idx,stack)
462 501 bookform(stack,user)
463 502 end)
464 503
465 504 minetest.register_on_craft(function(stack,player,grid,inv)
505 + -- god this is messy. i'm sorry. minetest made me do it
466 506 if stack:get_name() ~= 'sorcery:cookbook' then return nil end
467 507
468 508 local oldbook
469 509 local topic, onetopic = nil, true
470 510 local recipes = {}
471 - for _,s in pairs(grid) do
511 + local copybook = false
512 + local obindex
513 + for i,s in pairs(grid) do
472 514 if s:get_name() == 'sorcery:recipe' then
473 515 recipes[#recipes+1] = s
474 - elseif s:get_name() == 'sorcery:cookbook' then oldbook = s end
516 + elseif s:get_name() == 'default:book' then copybook = true
517 + elseif s:get_name() == 'sorcery:cookbook' then oldbook = s obindex = i end
518 + end
519 +
520 + if #recipes == 0 and copybook and oldbook then
521 + inv:set_stack('craft',obindex,oldbook)
522 + local newmeta = stack:get_meta()
523 + local copy = function(field)
524 + newmeta:set_string(field,oldbook:get_meta():get_string(field))
525 + end
526 + copy('cookbook') copy('description')
527 + newmeta:set_string('owner',player:get_player_name())
528 + return stack
475 529 end
476 530
477 531 oldbook = oldbook or stack
478 532 local bookmeta = oldbook:get_meta()
479 533 local newbook = not bookmeta:contains('cookbook')
480 534 local book = bookprops(oldbook)
481 535
................................................................................
494 548
495 549 if topic and newbook then
496 550 if not onetopic then topic = nil end
497 551 bookmeta:set_string('description',namebook(topic,player:get_player_name()))
498 552 bookmeta:set_string('owner',player:get_player_name())
499 553 end
500 554
501 - print('new book',bookmeta:get_string('description'))
502 - print('new book',dump(book))
503 555 bookmeta:set_string('cookbook', sorcery.lib.str.meta_armor(encbook(book),true))
504 556 return oldbook
505 557 end)
506 558
507 559 if minetest.get_modpath('books') then
508 560 -- make our own placeable cookbook somehow
509 561 end