31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
...
468
469
470
471
472
473
474
475
476
477
478
479
480
481
...
483
484
485
486
487
488
489
490
491
492
493
494
495
496
...
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
|
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};
}
local props_builtin = function(item)
................................................................................
return names[math.random(#names)]
end end
local find_builtin = function(out)
local rec = {}
local i = minetest.get_craft_recipe(out)
if i == nil or i.items == nil or #i.items == 0 then return nil end
local w = (i.width == 0) and 3 or i.width
for j=1,#i.items do
local row = math.floor((j-1) / w)
local col = (j-1) % w
if i.items[j] then
rec[1 + (row * 3) + col] = i.items[j]
end
end
return rec
................................................................................
end
end;
}
sorcery.cookbook.classes = {
craft = {
name = 'Crafting Guide';
node = 'xdecor:workbench';
booksuf = 'Manual';
w = 3, h = 3;
chance = 2;
slots = slot3x3;
pick = pick_builtin('normal');
find = find_builtin;
desc = desc_builtin;
props = props_builtin;
apply_exclusions = true;
};
-- smelt = {
-- w = 3, h = 3;
-- slots = slot3x3;
-- };
................................................................................
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;
desc = desc_builtin;
props = props_builtin;
slots = {
{0,1},
{0,0};
};
find = function(out)
cache:populate_grindables()
................................................................................
end
end
local img, ot
local props = k.props(result)
if props.note then
local nx, ny, nw, nh
if notes_right then
nx = 5 ny = 0
nw = 3 nh = 3
else
nx = 0 ny = 3
nw = 4 nh = 1
end
t = t .. string.format([[
textarea[%f,%f;%f,%f;;;%s]
]], nx,ny,nw,nh, minetest.formspec_escape(props.note))
end
if k.icon then img = k.icon(result) end
if k.outdesc then ot = k.outdesc(result) else ot = desc_builtin(result) end
-- image[%f,%f;1,1;gui_furnace_arrow_bg.png^[transformR270]
return t .. string.format([[
item_image[%f,%f;1,1;%s]tooltip[%f,%f;1,1;%s]
................................................................................
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;
})
................................................................................
local bookprops = function(stack)
local meta = stack:get_meta()
if meta:contains('cookbook') then
return decbook(sorcery.lib.str.meta_dearmor(meta:get_string('cookbook'),true))
else return {pages={}} end
end
local bookform_ctx = {}
local bookform = function(stack,user)
bookform_ctx[user:get_player_name()] = user:get_wield_index()
local meta = stack:get_meta()
local book = bookprops(stack)
................................................................................
local curpage = meta:contains("pagenr") and meta:get_int("pagenr") or 1
local pgofs = (curpage - 1) * constants.recipes_per_cookbook_page
local form = string.format([[
formspec_version[3]
size[10,12]real_coordinates[true]
box[0,0;10,1;#580C39FF]label[0.4,0.5;%s]
button_exit[3,11;4,1;quit;Page %u/%u]
]], minetest.formspec_escape(meta:get_string('description')),
curpage, pagect)
if curpage > 1 then form = form .. 'button[0,11;3,1;pageback;< Back]' end
if curpage < pagect then form = form .. 'button[7,11;3,1;pagenext;Next >]' end
local coords = {
{2,1.3};
{2,4.5};
{2,7.7};
-- {0,1.3}, {4, 1.3};
-- {0,4.7}, {4, 4.7};
-- {0,8.1}, {4, 8.1};
}
for i=pgofs,(pgofs + constants.recipes_per_cookbook_page-1) do
local maxw, maxh = 3, 2
if not book.pages[i+1] then break end
|
>
|
>
|
<
<
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
|
|
|
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
..
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
...
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
...
496
497
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
...
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
|
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' };
};
}
sorcery.cookbook.constants = constants
local slot3x3 = {
{0,0}, {1,0}, {2,0};
{0,1}, {1,1}, {2,1};
{0,2}, {1,2}, {2,2};
}
local props_builtin = function(item)
................................................................................
return names[math.random(#names)]
end end
local find_builtin = function(out)
local rec = {}
local i = minetest.get_craft_recipe(out)
if i == nil or i.items == nil or #i.items == 0 then return nil end
local w = (i.width == 0) and 3 or i.width
-- for j=1,#i.items do
for j,item in pairs(i.items) do
local row = math.floor((j-1) / w)
local col = (j-1) % w
if i.items[j] then
rec[1 + (row * 3) + col] = i.items[j]
end
end
return rec
................................................................................
end
end;
}
sorcery.cookbook.classes = {
craft = {
name = 'Crafting Guide';
node = 'xdecor:workbench';
booksuf = 'Codex';
w = 3, h = 3;
chance = 2;
slots = slot3x3;
pick = pick_builtin('normal');
find = find_builtin;
props = props_builtin;
apply_exclusions = true;
};
-- smelt = {
-- w = 3, h = 3;
-- slots = slot3x3;
-- };
................................................................................
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)
cache:populate_grindables()
................................................................................
end
end
local img, ot
local props = k.props(result)
if props.note then
local nx, ny, nw, nh
if notes_right then
nx = 5.25 ny = 0
nw = 4 nh = 3
else
nx = 0 ny = 3
nw = 4 nh = 1
end
t = t .. string.format([[
hypertext[%f,%f;%f,%f;note;<global valign=middle halign=justify size=20>%s]
]], nx,ny,nw,nh, minetest.formspec_escape(props.note))
end
if k.icon then img = k.icon(result) end
if k.outdesc then ot = k.outdesc(result) else ot = desc_builtin(result) end
-- image[%f,%f;1,1;gui_furnace_arrow_bg.png^[transformR270]
return t .. string.format([[
item_image[%f,%f;1,1;%s]tooltip[%f,%f;1,1;%s]
................................................................................
type = 'shapeless';
recipe = {
'sorcery:cookbook';
'default:book';
};
output = 'sorcery:cookbook';
};
-- erase cookbooks in the usual way
minetest.register_craft {
type = 'shapeless';
recipe = {
'sorcery:cookbook';
'bucket:bucket_water';
};
output = 'default:book';
replacements = {
{'bucket:bucket_water','bucket:bucket_empty'};
};
};
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;
})
................................................................................
local bookprops = function(stack)
local meta = stack:get_meta()
if meta:contains('cookbook') then
return decbook(sorcery.lib.str.meta_dearmor(meta:get_string('cookbook'),true))
else return {pages={}} end
end
sorcery.cookbook.get = bookprops
sorcery.cookbook.set = function(stack,props)
local meta = stack:get_meta()
meta:set_string('cookbook', sorcery.lib.str.meta_armor(encbook(props),true))
end
sorcery.cookbook.defaults = {
indesc = desc_builtin;
outdesc = desc_builtin;
title = desc_builtin;
props = props_builtin;
pick = pick_builtin;
find = find_builtin;
}
sorcery.cookbook.recfn = function(class,fn)
local c = sorcery.cookbook.classes[class]
if c[fn] then return c[fn] end
return sorcery.cookbook.defaults[fn]
end
local bookform_ctx = {}
local bookform = function(stack,user)
bookform_ctx[user:get_player_name()] = user:get_wield_index()
local meta = stack:get_meta()
local book = bookprops(stack)
................................................................................
local curpage = meta:contains("pagenr") and meta:get_int("pagenr") or 1
local pgofs = (curpage - 1) * constants.recipes_per_cookbook_page
local form = string.format([[
formspec_version[3]
size[10,12]real_coordinates[true]
box[0,0;10,1;#580C39FF]label[0.4,0.5;%s]
style[pgind;border=false]
style[pgind:hovered;content_offset=0,0]
button[3,11;4,1;pgind;Page %u/%u]
]], minetest.formspec_escape(meta:get_string('description')),
curpage, pagect)
-- using an extremely dishonorable trick to fake centered text
if curpage > 1 then form = form .. 'button[0,11;3,1;pageback;< Back]' end
if curpage < pagect then form = form .. 'button[7,11;3,1;pagenext;Next >]' end
local coords = {
{0.85,1.3};
{0.85,4.5};
{0.85,7.7};
-- {0,1.3}, {4, 1.3};
-- {0,4.7}, {4, 4.7};
-- {0,8.1}, {4, 8.1};
}
for i=pgofs,(pgofs + constants.recipes_per_cookbook_page-1) do
local maxw, maxh = 3, 2
if not book.pages[i+1] then break end
|