---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