]> git.lizzy.rs Git - elidragon_v2.git/blob - mods/elidragon_grouplist/init.lua
Add grouplist API
[elidragon_v2.git] / mods / elidragon_grouplist / init.lua
1 local grouplist = {}
2 grouplist.lists = {}
3
4 function grouplist.register(group)
5         local list = {}
6         grouplists.lists[group] = list
7         return list
8 end
9
10 function grouplist.get(group)
11         return grouplist.lists[group] or {}
12 end
13
14 function grouplist.insert(item, group)
15         table.insert(grouplist.get(group), item)
16 end
17
18 minetest.register_on_mods_loaded(function()
19         for nodename, nodedef in pairs(minetest.registered_items) do
20                 for group, list in pairs(grouplist.lists) do
21                         if nodedef.groups[group] and nodedef.groups[group] > 0 then
22                                 table.insert(list, nodename)
23                         end
24                 end
25         end
26 end)
27
28 elidragon.grouplist = grouplist