]> git.lizzy.rs Git - worldedit.git/blob - worldedit_commands/cuboid.lua
Remove some debug code
[worldedit.git] / worldedit_commands / cuboid.lua
1 dofile(minetest.get_modpath("worldedit_commands") .. "/cuboidapi.lua")
2
3
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]?)$")
10                 
11                 if find == nil then
12                         return false, "invalid usage: " .. param
13                 end
14                 
15                 local pos1 = worldedit.pos1[name]
16                 local pos2 = worldedit.pos2[name]
17                 
18                 if pos1 == nil or pos2 == nil then
19                         return false, 
20                                 "Undefined region. Region must be defined beforehand."
21                 end
22                 
23                 if dir == "" then
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))
33                 else
34                         return false, "Unknown error"
35                 end
36                 
37                 worldedit.marker_update(name)
38                 return true, "Region outset by " .. amount .. " blocks"
39       end,
40   }
41 )
42
43
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]?)$")
50                 
51                 if find == nil then
52                         return false, "invalid usage: " .. param
53                 end
54                 
55                 local pos1 = worldedit.pos1[name]
56                 local pos2 = worldedit.pos2[name]
57                 
58                 if pos1 == nil or pos2 == nil then
59                         return false, 
60                                 "Undefined region. Region must be defined beforehand."
61                 end
62                 
63                 if dir == "" then
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))
73                 else
74                         return false, "Unknown error"
75                 end
76                 
77                 worldedit.marker_update(name)
78                 return true, "Region inset by " .. amount .. " blocks"
79       end,
80   }
81 )
82
83
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+)")
92                 
93                 if find == nil then
94                         worldedit.player_notify(name, "invalid usage: " .. param)
95                         return
96                 end
97                 
98                 if pos1 == nil or pos2 == nil then
99                         worldedit.player_notify(name, 
100                                 "Undefined region. Region must be defined beforehand.")
101                         return
102                 end
103                 
104                 local axis, dir
105                 if direction ~= "?" then
106                         axis, dir = worldedit.translate_direction(name, direction)
107                 else
108                         axis, dir = worldedit.player_axis(name)
109                 end
110                 
111                 if axis == nil or dir == nil then
112                         return false, "Invalid"
113                 end
114                 
115                 assert(worldedit.cuboid_shift(name, axis, amount * dir))
116                 worldedit.marker_update(name)
117                 
118                 return true, "region shifted by " .. amount .. " nodes"
119       end,
120   }
121 )
122
123
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*)")
130         
131         if find == nil then
132                 worldedit.player_notify(name, "invalid use: " .. param)
133                 return
134         end
135         
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.")
139                 return
140         end
141         
142         local tmp = tonumber(arg2)
143         local axis, dir
144         local reverse_amount = 0
145         
146         axis,dir = worldedit.player_axis(name)
147         
148         if arg2 ~= "" then
149                 if tmp == nil then
150                         axis, dir = worldedit.translate_direction(name, arg2)
151                 else
152                         reverse_amount = tmp
153                 end
154         end
155         
156         if arg3 ~= "" then
157                 axis, dir = worldedit.translate_direction(name, arg3)
158         end
159         
160         worldedit.cuboid_linear_expand(name, axis, dir, amount)
161         worldedit.cuboid_linear_expand(name, axis, -dir, reverse_amount)
162         worldedit.marker_update(name)
163       end,
164   }
165 )
166
167
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*)")
174         
175         if find == nil then
176                 worldedit.player_notify(name, "invalid use: " .. param)
177                 return
178         end
179         
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.")
183                 return
184         end
185         
186         local tmp = tonumber(arg2)
187         local axis, dir
188         local reverse_amount = 0
189         
190         axis,dir = worldedit.player_axis(name)
191         
192         if arg2 ~= "" then
193                 if tmp == nil then
194                         axis, dir = worldedit.translate_direction(name, arg2)
195                 else
196                         reverse_amount = tmp
197                 end
198         end
199         
200         if arg3 ~= "" then
201                 axis, dir = worldedit.translate_direction(name, arg3)
202         end
203         
204         worldedit.cuboid_linear_expand(name, axis, dir, -amount)
205         worldedit.cuboid_linear_expand(name, axis, -dir, -reverse_amount)
206         worldedit.marker_update(name)
207       end,
208   }
209 )