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