or minetest.registered_nodes["default:" .. nodename] ~= nil\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
})\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
+ 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
return\r
end\r
\r
- local found, _, axis, length, radius, nodename = param:find("^([xyz])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")\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
\r
+minetest.register_chatcommand("/spiral", {\r
+ params = "<size> <node>",\r
+ description = "Add spiral at WorldEdit position 1 with size <size>, 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.spiral(pos, tonumber(size), nodename)\r
+ minetest.chat_send_player(name, count .. " nodes changed")\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
+ 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
return\r
end\r
\r
- local found, _, axis, length, radius, nodename = param:find("^([xyz])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")\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
})\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
+ 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
return\r
end\r
\r
- local found, _, axis, amount = param:find("^([xyz])%s+([+-]?%d+)$")\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
})\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
+ 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
return\r
end\r
\r
- local found, _, axis, amount = param:find("^([xyz])%s+([+-]?%d+)$")\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
minetest.chat_send_player(name, count .. " nodes moved")\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
+ 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
return\r
end\r
\r
- local found, _, axis, count = param:find("^([xyz])%s+([+-]?%d+)$")\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
})\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
+ 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
return\r
end\r
\r
- local found, _, axis1, axis2 = param:find("^([xyz])%s+([xyz])$")\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
})\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
+ 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
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
\r
minetest.chat_send_player(name, count .. " nodes loaded")\r
end,\r
-})
\ No newline at end of file
+})\r