summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorAnthony Zhang <azhang9@gmail.com>2012-07-22 18:12:29 -0400
committerAnthony Zhang <azhang9@gmail.com>2012-07-22 18:12:29 -0400
commit8cd32bcc59766f6c2aba77da7f64ea9882e97813 (patch)
tree2c6384069c372458e90188cf4fd84a45adb963db /init.lua
parenta4a361317075c7cdf1d9f92131ad4d9d03221c41 (diff)
Add the //transpose, //flip, and //rotate commands as well as their documentation and related WorldEdit API functions. Fix chat parameter handling using pattern anchors.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua81
1 files changed, 77 insertions, 4 deletions
diff --git a/init.lua b/init.lua
index d5c4eb5..5c37567 100644
--- a/init.lua
+++ b/init.lua
@@ -162,7 +162,7 @@ minetest.register_chatcommand("/replace", {
return
end
- local found, _, searchnode, replacenode = param:find("([^%s]+)%s+([^%s]+)")
+ local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")
if found == nil then
minetest.chat_send_player(name, "Invalid usage: " .. param)
return
@@ -192,7 +192,7 @@ minetest.register_chatcommand("/copy", {
return
end
- local found, _, axis, amount = param:find("([xyz])%s+([+-]?%d+)")
+ local found, _, axis, amount = param:find("^([xyz])%s+([+-]?%d+)$")
if found == nil then
minetest.chat_send_player(name, "Invalid usage: " .. param)
return
@@ -214,7 +214,7 @@ minetest.register_chatcommand("/move", {
return
end
- local found, _, axis, amount = param:find("([xyz])%s+([+-]?%d+)")
+ local found, _, axis, amount = param:find("^([xyz])%s+([+-]?%d+)$")
if found == nil then
minetest.chat_send_player(name, "Invalid usage: " .. param)
return
@@ -236,7 +236,7 @@ minetest.register_chatcommand("/stack", {
return
end
- local found, _, axis, count = param:find("([xyz])%s+([+-]?%d+)")
+ local found, _, axis, count = param:find("^([xyz])%s+([+-]?%d+)$")
if found == nil then
minetest.chat_send_player(name, "Invalid usage: " .. param)
return
@@ -247,6 +247,79 @@ minetest.register_chatcommand("/stack", {
end,
})
+minetest.register_chatcommand("/transpose", {
+ params = "x/y/z x/y/z",
+ description = "Transpose the current WorldEdit region along the x/y/z and x/y/z axes",
+ privs = {worldedit=true},
+ func = function(name, param)
+ local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
+ if pos1 == nil or pos2 == nil then
+ minetest.chat_send_player(name, "No WorldEdit region selected")
+ return
+ end
+
+ local found, _, axis1, axis2 = param:find("^([xyz])%s+([xyz])$")
+ if found == nil then
+ minetest.chat_send_player(name, "Invalid usage: " .. param)
+ return
+ end
+ if axis1 == axis2 then
+ minetest.chat_send_player(name, "Invalid usage: axes are the same")
+ return
+ end
+
+ local count = worldedit.transpose(pos1, pos2, axis1, axis2)
+ minetest.chat_send_player(name, count .. " nodes transposed")
+ end,
+})
+
+minetest.register_chatcommand("/flip", {
+ params = "x/y/z",
+ description = "Flip the current WorldEdit region along the x/y/z axis",
+ privs = {worldedit=true},
+ func = function(name, param)
+ local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
+ if pos1 == nil or pos2 == nil then
+ minetest.chat_send_player(name, "No WorldEdit region selected")
+ return
+ end
+
+ if param ~= "x" and param ~= "y" and param ~= "z" then
+ minetest.chat_send_player(name, "Invalid usage: " .. param)
+ return
+ end
+
+ local count = worldedit.flip(pos1, pos2, param)
+ minetest.chat_send_player(name, count .. " nodes flipped")
+ end,
+})
+
+minetest.register_chatcommand("/rotate", {
+ params = "<angle>",
+ description = "Rotate the current WorldEdit region around the y axis by angle <angle> (90 degree increment)",
+ privs = {worldedit=true},
+ func = function(name, param)
+ local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
+ if pos1 == nil or pos2 == nil then
+ minetest.chat_send_player(name, "No WorldEdit region selected")
+ return
+ end
+
+ angle = tonumber(param)
+ if angle == nil then
+ minetest.chat_send_player(name, "Invalid usage: " .. param)
+ return
+ end
+ if angle % 90 ~= 0 then
+ minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90")
+ return
+ end
+
+ local count = worldedit.rotate(pos1, pos2, angle)
+ minetest.chat_send_player(name, count .. " nodes rotated")
+ end,
+})
+
minetest.register_chatcommand("/dig", {
params = "",
description = "Dig the current WorldEdit region",