localize_nodeids.lua 923 B

123456789101112131415161718192021222324252627282930313233
  1. local import_mod = ...
  2. local air_content_id = minetest.get_content_id("air")
  3. -- local nodename->id cache
  4. local local_nodename_to_id_mapping = {} -- name -> id
  5. function import_mod.localize_nodeids(node_mapping, node_ids)
  6. local foreign_nodeid_to_name_mapping = {} -- id -> name
  7. for k, v in pairs(node_mapping) do
  8. foreign_nodeid_to_name_mapping[v] = k
  9. end
  10. for i, node_id in ipairs(node_ids) do
  11. local node_name = foreign_nodeid_to_name_mapping[node_id]
  12. local local_node_id = local_nodename_to_id_mapping[node_name]
  13. if not local_node_id then
  14. if minetest.registered_nodes[node_name] then
  15. -- node is locally available
  16. local_node_id = minetest.get_content_id(node_name)
  17. else
  18. -- node is not available here
  19. -- TODO: make replacements configurable
  20. local_node_id = air_content_id
  21. end
  22. local_nodename_to_id_mapping[node_name] = local_node_id
  23. end
  24. node_ids[i] = local_node_id
  25. end
  26. end