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