1 minetest.register_chatcommand("/outset", {
2 params = "<amount> [h|v]",
3 description = "outset the selection",
4 privs = {worldedit=true},
5 func = function(name, param)
6 local find, _, amount, dir = param:find("^(%d+)[%s+]?([hv]?)$")
9 return false, "invalid usage: " .. param
12 local pos1 = worldedit.pos1[name]
13 local pos2 = worldedit.pos2[name]
15 if pos1 == nil or pos2 == nil then
17 "Undefined region. Region must be defined beforehand."
21 assert(worldedit.cuboid_volumetricexpand(name, amount))
22 elseif dir == "h" then
23 assert(worldedit.cuboid_linealexpand(name, 'x', 1, amount))
24 assert(worldedit.cuboid_linealexpand(name, 'x', -1, amount))
25 assert(worldedit.cuboid_linealexpand(name, 'z', 1, amount))
26 assert(worldedit.cuboid_linealexpand(name, 'z', -1, amount))
27 elseif dir == "v" then
28 assert(worldedit.cuboid_linealexpand(name, 'y', 1, amount))
29 assert(worldedit.cuboid_linealexpand(name, 'y', -1, amount))
31 return false, "Unknown error"
34 worldedit.marker_update(name)
35 return true, "Region outset by " .. amount .. " blocks"
40 minetest.register_chatcommand("/inset", {
41 params = "<amount> [h|v]",
42 description = "inset the selection",
43 privs = {worldedit=true},
44 func = function(name, param)
45 local find, _, amount, dir = param:find("^(%d+)[%s+]?([hv]?)$")
48 return false, "invalid usage: " .. param
51 local pos1 = worldedit.pos1[name]
52 local pos2 = worldedit.pos2[name]
54 if pos1 == nil or pos2 == nil then
56 "Undefined region. Region must be defined beforehand."
60 assert(worldedit.cuboid_volumetricexpand(name, -amount))
61 elseif dir == "h" then
62 assert(worldedit.cuboid_linealexpand(name, 'x', 1, -amount))
63 assert(worldedit.cuboid_linealexpand(name, 'x', -1, -amount))
64 assert(worldedit.cuboid_linealexpand(name, 'z', 1, -amount))
65 assert(worldedit.cuboid_linealexpand(name, 'z', -1, -amount))
66 elseif dir == "v" then
67 assert(worldedit.cuboid_linealexpand(name, 'y', 1, -amount))
68 assert(worldedit.cuboid_linealexpand(name, 'y', -1, -amount))
70 return false, "Unknown error"
73 worldedit.marker_update(name)
74 return true, "Region inset by " .. amount .. " blocks"
80 minetest.register_chatcommand("/shift", {
81 params = "<amount> [up|down|left|right|front|back]",
82 description = "Moves the selection region. Does not move contents.",
83 privs = {worldedit=true},
84 func = function(name, param)
85 local pos1 = worldedit.pos1[name]
86 local pos2 = worldedit.pos2[name]
87 local find, _, amount, direction = param:find("(%d+)%s*(%l*)")
90 worldedit.player_notify(name, "invalid usage: " .. param)
94 if pos1 == nil or pos2 == nil then
95 worldedit.player_notify(name,
96 "Undefined region. Region must be defined beforehand.")
101 if direction ~= "" then
102 axis, dir = worldedit.translate_direction(name, direction)
104 axis, dir = worldedit.player_axis(name)
105 worldedit.player_notify(name, "entered player_axis")
108 assert(worldedit.cuboid_shift(name, axis, amount * dir))
109 worldedit.marker_update(name)
111 return true, "region shifted by " .. amount .. " blocks"
116 minetest.register_chatcommand("/expand", {
117 params = "<amount> [reverse-amount] [up|down|left|right|front|back]",
118 description = "expand the selection in one or two directions at once",
119 privs = {worldedit=true},
120 func = function(name, param)
121 local find, _, amount, arg2, arg3 = param:find("(%d+)%s*(%w*)%s*(%l*)")
124 worldedit.player_notify(name, "invalid use: " .. param)
128 if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then
129 worldedit.player_notify(name,
130 "Undefined region. Region must be defined beforehand.")
134 local tmp = tonumber(arg2)
136 local reverseamount = 0
138 axis,dir = worldedit.player_axis(name)
142 axis, dir = worldedit.translate_direction(name, arg2)
149 axis, dir = worldedit.translate_direction(name, arg3)
152 worldedit.cuboid_linealexpand(name, axis, dir, amount)
153 worldedit.cuboid_linealexpand(name, axis, -dir, reverseamount)
154 worldedit.marker_update(name)
160 minetest.register_chatcommand("/contract", {
161 params = "<amount> [reverse-amount] [up|down|left|right|front|back]",
162 description = "contract the selection in one or two directions at once",
163 privs = {worldedit=true},
164 func = function(name, param)
165 local find, _, amount, arg2, arg3 = param:find("(%d+)%s*(%w*)%s*(%l*)")
168 worldedit.player_notify(name, "invalid use: " .. param)
172 if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then
173 worldedit.player_notify(name,
174 "Undefined region. Region must be defined beforehand.")
178 local tmp = tonumber(arg2)
180 local reverseamount = 0
182 axis,dir = worldedit.player_axis(name)
186 axis, dir = worldedit.translate_direction(name, arg2)
193 axis, dir = worldedit.translate_direction(name, arg3)
196 worldedit.cuboid_linealexpand(name, axis, dir, -amount)
197 worldedit.cuboid_linealexpand(name, axis, -dir, -reverseamount)
198 worldedit.marker_update(name)
204 dofile(minetest.get_modpath("worldedit_commands") .. "/cuboidapi.lua")