Linuxdirk wrote:
Code: Select all
local wanted_nodes = {}
for name,def in pairs(minetest.registered_nodes) do
-- Maybe filter what nodes you do not want.
-- For example get only nodes that are solid (drawtype = normal)
if def.drawtype == 'normal' then
wanted_nodes[name] = def
end
end
for name,def in pairs(wanted_nodes) do
-- Now you can do whatever you want with your wanted nodes.
-- You have the name and you have the ID ... go figure yourself :)
done
This is a good solution to avoid the table maintenance problem, and indeed safe for the table.
There's always pros and cons to this. Because load order is random, if you register new nodes based on this list you will likely end up with unknown nodes on your map once in a while, so I still do not recommend it:
- mod foo creates new nodes for all "normal" nodes found in the registration list. They are named ":mod:node_foo"
- mod foo depends on mod bar, but not mod baz
- game loads, mod foo sees "bar:node" and "baz:node" and registers ":bar:node_foo" and ":baz:node_foo"
- player places ":baz:node_foo" on the map
- game shuts down
- game loads, but now mod "foo" is initialized *before* mod "baz"
- mod foo sees "bar:node" and registers ":bar:node_foo"
- unknown node ":baz:node_foo" now exists on the map.
The only way around that is to explicitly always (optionally) depend on the other mods and/or hard code the actual list of nodes that you want to handle, and check if they are registered. That method avoids the "unknown node" problem on your map. Yes, it's annoying to have to hard code the list of nodes, I realize that as well.