@@ -56,10 +56,19 @@ function worldedit.serialize(pos1, pos2)
56
56
57
57
worldedit .keep_loaded (pos1 , pos2 )
58
58
59
+ local get_node , get_meta , hash_node_position =
60
+ minetest .get_node , minetest .get_meta , minetest .hash_node_position
61
+
62
+ -- Find the positions which have metadata
63
+ local has_meta = {}
64
+ local meta_positions = minetest .find_nodes_with_meta (pos1 , pos2 )
65
+ for i = 1 , # meta_positions do
66
+ has_meta [hash_node_position (meta_positions [i ])] = true
67
+ end
68
+
59
69
local pos = {x = pos1 .x , y = 0 , z = 0 }
60
70
local count = 0
61
71
local result = {}
62
- local get_node , get_meta = minetest .get_node , minetest .get_meta
63
72
while pos .x <= pos2 .x do
64
73
pos .y = pos1 .y
65
74
while pos .y <= pos2 .y do
@@ -68,20 +77,19 @@ function worldedit.serialize(pos1, pos2)
68
77
local node = get_node (pos )
69
78
if node .name ~= " air" and node .name ~= " ignore" then
70
79
count = count + 1
71
- local meta = get_meta (pos ):to_table ()
72
-
73
- local meta_empty = true
74
- -- Convert metadata item stacks to item strings
75
- for name , inventory in pairs (meta .inventory ) do
76
- for index , stack in ipairs (inventory ) do
77
- meta_empty = false
78
- inventory [index ] = stack .to_string and stack :to_string () or stack
79
- end
80
- end
81
- for k in pairs (meta ) do
82
- if k ~= " inventory" then
83
- meta_empty = false
84
- break
80
+
81
+ local meta
82
+ if has_meta [hash_node_position (pos )] then
83
+ meta = get_meta (pos ):to_table ()
84
+
85
+ -- Convert metadata item stacks to item strings
86
+ for _ , invlist in pairs (meta .inventory ) do
87
+ for index = 1 , # invlist do
88
+ local itemstack = invlist [index ]
89
+ if itemstack .to_string then
90
+ invlist [index ] = itemstack :to_string ()
91
+ end
92
+ end
85
93
end
86
94
end
87
95
@@ -92,7 +100,7 @@ function worldedit.serialize(pos1, pos2)
92
100
name = node .name ,
93
101
param1 = node .param1 ~= 0 and node .param1 or nil ,
94
102
param2 = node .param2 ~= 0 and node .param2 or nil ,
95
- meta = not meta_empty and meta or nil ,
103
+ meta = meta ,
96
104
}
97
105
end
98
106
pos .z = pos .z + 1
0 commit comments