Returns the number of nodes deserialized.
+### worldedit.deserialize_old(originpos, value)
+
+Loads the nodes represented by string `value` at position `originpos`, using the older table-based WorldEdit format.
+
+This function is deprecated, and should not be used unless there is a need to support legacy WorldEdit save files.
+
+Returns the number of nodes deserialized.
+
License
-------
Copyright 2012 sfan5 and Anthony Zhang (Temperest)
count = count + 1\r
end\r
return count\r
+end\r
+\r
+--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized\r
+--based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)\r
+worldedit.deserialize_old = function(originpos, value)\r
+ --obtain the node table\r
+ local count = 0\r
+ local get_tables = loadstring(value)\r
+ if get_tables == nil then --error loading value\r
+ return count\r
+ end\r
+ local tables = get_tables()\r
+\r
+ --transform the node table into an array of nodes\r
+ for i = 1, #tables do\r
+ for j, v in pairs(tables[i]) do\r
+ if type(v) == "table" then\r
+ tables[i][j] = tables[v[1]]\r
+ end\r
+ end\r
+ end\r
+\r
+ --load the node array\r
+ local env = minetest.env\r
+ for i, v in ipairs(tables[1]) do\r
+ local pos = v[1]\r
+ pos.x, pos.y, pos.z = originpos.x + pos.x, originpos.y + pos.y, originpos.z + pos.z\r
+ env:add_node(pos, v[2])\r
+ count = count + 1\r
+ end\r
+ return count\r
end
\ No newline at end of file
minetest.register_privilege("worldedit", "Can use WorldEdit commands")\r
\r
---wip: check to make sure player positions are set before doing editing\r
---wip; fix meseconedit to export to new WorldEdit format\r
-\r
worldedit = {}\r
\r
worldedit.set_pos = {}\r
local value = file:read("*a")\r
file:close()\r
\r
- local count = worldedit.deserialize(pos1, value)\r
+ local count\r
+ if value:find("{") then --old WorldEdit format\r
+ count = worldedit.deserialize_old(pos1, value)\r
+ else --new WorldEdit format\r
+ count = worldedit.deserialize(pos1, value)\r
+ end\r
\r
minetest.chat_send_player(name, count .. " nodes loaded")\r
end,\r