summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Sosa <sosa.daniel23@gmail.com>2015-01-03 20:56:27 -0600
committerDaniel Sosa <sosa.daniel23@gmail.com>2016-07-03 21:44:02 -0500
commit859c6bd12a45a8c9c5ad25675b2916f39937e261 (patch)
treed7057f5c969d5c5e8240ae78dbd95d8e46c1485f
parent240380ff16bfb8dedb18b991315f0bacd937caf5 (diff)
Implement /expand and /contract
-rw-r--r--worldedit_commands/cuboid.lua90
1 files changed, 76 insertions, 14 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 = "<amount> [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 = "<amount> [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
+ 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
+ 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 = "<amount> [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,
}
)