\r
worldedit.keep_loaded(pos1, pos2)\r
\r
+ local get_node, get_meta, hash_node_position =\r
+ minetest.get_node, minetest.get_meta, minetest.hash_node_position\r
+\r
+ -- Find the positions which have metadata\r
+ local has_meta = {}\r
+ local meta_positions = minetest.find_nodes_with_meta(pos1, pos2)\r
+ for i = 1, #meta_positions do\r
+ has_meta[hash_node_position(meta_positions[i])] = true\r
+ end\r
+\r
local pos = {x=pos1.x, y=0, z=0}\r
local count = 0\r
local result = {}\r
- local get_node, get_meta = minetest.get_node, minetest.get_meta\r
while pos.x <= pos2.x do\r
pos.y = pos1.y\r
while pos.y <= pos2.y do\r
local node = get_node(pos)\r
if node.name ~= "air" and node.name ~= "ignore" then\r
count = count + 1\r
- local meta = get_meta(pos):to_table()\r
-\r
- local meta_empty = true\r
- -- Convert metadata item stacks to item strings\r
- for name, inventory in pairs(meta.inventory) do\r
- for index, stack in ipairs(inventory) do\r
- meta_empty = false\r
- inventory[index] = stack.to_string and stack:to_string() or stack\r
- end\r
- end\r
- for k in pairs(meta) do\r
- if k ~= "inventory" then\r
- meta_empty = false\r
- break\r
+\r
+ local meta\r
+ if has_meta[hash_node_position(pos)] then\r
+ meta = get_meta(pos):to_table()\r
+\r
+ -- Convert metadata item stacks to item strings\r
+ for _, invlist in pairs(meta.inventory) do\r
+ for index = 1, #invlist do\r
+ local itemstack = invlist[index]\r
+ if itemstack.to_string then\r
+ invlist[index] = itemstack:to_string()\r
+ end\r
+ end\r
end\r
end\r
\r
name = node.name,\r
param1 = node.param1 ~= 0 and node.param1 or nil,\r
param2 = node.param2 ~= 0 and node.param2 or nil,\r
- meta = not meta_empty and meta or nil,\r
+ meta = meta,\r
}\r
end\r
pos.z = pos.z + 1\r