1 minetest.register_chatcommand("/outset", {
2 params = "[h|v] <amount>",
3 description = "outset the selection",
4 privs = {worldedit=true},
5 func = function(name, param)
6 local find, _, dir, amount = param:find("(%a*)%s*([+-]?%d+)")
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."
20 local hv_test = dir:find("[^hv]+")
22 if hv_test ~= nil then
23 return false, "Invalid direction."
26 if dir == "" or dir == "hv" or dir == "vh" then
27 assert(worldedit.cuboid_volumetric_expand(name, amount))
28 elseif dir == "h" then
29 assert(worldedit.cuboid_linear_expand(name, 'x', 1, amount))
30 assert(worldedit.cuboid_linear_expand(name, 'x', -1, amount))
31 assert(worldedit.cuboid_linear_expand(name, 'z', 1, amount))
32 assert(worldedit.cuboid_linear_expand(name, 'z', -1, amount))
33 elseif dir == "v" then
34 assert(worldedit.cuboid_linear_expand(name, 'y', 1, amount))
35 assert(worldedit.cuboid_linear_expand(name, 'y', -1, amount))
37 return false, "Invalid number of arguments"
40 worldedit.marker_update(name)
41 return true, "Region outset by " .. amount .. " blocks"
47 minetest.register_chatcommand("/inset", {
48 params = "[h|v] <amount>",
49 description = "inset the selection",
50 privs = {worldedit=true},
51 func = function(name, param)
52 local find, _, dir, amount = param:find("(%a*)%s*([+-]?%d+)")
55 return false, "invalid usage: " .. param
58 local pos1 = worldedit.pos1[name]
59 local pos2 = worldedit.pos2[name]
61 if pos1 == nil or pos2 == nil then
63 "Undefined region. Region must be defined beforehand."
66 local hv_test = dir:find("[^hv]+")
68 if hv_test ~= nil then
69 return false, "Invalid direction."
72 if dir == "" or dir == "vh" or dir == "hv" then
73 assert(worldedit.cuboid_volumetric_expand(name, -amount))
74 elseif dir == "h" then
75 assert(worldedit.cuboid_linear_expand(name, 'x', 1, -amount))
76 assert(worldedit.cuboid_linear_expand(name, 'x', -1, -amount))
77 assert(worldedit.cuboid_linear_expand(name, 'z', 1, -amount))
78 assert(worldedit.cuboid_linear_expand(name, 'z', -1, -amount))
79 elseif dir == "v" then
80 assert(worldedit.cuboid_linear_expand(name, 'y', 1, -amount))
81 assert(worldedit.cuboid_linear_expand(name, 'y', -1, -amount))
83 return false, "Invalid number of arguments"
86 worldedit.marker_update(name)
87 return true, "Region inset by " .. amount .. " blocks"
93 minetest.register_chatcommand("/shift", {
94 params = "[x|y|z|?|up|down|left|right|front|back] [+|-]<amount>",
95 description = "Moves the selection region. Does not move contents.",
96 privs = {worldedit=true},
97 func = function(name, param)
98 local pos1 = worldedit.pos1[name]
99 local pos2 = worldedit.pos2[name]
100 local find, _, direction, amount = param:find("([%?%l]+)%s*([+-]?%d+)")
103 worldedit.player_notify(name, "invalid usage: " .. param)
107 if pos1 == nil or pos2 == nil then
108 worldedit.player_notify(name,
109 "Undefined region. Region must be defined beforehand.")
114 if direction == "x" or direction == "y" or direction == "z" then
115 axis, dir = direction, 1
116 elseif direction == "?" then
117 axis, dir = worldedit.player_axis(name)
119 axis, dir = worldedit.translate_direction(name, direction)
122 if axis == nil or dir == nil then
123 return false, "Invalid if looking straight up or down"
126 assert(worldedit.cuboid_shift(name, axis, amount * dir))
127 worldedit.marker_update(name)
129 return true, "Region shifted by " .. amount .. " nodes"
135 minetest.register_chatcommand("/expand", {
136 params = "[+|-]<x|y|z|?|up|down|left|right|front|back> <amount> [reverse-amount]",
137 description = "expand the selection in one or two directions at once",
138 privs = {worldedit=true},
139 func = function(name, param)
140 local find, _, sign, direction, amount,
141 rev_amount = param:find("([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)")
144 worldedit.player_notify(name, "invalid use: " .. param)
148 if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then
149 worldedit.player_notify(name,
150 "Undefined region. Region must be defined beforehand.")
154 local absolute = direction:find("[xyz?]")
157 if rev_amount == "" then
161 if absolute == nil then
162 axis, dir = worldedit.translate_direction(name, direction)
164 if axis == nil or dir == nil then
165 return false, "Invalid if looking straight up or down"
168 if direction == "?" then
169 axis, dir = worldedit.player_axis(name)
180 worldedit.cuboid_linear_expand(name, axis, dir, amount)
181 worldedit.cuboid_linear_expand(name, axis, -dir, rev_amount)
182 worldedit.marker_update(name)
183 return true, "Region expanded by " .. (amount + rev_amount) .. " nodes"
189 minetest.register_chatcommand("/contract", {
190 params = "[+|-]<x|y|z|?|up|down|left|right|front|back> <amount> [reverse-amount]",
191 description = "contract the selection in one or two directions at once",
192 privs = {worldedit=true},
193 func = function(name, param)
194 local find, _, sign, direction, amount,
195 rev_amount = param:find("([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)")
198 worldedit.player_notify(name, "invalid use: " .. param)
202 if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then
203 worldedit.player_notify(name,
204 "Undefined region. Region must be defined beforehand.")
208 local absolute = direction:find("[xyz?]")
211 if rev_amount == "" then
215 if absolute == nil then
216 axis, dir = worldedit.translate_direction(name, direction)
218 if axis == nil or dir == nil then
219 return false, "Invalid if looking straight up or down"
222 if direction == "?" then
223 axis, dir = worldedit.player_axis(name)
234 worldedit.cuboid_linear_expand(name, axis, dir, -amount)
235 worldedit.cuboid_linear_expand(name, axis, -dir, -rev_amount)
236 worldedit.marker_update(name)
237 return true, "Region contracted by " .. (amount + rev_amount) .. " nodes"