-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocalize_nodeids.lua
More file actions
30 lines (25 loc) · 896 Bytes
/
localize_nodeids.lua
File metadata and controls
30 lines (25 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
local air_content_id = minetest.get_content_id("air")
-- local nodename->id cache
local local_nodename_to_id_mapping = {} -- name -> id
function mapsync.localize_nodeids(node_mapping, node_ids)
local foreign_nodeid_to_name_mapping = {} -- id -> name
for k, v in pairs(node_mapping) do
foreign_nodeid_to_name_mapping[v] = k
end
for i, node_id in ipairs(node_ids) do
local node_name = foreign_nodeid_to_name_mapping[node_id]
local local_node_id = local_nodename_to_id_mapping[node_name]
if not local_node_id then
if minetest.registered_nodes[node_name] then
-- node is locally available
local_node_id = minetest.get_content_id(node_name)
else
-- node is not available here
-- TODO: make replacements configurable
local_node_id = air_content_id
end
local_nodename_to_id_mapping[node_name] = local_node_id
end
node_ids[i] = local_node_id
end
end