local function registered_nodes_by_group(group)
local result = {}
for name, def in pairs(minetest.registered_nodes) do
if def.groups[group] then
result[#result+1] = name
end
end
return result
end
-- get nodes in group and store in result table
function hardtrees.get_nodes(group)
local result = {} -- define blank table
local i = 1 -- for variable
for name, def in pairs(minetest.registered_nodes) do
if def.groups[group] then
result[i] = name
i = i + 1
end
end
return result -- return result table
end
-- override tree nodes
local tree = hardtrees.get_nodes("tree")
-- for loop to override tree nodes
for i, tree in pairs(tree) do
hardtrees.override.tree(tree[i])
end
-- override leaves nodes
local leaf = hardtrees.get_nodes("leaves") -- get leaves
local sapling = hardtrees.get_nodes("sapling") -- get sapling
-- for loop to override nodes
for i,leaf,sapling in pairs(leaf,sapling) do
hardtrees.override.leaf(leaf[i], sapling[i])
end
local function registered_nodes_by_group(group)
local result = {}
for name, def in pairs(minetest.registered_nodes) do
if def.groups[group] then
result[#result+1] = name
end
end
return result
end
local grouped_trees = registered_nodes_by_group("tree")
for i = 1, #grouped_trees do
minetest.override_item(grouped_trees[i], {
-- override stuff here
})
end
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"})
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"}
}
Users browsing this forum: Google [Bot] and 1 guest