I fiddled around with the function. You can send this one all three groups (or more, or less) at once and it will return a grouped table. This way you only have to loop through the registered nodes once instead of three times.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local function registered_nodes_by_group(groups, allow_duplicates)
if type(groups) ~= "table" then
return nil
end
allow_duplicates = allow_duplicates or false
local g_cnt = #groups
local result = {}
for i = 1, g_cnt do
result[groups[i]] = {}
end
for name, def in pairs(minetest.registered_nodes) do
for i = 1, g_cnt do
local grp = groups[i]
if def.groups[grp] then
result[grp][#result[grp]+1] = name
if allow_duplicates == false then
break
end
end
end
end
return result
end
local grouped_nodes = registered_nodes_by_group({"tree", "leaves", "sapling"})
The following is what is returned from vanilla Minetest_Game:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
return {
["leaves"] = {"default:leaves", "default:pine_needles", "default:acacia_leaves", "default:jungleleaves", "default:aspen_leaves"},
["sapling"] = {"default:sapling", "default:junglesapling", "default:pine_sapling", "default:aspen_sapling", "default:acacia_sapling"},
["tree"] = {"default:pine_tree", "default:acacia_tree", "default:tree", "default:aspen_tree", "default:jungletree"}
}
Note: If 'allow_duplicates' = true then nodes that match two or more groups will be added to all matching sub-tables. If false, or not sent, then nodes will be added to the sub-table of the first group it matches.