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