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