summaryrefslogtreecommitdiff
path: root/worldedit/serialization.lua
diff options
context:
space:
mode:
authorVanessa Dannenberg <vanessa.e.dannenberg@gmail.com>2019-04-24 18:59:36 -0400
committerVanessa Dannenberg <vanessa.e.dannenberg@gmail.com>2019-04-24 18:59:36 -0400
commita5eef1c5de77fa7770877802e66c3e1c53f9a0da (patch)
tree0f36e64a58e5f5bb7d95be6ae692f58f2ebfe483 /worldedit/serialization.lua
parentdda854cf06f90a04a03844e19c4d4ad220e38fe4 (diff)
downloaddreambuilder_modpack-a5eef1c5de77fa7770877802e66c3e1c53f9a0da.tar
dreambuilder_modpack-a5eef1c5de77fa7770877802e66c3e1c53f9a0da.tar.gz
dreambuilder_modpack-a5eef1c5de77fa7770877802e66c3e1c53f9a0da.tar.bz2
dreambuilder_modpack-a5eef1c5de77fa7770877802e66c3e1c53f9a0da.tar.xz
dreambuilder_modpack-a5eef1c5de77fa7770877802e66c3e1c53f9a0da.zip
update castles, areas, homedecor, plantlife,
gloopblocks, hotbar, inspector, maptools, mesecons, moreblocks, moreores, technic, teleport_request, and worldedit switched to caverealms_lite (with minor fixes by me) switched to CWz's fork of player_textures The homedecor update brings in the big split, and will require you to re-enable all modpack components in order to avoid loss of content.
Diffstat (limited to 'worldedit/serialization.lua')
-rw-r--r--worldedit/serialization.lua40
1 files changed, 24 insertions, 16 deletions
diff --git a/worldedit/serialization.lua b/worldedit/serialization.lua
index a0848e2..4aef556 100644
--- a/worldedit/serialization.lua
+++ b/worldedit/serialization.lua
@@ -56,10 +56,19 @@ function worldedit.serialize(pos1, pos2)
worldedit.keep_loaded(pos1, pos2)
+ local get_node, get_meta, hash_node_position =
+ minetest.get_node, minetest.get_meta, minetest.hash_node_position
+
+ -- Find the positions which have metadata
+ local has_meta = {}
+ local meta_positions = minetest.find_nodes_with_meta(pos1, pos2)
+ for i = 1, #meta_positions do
+ has_meta[hash_node_position(meta_positions[i])] = true
+ end
+
local pos = {x=pos1.x, y=0, z=0}
local count = 0
local result = {}
- local get_node, get_meta = minetest.get_node, minetest.get_meta
while pos.x <= pos2.x do
pos.y = pos1.y
while pos.y <= pos2.y do
@@ -68,20 +77,19 @@ function worldedit.serialize(pos1, pos2)
local node = get_node(pos)
if node.name ~= "air" and node.name ~= "ignore" then
count = count + 1
- local meta = get_meta(pos):to_table()
-
- local meta_empty = true
- -- Convert metadata item stacks to item strings
- for name, inventory in pairs(meta.inventory) do
- for index, stack in ipairs(inventory) do
- meta_empty = false
- inventory[index] = stack.to_string and stack:to_string() or stack
- end
- end
- for k in pairs(meta) do
- if k ~= "inventory" then
- meta_empty = false
- break
+
+ local meta
+ if has_meta[hash_node_position(pos)] then
+ meta = get_meta(pos):to_table()
+
+ -- Convert metadata item stacks to item strings
+ for _, invlist in pairs(meta.inventory) do
+ for index = 1, #invlist do
+ local itemstack = invlist[index]
+ if itemstack.to_string then
+ invlist[index] = itemstack:to_string()
+ end
+ end
end
end
@@ -92,7 +100,7 @@ function worldedit.serialize(pos1, pos2)
name = node.name,
param1 = node.param1 ~= 0 and node.param1 or nil,
param2 = node.param2 ~= 0 and node.param2 or nil,
- meta = not meta_empty and meta or nil,
+ meta = meta,
}
end
pos.z = pos.z + 1