From 8cd32bcc59766f6c2aba77da7f64ea9882e97813 Mon Sep 17 00:00:00 2001 From: Anthony Zhang Date: Sun, 22 Jul 2012 18:12:29 -0400 Subject: Add the //transpose, //flip, and //rotate commands as well as their documentation and related WorldEdit API functions. Fix chat parameter handling using pattern anchors. --- init.lua | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 4 deletions(-) (limited to 'init.lua') 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 = "", + description = "Rotate the current WorldEdit region around the y axis by 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", -- cgit v1.2.3