RealBadAngel
2013-03-02 310cdb06ad3c2db5ca9114da3441413047fa7922
commit | author | age
a4a3c2 1 --data tables definitions
R 2 unified_inventory = {}
3 unified_inventory.players = {}
4 unified_inventory.current_page = {}
5 unified_inventory.current_index = {}
6 unified_inventory.items_list_size = 0
7 unified_inventory.items_list = {}
8 unified_inventory.filtered_items_list_size = {}
9 unified_inventory.filtered_items_list = {}
10 unified_inventory.activefilter = {}
11 unified_inventory.alternate = {}
12 unified_inventory.current_item = {}
13
14 -- default inventory page
15 unified_inventory.default = "craft"
16
17 -- homepos stuff
18 local home_gui = {}
19 local homepos = {}
20 unified_inventory.home_filename = minetest.get_worldpath()..'/unified_inventory_home'
21
22 -- Create detached creative inventory after loading all mods
23 minetest.after(0.01, function()
24     unified_inventory.items_list = {}
25     for name,def in pairs(minetest.registered_items) do
26         if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
27                 and def.description and def.description ~= "" then
28             table.insert(unified_inventory.items_list, name)
29         end
30     end
31     table.sort(unified_inventory.items_list)
32     unified_inventory.items_list_size = #unified_inventory.items_list
33     print ("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
34 end)
35
36 -- register_on_joinplayer
37 minetest.register_on_joinplayer(function(player)
38     local player_name = player:get_player_name()
35cf96 39     unified_inventory.players[player_name]={}
R 40     unified_inventory.players[player_name]["sound_volume"]=minetest.setting_get("sound_volume")*10
a4a3c2 41     unified_inventory.current_index[player_name] = 1
R 42     unified_inventory.filtered_items_list[player_name] = {}
43     unified_inventory.filtered_items_list[player_name] = unified_inventory.items_list
44     unified_inventory.filtered_items_list_size[player_name]=unified_inventory.items_list_size
45     unified_inventory.activefilter[player_name]=""
36b104 46     unified_inventory.apply_filter(player, "")
a4a3c2 47     unified_inventory.alternate[player_name] = 1
R 48     unified_inventory.current_item[player_name] =nil
49     unified_inventory.set_inventory_formspec(player,unified_inventory.get_formspec(player, unified_inventory.default))
50
51 --crafting guide inventories    
52 local inv = minetest.create_detached_inventory(player:get_player_name().."craftrecipe",{
53     allow_put = function(inv, listname, index, stack, player)
54         return 0
55         end,
56         allow_take = function(inv, listname, index, stack, player)
3a8a46 57             if minetest.setting_getbool("creative_mode") then
R 58                 return stack:get_count()
59             else
60                 return 0
61             end
a4a3c2 62         end,
R 63         allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
64             return 0
65         end,
66     })
67     inv:set_size("output", 1)
68     inv:set_size("build", 3*3)
69
70 -- refill slot
71 unified_inventory.refill = minetest.create_detached_inventory(player_name.."refill", {
72     allow_put = function(inv, listname, index, stack, player)
73         if minetest.setting_getbool("creative_mode") then
74             return stack:get_count()
75         else
76             return 0
77         end
78     end,
79     on_put = function(inv, listname, index, stack, player)
80         inv:set_stack(listname, index, ItemStack(stack:get_name().." "..stack:get_stack_max()))
81     end,
82 })
83 unified_inventory.refill:set_size("main", 1)
84 end)
85
86 -- trash slot
87 unified_inventory.trash = minetest.create_detached_inventory("trash", {
88     allow_put = function(inv, listname, index, stack, player)
89         if minetest.setting_getbool("creative_mode") then
90             return stack:get_count()
91         else
92             return 0
93         end
94     end,
95     on_put = function(inv, listname, index, stack, player)
96         inv:set_stack(listname, index, nil)
97     end,
98 })
99 unified_inventory.trash:set_size("main", 1)
100
101 -- set_inventory_formspec
102 unified_inventory.set_inventory_formspec = function(player,formspec)
103     if player then
104         if minetest.setting_getbool("creative_mode") then
105             -- if creative mode is on then wait a bit
106             minetest.after(0.01,function()
107             player:set_inventory_formspec(formspec)
108             end)
109         else
110         player:set_inventory_formspec(formspec)
111         end
112     end
113 end
114
115 -- get_formspec
116 unified_inventory.get_formspec = function(player,page)
117     if player==nil then    return "" end
118     local player_name = player:get_player_name()
119     unified_inventory.current_page[player_name]=page
120     
121     local formspec = "size[14,10]"
eff76c 122
a4a3c2 123     -- player inventory
R 124     formspec = formspec .. "list[current_player;main;0,4.5;8,4;]"
eff76c 125
21e626 126     -- backgrounds
VE 127         formspec = formspec .. "background[-0.19,-0.2,;14.38,10.55;ui_form_bg.png]"
128     if page=="craft" then
129         formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_crafting_form.png]"
130         end
131     if page=="craftguide" then
132         formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_craftguide_form.png]"
133         end
134     if page=="misc" then
135         formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_misc_form.png]"
136         end
137     if page=="bags" then
138         formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_bags_main_form.png]"
139         end
140
141     for i=1,4 do
142         if page=="bag"..i then
143             local slots = player:get_inventory():get_stack(page, 1):get_definition().groups.bagslots
144             if slots == 8 then
145                 formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_bags_sm_form.png]"
146             elseif slots == 16 then
147                 formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_bags_med_form.png]"
148             elseif slots == 24 then
149                 formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_bags_lg_form.png]"
150             end
151         end
152     end
153
a4a3c2 154     -- main buttons
310cdb 155         local start_x=0
R 156         formspec = formspec .. "image_button["..(start_x+.65*0)..",9;.8,.8;ui_craft_icon.png;craft;]"
157         formspec = formspec .. "image_button["..(start_x+.65*1)..",9;.8,.8;ui_craftguide_icon.png;craftguide;]"
158         formspec = formspec .. "image_button["..(start_x+.65*2)..",9;.8,.8;ui_bags_icon.png;bags;]"
159         formspec = formspec .. "image_button["..(start_x+.65*3)..",9;.8,.8;ui_sethome_icon.png;home_gui_set;]"
160         formspec = formspec .. "image_button["..(start_x+.65*4)..",9;.8,.8;ui_gohome_icon.png;home_gui_go;]"
161         if minetest.setting_getbool("creative_mode") then
162         formspec = formspec .. "image_button["..(start_x+.65*5)..",9;.8,.8;ui_sun_icon.png;misc_set_day;]"
163         formspec = formspec .. "image_button["..(start_x+.65*6)..",9;.8,.8;ui_moon_icon.png;misc_set_night;]"
164         formspec = formspec .. "image_button["..(start_x+.65*7)..",9;.8,.8;ui_trash_icon.png;clear_inv;]"
165         end
166         
a4a3c2 167     --controls to flip items pages
310cdb 168         start_x=9.2
R 169         formspec = formspec .. "image_button["..(start_x+.6*0)..",9;.8,.8;ui_skip_backward_icon.png;start_list;]"
170         formspec = formspec .. "image_button["..(start_x+.6*1)..",9;.8,.8;ui_doubleleft_icon.png;rewind3;]"
171         formspec = formspec .. "image_button["..(start_x+.6*2)..",9;.8,.8;ui_left_icon.png;rewind1;]"
172         formspec = formspec .. "image_button["..(start_x+.6*3)..",9;.8,.8;ui_right_icon.png;forward1;]"
173         formspec = formspec .. "image_button["..(start_x+.6*4)..",9;.8,.8;ui_doubleright_icon.png;forward3;]"
174         formspec = formspec .. "image_button["..(start_x+.6*5)..",9;.8,.8;ui_skip_forward_icon.png;end_list;]"
175         
eff76c 176     -- search box
310cdb 177         formspec = formspec .. "field[9.5,8.325;3,1;searchbox;;]"
R 178         formspec = formspec .. "image_button[12.2,8.1;.8,.8;ui_search_icon.png;searchbutton;]"
eff76c 179
a4a3c2 180     -- craft page
R 181     if page=="craft" then
182         formspec = formspec.."label[0,0;Crafting]"
183         formspec = formspec.."list[current_player;craftpreview;6,1;1,1;]"
184         formspec = formspec.."list[current_player;craft;2,1;3,3;]"
185             if minetest.setting_getbool("creative_mode") then
186                 formspec = formspec.."label[0,2.5;Refill:]"
187                 formspec = formspec.."list[detached:"..player_name.."refill;main;0,3;1,1;]"
188                 formspec = formspec.."label[7,2.5;Trash:]"
189                 formspec = formspec.."list[detached:trash;main;7,3;1,1;]"
190             end
191         end
eff76c 192
a4a3c2 193     -- craft guide page
R 194     if page=="craftguide" then
195         formspec = formspec.."label[0,0;Crafting Guide]"
196         formspec = formspec.."list[detached:"..player_name.."craftrecipe;build;2,1;3,3;]"
197         formspec = formspec.."list[detached:"..player_name.."craftrecipe;output;6,1;1,1;]"
198         formspec = formspec.."label[2,0.5;Input:]"
199         formspec = formspec.."label[6,0.5;Output:]"
200         formspec = formspec.."label[6,2.6;Method:]"
201         local item_name=unified_inventory.current_item[player_name]
202         if item_name then
203             formspec = formspec.."label[2,0;"..item_name.."]"    
204             local alternates = 0
205             local alternate = unified_inventory.alternate[player_name]
206             local crafts = crafts_table[item_name]
eff76c 207
a4a3c2 208             if crafts ~= nil then
R 209                 alternates = #crafts
210                 local craft = crafts[alternate]
211                 local method = "Crafting"
212                 if craft.type == "shapeless" then
213                 method="Crafting"
214                 end    
215                 if craft.type == "cooking" then
216                 method="Cooking"
217                 end    
218                 if craft.type == "fuel" then
219                 method="Fuel"
220                 end    
221                 if craft.type == "grinding" then
222                 method="Grinding"
223                 end    
224                 if craft.type == "alloy" then
225                 method="Alloy cooking"
226                 end    
227                 formspec = formspec.."label[6,3;"..method.."]"
228             end
229             
230             if alternates > 1 then
231             formspec = formspec.."label[0,2.6;Recipe "..tostring(alternate).." of "..tostring(alternates).."]"
232             formspec = formspec.."button[0,3.15;2,1;alternate;Alternate]"
233             end
234         end
235     end
315881 236
a4a3c2 237     -- bags
R 238     if page=="bags" then
315881 239     formspec = formspec.."label[0,0;Bags]"
a4a3c2 240     formspec=formspec.."button[0,2;2,0.5;bag1;Bag 1]"
R 241     formspec=formspec.."button[2,2;2,0.5;bag2;Bag 2]"
242     formspec=formspec.."button[4,2;2,0.5;bag3;Bag 3]"
243     formspec=formspec.."button[6,2;2,0.5;bag4;Bag 4]"
244     formspec=formspec.."list[detached:"..player_name.."_bags;bag1;0.5,1;1,1;]"
245     formspec=formspec.."list[detached:"..player_name.."_bags;bag2;2.5,1;1,1;]"
246     formspec=formspec.."list[detached:"..player_name.."_bags;bag3;4.5,1;1,1;]"
247     formspec=formspec.."list[detached:"..player_name.."_bags;bag4;6.5,1;1,1;]"
248         end
315881 249
a4a3c2 250     for i=1,4 do
R 251         if page=="bag"..i then
252             local image = player:get_inventory():get_stack("bag"..i, 1):get_definition().inventory_image
253             formspec=formspec.."image[7,0;1,1;"..image.."]"
254             formspec=formspec.."list[current_player;bag"..i.."contents;0,1;8,3;]"
255         end
256     end
315881 257
a4a3c2 258     --Items list
R 259     local list_index=unified_inventory.current_index[player_name]
260     local page=math.floor(list_index / (80) + 1)
261     local pagemax = math.floor((unified_inventory.filtered_items_list_size[player_name]-1) / (80) + 1)
262     local image
263     local item={}
264     for y=0,9,1 do
265     for x=0,7,1 do
266         name=unified_inventory.filtered_items_list[player_name][list_index]    
267         if minetest.registered_items[name] then
268         formspec=formspec.."item_image_button["..(8.2+x*.7)..","..(1+y*.7)..";.81,.81;"..name..";item_button"..list_index..";]"
269         list_index=list_index+1
270         end
271     end
272     end    
273     formspec=formspec.."label[8.2,0;Page:]"
274     formspec=formspec.."label[9,0;"..page.." of "..pagemax.."]"
275     formspec=formspec.."label[8.2,0.4;Filter:]"
276     formspec=formspec.."label[9,0.4;"..unified_inventory.activefilter[player_name].."]"
277     return formspec
278 end
279
280 -- register_on_player_receive_fields
281 minetest.register_on_player_receive_fields(function(player, formname, fields)
282     local player_name = player:get_player_name()
283     
284     -- main buttons
285     if fields.craft then
286         unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craft"))
287         return
288     end
289     
290     if fields.craftguide then
291         unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craftguide"))
292         return
293     end
294     
295     if fields.bags then
296         unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"bags"))
297         return
298     end
310cdb 299
R 300
a4a3c2 301     
R 302     -- bags
303     for i=1,4 do
304         local page = "bag"..i
305         if fields[page] then
306             if player:get_inventory():get_stack(page, 1):get_definition().groups.bagslots==nil then
307                 page = "bags"
308             end
309             unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,page))
310             return
311         end
312     end
313     
314     -- Miscellaneous
315     if fields.home_gui_set then
316         unified_inventory.set_home(player, player:getpos())
310cdb 317         local home = homepos[player_name]
R 318         if home ~= nil then
319             minetest.chat_send_player(player_name, "Home position set to: "..math.floor(home.x)..","..math.floor(home.y)..","..math.floor(home.z))
320         end
a4a3c2 321     end
R 322     if fields.home_gui_go then
323         unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craft"))
324         unified_inventory.go_home(player)
325     end
326     if fields.misc_set_day then
327         if minetest.get_player_privs(player_name).settime==true then 
328         minetest.env:set_timeofday((6000 % 24000) / 24000)
329         minetest.chat_send_player(player_name, "Time of day set to 6am")
330         else
331         minetest.chat_send_player(player_name, "You don't have settime priviledge!")
332         end
333     end
334     if fields.misc_set_night then
335         if minetest.get_player_privs(player_name).settime==true then     
336         minetest.env:set_timeofday((21000 % 24000) / 24000)
337         minetest.chat_send_player(player_name, "Time of day set to 9pm")
338         else
339         minetest.chat_send_player(player_name, "You don't have settime priviledge!")    
340         end    
341     end
310cdb 342
R 343     if fields.clear_inv then
344         local inventory = {}
345         player:get_inventory():set_list("main", inventory)
346         minetest.chat_send_player(player_name, 'Inventory Cleared!')
315881 347     end
a4a3c2 348     
R 349     -- Inventory page controls
350     local start=math.floor(unified_inventory.current_index[player_name]/80 +1 )
351     local start_i=start
352     local pagemax = math.floor((unified_inventory.filtered_items_list_size[player_name]-1) / (80) + 1)
353     
354     if fields.start_list then
355         start_i = 1
356     end
357     if fields.rewind1 then
358         start_i = start_i - 1
359     end
360     if fields.forward1 then
361         start_i = start_i + 1
362     end
363     if fields.rewind3 then
364         start_i = start_i - 3
365     end
366     if fields.forward3 then
367         start_i = start_i + 3
368     end
369     if fields.end_list then
370         start_i = pagemax
371     end
372     if start_i < 1 then
373         start_i = 1
374     end
375     if start_i > pagemax then
376         start_i =  pagemax
377     end
378     if not (start_i    ==start) then
379         unified_inventory.current_index[player_name] = (start_i-1)*80+1
380         unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name]))
381         end
382     
383     -- Item list buttons
384     local list_index=unified_inventory.current_index[player_name]
385     local page=unified_inventory.current_page[player_name]
386     for i=0,80,1 do
387         local button="item_button"..list_index
388         if fields[button] then 
389             if minetest.setting_getbool("creative_mode")==false then
390                 unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craftguide"))
391                 page="craftguide"
310cdb 392                 end
a4a3c2 393             if page=="craftguide" then 
R 394                 unified_inventory.current_item[player_name] = unified_inventory.filtered_items_list[player_name][list_index] 
395                 unified_inventory.alternate[player_name] = 1
396                 unified_inventory.update_recipe (player, unified_inventory.filtered_items_list[player_name][list_index], 1)
397                 unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name]))
398             else
399                 if minetest.setting_getbool("creative_mode") then
400                     local inv = player:get_inventory()
401                     dst_stack={}
402                     dst_stack["name"] = unified_inventory.filtered_items_list[player_name][list_index] 
403                     dst_stack["count"]=99
404                     if inv:room_for_item("main",dst_stack) then
405                     inv:add_item("main",dst_stack)
406                     end
407                 end    
408             end    
409         end    
410     list_index=list_index+1
411     end
412     
413     if fields.searchbutton then
36b104 414         unified_inventory.apply_filter(player, fields.searchbox)
a4a3c2 415         unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name]))
R 416     end    
417     
418     -- alternate button
419     if fields.alternate then
420         local item_name=unified_inventory.current_item[player_name]
421         if item_name then
422             local alternates = 0
423             local alternate=unified_inventory.alternate[player_name]
424             local crafts = crafts_table[item_name]
425             if crafts ~= nil then
426                 alternates = #crafts
427             end
428             if alternates > 1 then
429             alternate=alternate+1
430             if alternate>alternates then
431                 alternate=1
432             end
433             unified_inventory.alternate[player_name]=alternate        
434             unified_inventory.update_recipe (player, unified_inventory.current_item[player_name], alternate)
435             unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name]))
436             end
437         end    
438     end        
439 end)
440
441 -- load_home
442 local load_home = function()
443     local input = io.open(unified_inventory.home_filename..".home", "r")
444     if input then
445         while true do
446             local x = input:read("*n")
447             if x == nil then
448                 break
449             end
450             local y = input:read("*n")
451             local z = input:read("*n")
452             local name = input:read("*l")
453             homepos[name:sub(2)] = {x = x, y = y, z = z}
454         end
455         io.close(input)
456     else
457         homepos = {}
458     end
459 end
460 load_home() -- run it now
461
462 -- set_home
463 unified_inventory.set_home = function(player, pos)
310cdb 464     local player_name=player:get_player_name()
R 465     homepos[player_name] = pos
a4a3c2 466     -- save the home data from the table to the file
R 467     local output = io.open(unified_inventory.home_filename..".home", "w")
468     for k, v in pairs(homepos) do
469         if v ~= nil then
470             output:write(math.floor(v.x).." "..math.floor(v.y).." "..math.floor(v.z).." "..k.."\n")
471         end
472     end
473     io.close(output)
474 end
475
476 -- go_home 
477 unified_inventory.go_home = function(player)
478     local pos = homepos[player:get_player_name()]
479     if pos~=nil then
480         player:setpos(pos)
481     end
482 end
483
484 --apply filter to the inventory list (create filtered copy of full one)
36b104 485 unified_inventory.apply_filter = function(player,filter)
K 486     local player_name = player:get_player_name() 
a4a3c2 487     local size=0
R 488     local str_temp1=string.lower(filter)
489     local str_temp2
490     local str_temp3
491     unified_inventory.filtered_items_list[player_name]={}
492     for name,def in pairs(minetest.registered_items) do
493         if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
494                 and def.description and def.description ~= "" then
495             str_temp2=string.lower(def.name)
496             str_temp3=string.lower(def.description)
497             if string.find(str_temp2, str_temp1) or string.find(str_temp3, str_temp1) then
498                 table.insert(unified_inventory.filtered_items_list[player_name], name)
499                 size=size+1
500             end
501         end
502     
503     end
504     table.sort(unified_inventory.filtered_items_list[player_name])
505     unified_inventory.filtered_items_list_size[player_name]=size
506     unified_inventory.current_index[player_name]=1    
507     unified_inventory.activefilter[player_name]=filter
508     unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name]))
509 end
510
511
512 -- update_recipe
513 unified_inventory.update_recipe = function(player, stack_name, alternate)
514     --print("Lookup:"..stack_name)
515     local inv = minetest.get_inventory({type="detached", name=player:get_player_name().."craftrecipe"})    
516     for i=0,inv:get_size("build"),1 do
517         inv:set_stack("build", i, nil)
518     end
519     inv:set_stack("cook", 1, nil)
520     inv:set_stack("fuel", 1, nil)
521
522     inv:set_stack("output", 1, stack_name)
523     local def
524     alternate = tonumber(alternate) or 1
525     local crafts = crafts_table[stack_name]
526     if crafts == nil then
527         --minetest.chat_send_player(player:get_player_name(), "no recipe available for "..stack_name)
528         return
529     end
530     if alternate < 1 or alternate > #crafts then
531         alternate = 1
532     end
533     local craft = crafts[alternate]
534     --print (dump(craft))
535     --minetest.chat_send_player(player:get_player_name(), "recipe for "..stack_name..": "..dump(craft))
536     
537     local itemstack = ItemStack(craft.output)
538     inv:set_stack("output", 1, itemstack)
539
540     -- cook, fuel, grinding recipes
541     if craft.type == "cooking" or craft.type == "fuel" or craft.type == "grinding" then
542         def=unified_inventory.find_item_def(craft.recipe)
543         if def then
544             inv:set_stack("build", 1, def)
545         end
546         return 
547     end
548     
549     -- build (shaped or shapeless)
550     if craft.recipe[1] then
551         def=unified_inventory.find_item_def(craft.recipe[1])
552         if def then
553             inv:set_stack("build", 1, def)
554         else
555             def=unified_inventory.find_item_def(craft.recipe[1][1])
556             if def then
557                 inv:set_stack("build", 1, def)
558             end
559             def=unified_inventory.find_item_def(craft.recipe[1][2])
560             if def then
561                 inv:set_stack("build", 2, def)
562             end
563             def=unified_inventory.find_item_def(craft.recipe[1][3])
564             if def then
565                 inv:set_stack("build", 3, def)
566             end
567         end
568     end
569     if craft.recipe[2] then
570         def=unified_inventory.find_item_def(craft.recipe[2])
571         if def then
572             inv:set_stack("build", 2, def)
573         else
574             def=unified_inventory.find_item_def(craft.recipe[2][1])
575             if def then
576                 inv:set_stack("build", 4, def)
577             end
578             def=unified_inventory.find_item_def(craft.recipe[2][2])
579             if def then
580                 inv:set_stack("build", 5, def)
581             end
582             def=unified_inventory.find_item_def(craft.recipe[2][3])
583             if def then
584                 inv:set_stack("build", 6, def)
585             end
586         end
587     end
588     
589     if craft.recipe[3] then
590         def=unified_inventory.find_item_def(craft.recipe[3])
591         if def then
592             inv:set_stack("build", 3, def)
593         else
594             def=unified_inventory.find_item_def(craft.recipe[3][1])
595             if def then
596                 inv:set_stack("build", 7, def)
597             end
598             def=unified_inventory.find_item_def(craft.recipe[3][2])
599             if def then
600                 inv:set_stack("build", 8, def)
601             end
602             def=unified_inventory.find_item_def(craft.recipe[3][3])
603             if def then
604                 inv:set_stack("build", 9, def)
605             end
606         end
607     end
608     if craft.recipe[4] then
609         def=unified_inventory.find_item_def(craft.recipe[4])
610         if def then
611             inv:set_stack("build", 4, def)
612         end
613     end
614     if craft.recipe[5] then
615         def=unified_inventory.find_item_def(craft.recipe[5])
616         if def then
617             inv:set_stack("build", 5, def)
618         end
619     end
620     if craft.recipe[6] then
621         def=unified_inventory.find_item_def(craft.recipe[6])
622         if def then
623             inv:set_stack("build", 6, def)
624         end
625     end
626     if craft.recipe[7] then
627         def=unified_inventory.find_item_def(craft.recipe[7])
628         if def then
629             inv:set_stack("build", 7, def)
630         end
631     end
632     if craft.recipe[8] then
633         def=unified_inventory.find_item_def(craft.recipe[8])
634         if def then
635             inv:set_stack("build", 8, def)
636         end
637     end
638     if craft.recipe[9] then
639         def=unified_inventory.find_item_def(craft.recipe[9])
640         if def then
641             inv:set_stack("build", 9, def)
642         end
643     end
644 end
645
646 unified_inventory.find_item_def = function(def1)
647 if type(def1)=="string" then
648     if string.find(def1, "group:") then
649         def1=string.gsub(def1, "group:", "")
650         def1=string.gsub(def1, '\"', "")
651         for name,def in pairs(minetest.registered_items) do
652                 if def.groups[def1] == 1 and def.groups.not_in_creative_inventory ~= 1 then
653                     return def
654                 end
655         end
656     else
657     return def1
658     end
659 end
660 return nil
661 end