1 dofile(minetest.get_modpath("worldedit_commands") .. "/cuboidapi.lua")
4 minetest.register_chatcommand("/outset", {
5 params = "<amount> [h|v]",
6 description = "outset the selection",
7 privs = {worldedit=true},
8 func = function(name, param)
9 local find, _, amount, dir = param:find("^(%d+)[%s+]?([hv]?)$")
12 return false, "invalid usage: " .. param
15 local pos1 = worldedit.pos1[name]
16 local pos2 = worldedit.pos2[name]
18 if pos1 == nil or pos2 == nil then
20 "Undefined region. Region must be defined beforehand."
24 assert(worldedit.cuboid_volumetric_expand(name, amount))
25 elseif dir == "h" then
26 assert(worldedit.cuboid_linear_expand(name, 'x', 1, amount))
27 assert(worldedit.cuboid_linear_expand(name, 'x', -1, amount))
28 assert(worldedit.cuboid_linear_expand(name, 'z', 1, amount))
29 assert(worldedit.cuboid_linear_expand(name, 'z', -1, amount))
30 elseif dir == "v" then
31 assert(worldedit.cuboid_linear_expand(name, 'y', 1, amount))
32 assert(worldedit.cuboid_linear_expand(name, 'y', -1, amount))
34 return false, "Unknown error"
37 worldedit.marker_update(name)
38 return true, "Region outset by " .. amount .. " blocks"
44 minetest.register_chatcommand("/inset", {
45 params = "<amount> [h|v]",
46 description = "inset the selection",
47 privs = {worldedit=true},
48 func = function(name, param)
49 local find, _, amount, dir = param:find("^(%d+)[%s+]?([hv]?)$")
52 return false, "invalid usage: " .. param
55 local pos1 = worldedit.pos1[name]
56 local pos2 = worldedit.pos2[name]
58 if pos1 == nil or pos2 == nil then
60 "Undefined region. Region must be defined beforehand."
64 assert(worldedit.cuboid_volumetric_expand(name, -amount))
65 elseif dir == "h" then
66 assert(worldedit.cuboid_linear_expand(name, 'x', 1, -amount))
67 assert(worldedit.cuboid_linear_expand(name, 'x', -1, -amount))
68 assert(worldedit.cuboid_linear_expand(name, 'z', 1, -amount))
69 assert(worldedit.cuboid_linear_expand(name, 'z', -1, -amount))
70 elseif dir == "v" then
71 assert(worldedit.cuboid_linear_expand(name, 'y', 1, -amount))
72 assert(worldedit.cuboid_linear_expand(name, 'y', -1, -amount))
74 return false, "Unknown error"
77 worldedit.marker_update(name)
78 return true, "Region inset by " .. amount .. " blocks"
84 minetest.register_chatcommand("/shift", {
85 params = "[x|y|z|?|up|down|left|right|front|back] [+|-]<amount>",
86 description = "Moves the selection region. Does not move contents.",
87 privs = {worldedit=true},
88 func = function(name, param)
89 local pos1 = worldedit.pos1[name]
90 local pos2 = worldedit.pos2[name]
91 local find, _, direction, amount = param:find("([%?%l]+)%s*([+-]?%d+)")
94 worldedit.player_notify(name, "invalid usage: " .. param)
98 if pos1 == nil or pos2 == nil then
99 worldedit.player_notify(name,
100 "Undefined region. Region must be defined beforehand.")
105 if direction ~= "?" then
106 axis, dir = worldedit.translate_direction(name, direction)
108 axis, dir = worldedit.player_axis(name)
111 if axis == nil or dir == nil then
112 return false, "Invalid"
115 assert(worldedit.cuboid_shift(name, axis, amount * dir))
116 worldedit.marker_update(name)
118 return true, "region shifted by " .. amount .. " nodes"
124 minetest.register_chatcommand("/expand", {
125 params = "<amount> [reverse-amount] [up|down|left|right|front|back]",
126 description = "expand the selection in one or two directions at once",
127 privs = {worldedit=true},
128 func = function(name, param)
129 local find, _, amount, arg2, arg3 = param:find("(%d+)%s*(%w*)%s*(%l*)")
132 worldedit.player_notify(name, "invalid use: " .. param)
136 if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then
137 worldedit.player_notify(name,
138 "Undefined region. Region must be defined beforehand.")
142 local tmp = tonumber(arg2)
144 local reverse_amount = 0
146 axis,dir = worldedit.player_axis(name)
150 axis, dir = worldedit.translate_direction(name, arg2)
157 axis, dir = worldedit.translate_direction(name, arg3)
160 worldedit.cuboid_linear_expand(name, axis, dir, amount)
161 worldedit.cuboid_linear_expand(name, axis, -dir, reverse_amount)
162 worldedit.marker_update(name)
168 minetest.register_chatcommand("/contract", {
169 params = "<amount> [reverse-amount] [up|down|left|right|front|back]",
170 description = "contract the selection in one or two directions at once",
171 privs = {worldedit=true},
172 func = function(name, param)
173 local find, _, amount, arg2, arg3 = param:find("(%d+)%s*(%w*)%s*(%l*)")
176 worldedit.player_notify(name, "invalid use: " .. param)
180 if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then
181 worldedit.player_notify(name,
182 "Undefined region. Region must be defined beforehand.")
186 local tmp = tonumber(arg2)
188 local reverse_amount = 0
190 axis,dir = worldedit.player_axis(name)
194 axis, dir = worldedit.translate_direction(name, arg2)
201 axis, dir = worldedit.translate_direction(name, arg3)
204 worldedit.cuboid_linear_expand(name, axis, dir, -amount)
205 worldedit.cuboid_linear_expand(name, axis, -dir, -reverse_amount)
206 worldedit.marker_update(name)