From 859c6bd12a45a8c9c5ad25675b2916f39937e261 Mon Sep 17 00:00:00 2001 From: Daniel Sosa Date: Sat, 3 Jan 2015 20:56:27 -0600 Subject: [PATCH] Implement /expand and /contract --- worldedit_commands/cuboid.lua | 100 +++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 19 deletions(-) diff --git a/worldedit_commands/cuboid.lua b/worldedit_commands/cuboid.lua index 2e59f16..9d6d86a 100644 --- a/worldedit_commands/cuboid.lua +++ b/worldedit_commands/cuboid.lua @@ -113,27 +113,89 @@ minetest.register_chatcommand("/shift", { } ) -minetest.register_chatcommand( - "/expand", - { - params = " [reverse-amount] [up|down|left|right|front|back]", - description = "expand the selection in one or two directions at once", - privs = {worldedit=true}, - func = function(name, param) +minetest.register_chatcommand("/expand", { + params = " [reverse-amount] [up|down|left|right|front|back]", + description = "expand the selection in one or two directions at once", + privs = {worldedit=true}, + func = function(name, param) local find, _, amount, arg2, arg3 = param:find("(%d+)%s*(%w*)%s*(%l*)") - - if find == nil then - worldedit.player_notify(name, "invalid use: " .. param) - return - end - - if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then - worldedit.player_notify(name, - "Undefined region. Region must be defined beforehand.") - return - end - + if find == nil then + worldedit.player_notify(name, "invalid use: " .. param) + return + end + + if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then + worldedit.player_notify(name, + "Undefined region. Region must be defined beforehand.") + return + end + + local tmp = tonumber(arg2) + local axis, dir + local reverseamount = 0 + + axis,dir = worldedit.player_axis(name) + + if arg2 ~= "" then + if tmp == nil then + axis, dir = worldedit.translate_direction(name, arg2) + else + reverseamount = tmp + end + end + + if arg3 ~= "" then + axis, dir = worldedit.translate_direction(name, arg3) + end + + worldedit.cuboid_linealexpand(name, axis, dir, amount) + worldedit.cuboid_linealexpand(name, axis, -dir, reverseamount) + worldedit.marker_update(name) + end, + } +) + + +minetest.register_chatcommand("/contract", { + params = " [reverse-amount] [up|down|left|right|front|back]", + description = "contract the selection in one or two directions at once", + privs = {worldedit=true}, + func = function(name, param) + local find, _, amount, arg2, arg3 = param:find("(%d+)%s*(%w*)%s*(%l*)") + + if find == nil then + worldedit.player_notify(name, "invalid use: " .. param) + return + end + + if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then + worldedit.player_notify(name, + "Undefined region. Region must be defined beforehand.") + return + end + + local tmp = tonumber(arg2) + local axis, dir + local reverseamount = 0 + + axis,dir = worldedit.player_axis(name) + + if arg2 ~= "" then + if tmp == nil then + axis, dir = worldedit.translate_direction(name, arg2) + else + reverseamount = tmp + end + end + + if arg3 ~= "" then + axis, dir = worldedit.translate_direction(name, arg3) + end + + worldedit.cuboid_linealexpand(name, axis, dir, -amount) + worldedit.cuboid_linealexpand(name, axis, -dir, -reverseamount) + worldedit.marker_update(name) end, } )