]> git.lizzy.rs Git - elidragon_v2.git/commitdiff
Add grouplist API
authorElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 19 Feb 2021 09:46:56 +0000 (10:46 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 19 Feb 2021 09:46:56 +0000 (10:46 +0100)
mods/elidragon_grouplist/init.lua [new file with mode: 0644]
mods/elidragon_grouplist/mod.conf [new file with mode: 0644]

diff --git a/mods/elidragon_grouplist/init.lua b/mods/elidragon_grouplist/init.lua
new file mode 100644 (file)
index 0000000..26d9dd3
--- /dev/null
@@ -0,0 +1,28 @@
+local grouplist = {}
+grouplist.lists = {}
+
+function grouplist.register(group)
+       local list = {}
+       grouplists.lists[group] = list
+       return list
+end
+
+function grouplist.get(group)
+       return grouplist.lists[group] or {}
+end
+
+function grouplist.insert(item, group)
+       table.insert(grouplist.get(group), item)
+end
+
+minetest.register_on_mods_loaded(function()
+       for nodename, nodedef in pairs(minetest.registered_items) do
+               for group, list in pairs(grouplist.lists) do
+                       if nodedef.groups[group] and nodedef.groups[group] > 0 then
+                               table.insert(list, nodename)
+                       end
+               end
+       end
+end)
+
+elidragon.grouplist = grouplist
diff --git a/mods/elidragon_grouplist/mod.conf b/mods/elidragon_grouplist/mod.conf
new file mode 100644 (file)
index 0000000..cba148c
--- /dev/null
@@ -0,0 +1,4 @@
+name = elidragon_grouplist
+author = Fleckenstein
+description = An API to easily store all items belonging to an itemgroup in a list
+depends = elidragon