-minetest.register_privilege("worldedit", "Can use WorldEdit commands")\r
+--- WorldEdit mod for the Minetest engine\r
+-- @module worldedit\r
+-- @release 1.3\r
+-- @copyright 2012 sfan5, Anthony Zhang (Uberi/Temperest), and Brett O'Donnell (cornernote)\r
+-- @license GNU Affero General Public License version 3 (AGPLv3)\r
+-- @author sfan5\r
+-- @author Anthony Zang (Uberi/Temperest)\r
+-- @author Bret O'Donnel (cornernote)\r
+-- @author ShadowNinja\r
\r
-worldedit = {}\r
\r
-worldedit.set_pos = {}\r
+worldedit = {}\r
\r
-worldedit.pos1 = {}\r
-worldedit.pos2 = {}\r
+local ver = {major=1, minor=3}\r
+worldedit.version = ver\r
+worldedit.version_string = string.format("%d.%d", ver.major, ver.minor)\r
\r
-dofile(minetest.get_modpath("worldedit") .. "/functions.lua")\r
-dofile(minetest.get_modpath("worldedit") .. "/mark.lua")\r
-dofile(minetest.get_modpath("worldedit") .. "/table_save.lua")\r
+local path = minetest.get_modpath(minetest.get_current_modname())\r
\r
---determines whether `nodename` is a valid node name, returning a boolean\r
-worldedit.node_is_valid = function(temp_pos, nodename)\r
- return minetest.registered_nodes[nodename] ~= nil\r
- or minetest.registered_nodes["default:" .. nodename] ~= nil\r
+local function load_module(path)\r
+ local file = io.open(path, "r")\r
+ if not file then return end\r
+ file:close()\r
+ return dofile(path)\r
end\r
\r
---determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)\r
-worldedit.player_axis = function(name)\r
- local dir = minetest.env:get_player_by_name(name):get_look_dir()\r
- local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)\r
- if x > y then\r
- if x > z then\r
- return "x", dir.x > 0 and 1 or -1\r
- end\r
- elseif y > z then\r
- return "y", dir.y > 0 and 1 or -1\r
- end\r
- return "z", dir.z > 0 and 1 or -1\r
-end\r
-\r
-minetest.register_chatcommand("/reset", {\r
- params = "",\r
- description = "Reset the region so that it is empty",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- worldedit.pos1[name] = nil\r
- worldedit.pos2[name] = nil\r
- worldedit.mark_pos1(name)\r
- worldedit.mark_pos2(name)\r
- minetest.chat_send_player(name, "WorldEdit region reset")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/mark", {\r
- params = "",\r
- description = "Show markers at the region positions",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- worldedit.mark_pos1(name)\r
- worldedit.mark_pos2(name)\r
- minetest.chat_send_player(name, "WorldEdit region marked")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/pos1", {\r
- params = "",\r
- description = "Set WorldEdit region position 1 to the player's location",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos = minetest.env:get_player_by_name(name):getpos()\r
- pos.x, pos.y, pos.z = math.floor(pos.x), math.floor(pos.y), math.floor(pos.z)\r
- worldedit.pos1[name] = pos\r
- worldedit.mark_pos1(name)\r
- minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/pos2", {\r
- params = "",\r
- description = "Set WorldEdit region position 2 to the player's location",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos = minetest.env:get_player_by_name(name):getpos()\r
- pos.x, pos.y, pos.z = math.floor(pos.x), math.floor(pos.y), math.floor(pos.z)\r
- worldedit.pos2[name] = pos\r
- worldedit.mark_pos2(name)\r
- minetest.chat_send_player(name, "WorldEdit position 2 set to " .. minetest.pos_to_string(pos))\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/p", {\r
- params = "set/get",\r
- description = "Set WorldEdit region by punching two nodes, or display the current WorldEdit region",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- if param == "set" then --set both WorldEdit positions\r
- worldedit.set_pos[name] = 1\r
- minetest.chat_send_player(name, "Select positions by punching two nodes")\r
- elseif param == "get" then --display current WorldEdit positions\r
- if worldedit.pos1[name] ~= nil then\r
- minetest.chat_send_player(name, "WorldEdit position 1: " .. minetest.pos_to_string(worldedit.pos1[name]))\r
- else\r
- minetest.chat_send_player(name, "WorldEdit position 1 not set")\r
- end\r
- if worldedit.pos2[name] ~= nil then\r
- minetest.chat_send_player(name, "WorldEdit position 2: " .. minetest.pos_to_string(worldedit.pos2[name]))\r
- else\r
- minetest.chat_send_player(name, "WorldEdit position 2 not set")\r
- end\r
- else\r
- minetest.chat_send_player(name, "Unknown subcommand: " .. param)\r
- end\r
- end,\r
-})\r
-\r
-minetest.register_on_punchnode(function(pos, node, puncher)\r
- local name = puncher:get_player_name()\r
- if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position\r
- if worldedit.set_pos[name] == 1 then --setting position 1\r
- worldedit.set_pos[name] = 2 --set position 2 on the next invocation\r
- worldedit.pos1[name] = pos\r
- worldedit.mark_pos1(name)\r
- minetest.chat_send_player(name, "WorldEdit region position 1 set to " .. minetest.pos_to_string(pos))\r
- else --setting position 2\r
- worldedit.set_pos[name] = nil --finished setting positions\r
- worldedit.pos2[name] = pos\r
- worldedit.mark_pos2(name)\r
- minetest.chat_send_player(name, "WorldEdit region position 2 set to " .. minetest.pos_to_string(pos))\r
- end\r
- end\r
-end)\r
-\r
-minetest.register_chatcommand("/volume", {\r
- params = "",\r
- description = "Display the volume of the current WorldEdit region",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local volume = worldedit.volume(pos1, pos2)\r
- minetest.chat_send_player(name, "Current WorldEdit region has a volume of " .. volume .. " nodes (" .. pos2.x - pos1.x .. "*" .. pos2.y - pos1.y .. "*" .. pos2.z - pos1.z .. ")")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/set", {\r
- params = "<node>",\r
- description = "Set the current WorldEdit region to <node>",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- if param == "" or not worldedit.node_is_valid(pos1, param) then\r
- minetest.chat_send_player(name, "Invalid node name: " .. param)\r
- return\r
- end\r
-\r
- local count = worldedit.set(pos1, pos2, param)\r
- minetest.chat_send_player(name, count .. " nodes set")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/replace", {\r
- params = "<search node> <replace node>",\r
- description = "Replace all instances of <search node> with <place node> in the current WorldEdit region",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if not worldedit.node_is_valid(pos1, searchnode) then\r
- minetest.chat_send_player(name, "Invalid search node name: " .. searchnode)\r
- return\r
- end\r
- if not worldedit.node_is_valid(pos1, replacenode) then\r
- minetest.chat_send_player(name, "Invalid replace node name: " .. replacenode)\r
- return\r
- end\r
-\r
- local count = worldedit.replace(pos1, pos2, searchnode, replacenode)\r
- minetest.chat_send_player(name, count .. " nodes replaced")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/hollowsphere", {\r
- params = "<radius> <node>",\r
- description = "Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos = worldedit.pos1[name]\r
- if pos == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if not worldedit.node_is_valid(pos, nodename) then\r
- minetest.chat_send_player(name, "Invalid node name: " .. param)\r
- return\r
- end\r
-\r
- local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename)\r
- minetest.chat_send_player(name, count .. " nodes added")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/sphere", {\r
- params = "<radius> <node>",\r
- description = "Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos = worldedit.pos1[name]\r
- if pos == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if not worldedit.node_is_valid(pos, nodename) then\r
- minetest.chat_send_player(name, "Invalid node name: " .. param)\r
- return\r
- end\r
-\r
- local count = worldedit.sphere(pos, tonumber(radius), nodename)\r
- minetest.chat_send_player(name, count .. " nodes added")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/hollowcylinder", {\r
- params = "x/y/z/? <length> <radius> <node>",\r
- description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos = worldedit.pos1[name]\r
- if pos == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if axis == "?" then\r
- axis, sign = worldedit.player_axis(name)\r
- length = length * sign\r
- end\r
- if not worldedit.node_is_valid(pos, nodename) then\r
- minetest.chat_send_player(name, "Invalid node name: " .. param)\r
- return\r
- end\r
-\r
- local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), nodename)\r
- minetest.chat_send_player(name, count .. " nodes added")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/cylinder", {\r
- params = "x/y/z/? <length> <radius> <node>",\r
- description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos = worldedit.pos1[name]\r
- if pos == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if axis == "?" then\r
- axis, sign = worldedit.player_axis(name)\r
- length = length * sign\r
- end\r
- if not worldedit.node_is_valid(pos, nodename) then\r
- minetest.chat_send_player(name, "Invalid node name: " .. param)\r
- return\r
- end\r
-\r
- local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), nodename)\r
- minetest.chat_send_player(name, count .. " nodes added")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/pyramid", {\r
- params = "<height> <node>",\r
- description = "Add pyramid at WorldEdit position 1 with height <height>, composed of <node>",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos = worldedit.pos1[name]\r
- if pos == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, size, nodename = param:find("(%d+)%s+([^%s]+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if not worldedit.node_is_valid(pos, nodename) then\r
- minetest.chat_send_player(name, "Invalid node name: " .. param)\r
- return\r
- end\r
-\r
- local count = worldedit.pyramid(pos, tonumber(size), nodename)\r
- minetest.chat_send_player(name, count .. " nodes added")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/spiral", {\r
- params = "<width> <height> <space> <node>",\r
- description = "Add spiral at WorldEdit position 1 with width <width>, height <height>, space between walls <space>, composed of <node>",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos = worldedit.pos1[name]\r
- if pos == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+([^%s]+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if not worldedit.node_is_valid(pos, nodename) then\r
- minetest.chat_send_player(name, "Invalid node name: " .. param)\r
- return\r
- end\r
+dofile(path .. "/common.lua")\r
+load_module(path .. "/manipulations.lua")\r
+load_module(path .. "/primitives.lua")\r
+load_module(path .. "/visualization.lua")\r
+load_module(path .. "/serialization.lua")\r
+load_module(path .. "/code.lua")\r
+load_module(path .. "/compatibility.lua")\r
+load_module(path .. "/cuboid.lua")\r
\r
- local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), nodename)\r
- minetest.chat_send_player(name, count .. " nodes changed")\r
- end,\r
-})\r
\r
-minetest.register_chatcommand("/copy", {\r
- params = "x/y/z/? <amount>",\r
- description = "Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if axis == "?" then\r
- axis, sign = worldedit.player_axis(name)\r
- amount = amount * sign\r
- end\r
-\r
- local count = worldedit.copy(pos1, pos2, axis, tonumber(amount))\r
- minetest.chat_send_player(name, count .. " nodes copied")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/move", {\r
- params = "x/y/z/? <amount>",\r
- description = "Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if axis == "?" then\r
- axis, sign = worldedit.player_axis(name)\r
- amount = amount * sign\r
- end\r
-\r
- local count = worldedit.move(pos1, pos2, axis, tonumber(amount))\r
-\r
- pos1[axis] = pos1[axis] + amount\r
- pos2[axis] = pos2[axis] + amount\r
- worldedit.mark_pos1(name)\r
- worldedit.mark_pos2(name)\r
-\r
- minetest.chat_send_player(name, count .. " nodes moved")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/stack", {\r
- params = "x/y/z/? <count>",\r
- description = "Stack the current WorldEdit region along the x/y/z/? axis <count> times",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, axis, count = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if axis == "?" then\r
- axis, sign = worldedit.player_axis(name)\r
- count = count * sign\r
- end\r
-\r
- local count = worldedit.stack(pos1, pos2, axis, tonumber(count))\r
- minetest.chat_send_player(name, count .. " nodes stacked")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/transpose", {\r
- params = "x/y/z/? x/y/z/?",\r
- description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if axis1 == "?" then\r
- axis1 = worldedit.player_axis(name)\r
- end\r
- if axis2 == "?" then\r
- axis2 = worldedit.player_axis(name)\r
- end\r
- if axis1 == axis2 then\r
- minetest.chat_send_player(name, "Invalid usage: axes are the same")\r
- return\r
- end\r
-\r
- local count = worldedit.transpose(pos1, pos2, axis1, axis2)\r
- minetest.chat_send_player(name, count .. " nodes transposed")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/flip", {\r
- params = "x/y/z/?",\r
- description = "Flip the current WorldEdit region along the x/y/z/? axis",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- if param == "?" then\r
- param = worldedit.player_axis(name)\r
- end\r
- if param ~= "x" and param ~= "y" and param ~= "z" then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
-\r
- local count = worldedit.flip(pos1, pos2, param)\r
- minetest.chat_send_player(name, count .. " nodes flipped")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/rotate", {\r
- params = "<axis> <angle>",\r
- description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
- if found == nil then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- if axis == "?" then\r
- axis = worldedit.player_axis(name)\r
- end\r
- if angle % 90 ~= 0 then\r
- minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90")\r
- return\r
- end\r
-\r
- local count = worldedit.rotate(pos1, pos2, axis, angle)\r
- minetest.chat_send_player(name, count .. " nodes rotated")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/dig", {\r
- params = "",\r
- description = "Dig the current WorldEdit region",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- local count = worldedit.dig(pos1, pos2)\r
- minetest.chat_send_player(name, count .. " nodes dug")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/save", {\r
- params = "<file>",\r
- description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- if param == "" then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
-\r
- local result, count = worldedit.serialize(pos1, pos2)\r
-\r
- local path = minetest.get_worldpath() .. "/schems"\r
- local filename = path .. "/" .. param .. ".we"\r
- os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist\r
- local file, err = io.open(filename, "wb")\r
- if err ~= nil then\r
- minetest.chat_send_player(name, "Could not save file to \"" .. filename .. "\"")\r
- return\r
- end\r
- file:write(result)\r
- file:flush()\r
- file:close()\r
-\r
- minetest.chat_send_player(name, count .. " nodes saved")\r
- end,\r
-})\r
-\r
-minetest.register_chatcommand("/load", {\r
- params = "<file>",\r
- description = "Load nodes from \"(world folder)/schems/<file>.we\" with position 1 of the current WorldEdit region as the origin",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1 = worldedit.pos1[name]\r
- if pos1 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
-\r
- if param == "" then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
-\r
- local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"\r
- local file, err = io.open(filename, "rb")\r
- if err ~= nil then\r
- minetest.chat_send_player(name, "Could not open file \"" .. filename .. "\"")\r
- return\r
- end\r
- local value = file:read("*a")\r
- file:close()\r
-\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
-})\r
-\r
-minetest.register_chatcommand("/metasave", {\r
- params = "<file>",\r
- description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.wem\"",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
- if param == "" then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- local count, err = worldedit.metasave(pos1, pos2, param)\r
- if err then\r
- minetest.chat_send_player(name, "error loading file: " .. err)\r
- else\r
- minetest.chat_send_player(name, count .. " nodes saved")\r
- end\r
- end,\r
-})\r
+if minetest.settings:get_bool("log_mods") then\r
+ print("[WorldEdit] Loaded!")\r
+end\r
\r
-minetest.register_chatcommand("/metaload", {\r
- params = "<file>",\r
- description = "Load nodes from \"(world folder)/schems/<file>.wem\" with position 1 of the current WorldEdit region as the origin",\r
- privs = {worldedit=true},\r
- func = function(name, param)\r
- local pos1 = worldedit.pos1[name]\r
- if pos1 == nil then\r
- minetest.chat_send_player(name, "No WorldEdit region selected")\r
- return\r
- end\r
- if param == "" then\r
- minetest.chat_send_player(name, "Invalid usage: " .. param)\r
- return\r
- end\r
- local count, err = worldedit.metaload(pos1, param)\r
- if err then\r
- minetest.chat_send_player(name, "error loading file: " .. err)\r
- else\r
- minetest.chat_send_player(name, count .. " nodes loaded")\r
- end\r
- end,\r
-})\r