1 worldedit.register_command("outset", {
2 params = "[h|v] <amount>",
3 description = "Outset the selected region.",
4 privs = {worldedit=true},
6 parse = function(param)
7 local find, _, dir, amount = param:find("(%a*)%s*([+-]?%d+)")
12 local hv_test = dir:find("[^hv]+")
13 if hv_test ~= nil then
14 return false, "Invalid direction."
17 return true, dir, tonumber(amount)
19 func = function(name, dir, amount)
20 if dir == "" or dir == "hv" or dir == "vh" then
21 assert(worldedit.cuboid_volumetric_expand(name, amount))
22 elseif dir == "h" then
23 assert(worldedit.cuboid_linear_expand(name, 'x', 1, amount))
24 assert(worldedit.cuboid_linear_expand(name, 'x', -1, amount))
25 assert(worldedit.cuboid_linear_expand(name, 'z', 1, amount))
26 assert(worldedit.cuboid_linear_expand(name, 'z', -1, amount))
27 elseif dir == "v" then
28 assert(worldedit.cuboid_linear_expand(name, 'y', 1, amount))
29 assert(worldedit.cuboid_linear_expand(name, 'y', -1, amount))
31 return false, "Invalid number of arguments"
34 worldedit.marker_update(name)
35 return true, "Region outset by " .. amount .. " blocks"
40 worldedit.register_command("inset", {
41 params = "[h|v] <amount>",
42 description = "Inset the selected region.",
43 privs = {worldedit=true},
45 parse = function(param)
46 local find, _, dir, amount = param:find("(%a*)%s*([+-]?%d+)")
51 local hv_test = dir:find("[^hv]+")
52 if hv_test ~= nil then
53 return false, "Invalid direction."
56 return true, dir, tonumber(amount)
58 func = function(name, dir, amount)
59 if dir == "" or dir == "vh" or dir == "hv" then
60 assert(worldedit.cuboid_volumetric_expand(name, -amount))
61 elseif dir == "h" then
62 assert(worldedit.cuboid_linear_expand(name, 'x', 1, -amount))
63 assert(worldedit.cuboid_linear_expand(name, 'x', -1, -amount))
64 assert(worldedit.cuboid_linear_expand(name, 'z', 1, -amount))
65 assert(worldedit.cuboid_linear_expand(name, 'z', -1, -amount))
66 elseif dir == "v" then
67 assert(worldedit.cuboid_linear_expand(name, 'y', 1, -amount))
68 assert(worldedit.cuboid_linear_expand(name, 'y', -1, -amount))
70 return false, "Invalid number of arguments"
73 worldedit.marker_update(name)
74 return true, "Region inset by " .. amount .. " blocks"
79 worldedit.register_command("shift", {
80 params = "[x|y|z|?|up|down|left|right|front|back] [+|-]<amount>",
81 description = "Moves the selection region. Does not move contents.",
82 privs = {worldedit=true},
84 parse = function(param)
85 local find, _, direction, amount = param:find("([%?%l]+)%s*([+-]?%d+)")
90 return true, direction, tonumber(amount)
92 func = function(name, direction, amount)
94 if direction == "x" or direction == "y" or direction == "z" then
95 axis, dir = direction, 1
96 elseif direction == "?" then
97 axis, dir = worldedit.player_axis(name)
99 axis, dir = worldedit.translate_direction(name, direction)
102 if axis == nil or dir == nil then
103 return false, "Invalid if looking straight up or down"
106 assert(worldedit.cuboid_shift(name, axis, amount * dir))
107 worldedit.marker_update(name)
109 return true, "Region shifted by " .. amount .. " nodes"
114 worldedit.register_command("expand", {
115 params = "[+|-]<x|y|z|?|up|down|left|right|front|back> <amount> [reverse-amount]",
116 description = "expand the selection in one or two directions at once",
117 privs = {worldedit=true},
119 parse = function(param)
120 local find, _, sign, direction, amount,
121 rev_amount = param:find("([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)")
126 if rev_amount == "" then
130 return true, sign, direction, tonumber(amount), tonumber(rev_amount)
132 func = function(name, sign, direction, amount, rev_amount)
133 local absolute = direction:find("[xyz?]")
136 if absolute == nil then
137 axis, dir = worldedit.translate_direction(name, direction)
139 if axis == nil or dir == nil then
140 return false, "Invalid if looking straight up or down"
143 if direction == "?" then
144 axis, dir = worldedit.player_axis(name)
155 worldedit.cuboid_linear_expand(name, axis, dir, amount)
156 worldedit.cuboid_linear_expand(name, axis, -dir, rev_amount)
157 worldedit.marker_update(name)
158 return true, "Region expanded by " .. (amount + rev_amount) .. " nodes"
163 worldedit.register_command("contract", {
164 params = "[+|-]<x|y|z|?|up|down|left|right|front|back> <amount> [reverse-amount]",
165 description = "contract the selection in one or two directions at once",
166 privs = {worldedit=true},
168 parse = function(param)
169 local find, _, sign, direction, amount,
170 rev_amount = param:find("([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)")
175 if rev_amount == "" then
179 return true, sign, direction, tonumber(amount), tonumber(rev_amount)
181 func = function(name, sign, direction, amount, rev_amount)
182 local absolute = direction:find("[xyz?]")
185 if absolute == nil then
186 axis, dir = worldedit.translate_direction(name, direction)
188 if axis == nil or dir == nil then
189 return false, "Invalid if looking straight up or down"
192 if direction == "?" then
193 axis, dir = worldedit.player_axis(name)
204 worldedit.cuboid_linear_expand(name, axis, dir, -amount)
205 worldedit.cuboid_linear_expand(name, axis, -dir, -rev_amount)
206 worldedit.marker_update(name)
207 return true, "Region contracted by " .. (amount + rev_amount) .. " nodes"