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