@@ -172,6 +172,129 @@ worldedit.copy = function(pos1, pos2, axis, amount) --wip: replace the old versi
172
172
return worldedit .volume (pos1 , pos2 )
173
173
end
174
174
175
+ worldedit .copy2 = function (pos1 , pos2 , direction , volume )
176
+ -- the overlap shouldn't matter as long as we
177
+ -- 1) start at the furthest separated corner
178
+ -- 2) complete an edge before moving inward, either edge works
179
+ -- 3) complete a face before moving inward, similarly
180
+ --
181
+ -- to do this I
182
+ -- 1) find the furthest destination in the direction, of each axis
183
+ -- 2) call those the furthest separated corner
184
+ -- 3) make sure to iterate inward from there
185
+ -- 4) nested loop to make sure complete edge, complete face, then complete cube.
186
+
187
+ local get_node , get_meta , add_node = minetest .get_node , minetest .get_meta , minetest .add_node
188
+ local somemeta = get_meta (pos1 ) -- hax lol
189
+ local to_table = somemeta .to_table
190
+ local from_table = somemeta .from_table
191
+ somemeta = nil
192
+
193
+ local pos1 , pos2 = worldedit .sort_pos (pos1 , pos2 )
194
+ local manip = minetest .get_voxel_manip ()
195
+ manip :read_from_map (pos1 , pos2 )
196
+
197
+ local sx ,sy ,sz -- direction sign
198
+ local ix ,iy ,iz -- initial destination
199
+ local ex ,ey ,ez -- final destination
200
+ local originalx ,originaly ,originalz -- source
201
+ -- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g
202
+ if direction .x > 0 then
203
+ originalx = pos2 .x
204
+ ix = originalx + direction .x
205
+ ex = pos1 .x + direction .x
206
+ sx = - 1
207
+ elseif direction .x < 0 then
208
+ originalx = pos1 .x
209
+ ix = originalx + direction .x
210
+ ex = pos2 .x + direction .x
211
+ sx = 1
212
+ else
213
+ originalx = pos1 .x
214
+ ix = originalx -- whatever
215
+ ex = pos2 .x
216
+ sx = 1
217
+ end
218
+
219
+ if direction .y > 0 then
220
+ originaly = pos2 .y
221
+ iy = originaly + direction .y
222
+ ey = pos1 .y + direction .y
223
+ sy = - 1
224
+ elseif direction .y < 0 then
225
+ originaly = pos1 .y
226
+ iy = originaly + direction .y
227
+ ey = pos2 .y + direction .y
228
+ sy = 1
229
+ else
230
+ originaly = pos1 .y
231
+ iy = originaly -- whatever
232
+ ey = pos2 .y
233
+ sy = 1
234
+ end
235
+
236
+ if direction .z > 0 then
237
+ originalz = pos2 .z
238
+ iz = originalz + direction .z
239
+ ez = pos1 .z + direction .z
240
+ sz = - 1
241
+ elseif direction .z < 0 then
242
+ originalz = pos1 .z
243
+ iz = originalz + direction .z
244
+ ez = pos2 .z + direction .z
245
+ sz = 1
246
+ else
247
+ originalz = pos1 .z
248
+ iz = originalz -- whatever
249
+ ez = pos2 .z
250
+ sz = 1
251
+ end
252
+ -- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz)
253
+
254
+ local ox ,oy ,oz
255
+
256
+ ox = originalx
257
+ for x = ix ,ex ,sx do
258
+ oy = originaly
259
+ for y = iy ,ey ,sy do
260
+ oz = originalz
261
+ for z = iz ,ez ,sz do
262
+ -- reusing pos1/pos2 as source/dest here
263
+ pos1 .x = ox ; pos1 .y = oy ; pos1 .z = oz
264
+ pos2 .x = x ; pos2 .y = y ; pos2 .z = z
265
+ local node = get_node (pos1 )
266
+ local meta = to_table (get_meta (pos1 )) -- get meta of current node
267
+ add_node (pos2 ,node )
268
+ from_table (get_meta (pos2 ),meta )
269
+ oz = oz + sz
270
+ end
271
+ oy = oy + sy
272
+ end
273
+ ox = ox + sx
274
+ end
275
+ end
276
+
277
+ worldedit .stack2 = function (pos1 , pos2 , direction , amount , finished )
278
+ local i = 0
279
+ local translated = {x = 0 ,y = 0 ,z = 0 }
280
+ local function nextone ()
281
+ if i <= amount then
282
+ i = i + 1
283
+ translated .x = translated .x + direction .x
284
+ translated .y = translated .y + direction .y
285
+ translated .z = translated .z + direction .z
286
+ worldedit .copy2 (pos1 ,pos2 ,translated ,volume )
287
+ minetest .after (0 ,nextone )
288
+ else
289
+ if finished then
290
+ finished ()
291
+ end
292
+ end
293
+ end
294
+ nextone ()
295
+ return nil
296
+ end
297
+
175
298
-- copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied
176
299
worldedit .copy = function (pos1 , pos2 , axis , amount )
177
300
local pos1 , pos2 = worldedit .sort_pos (pos1 , pos2 )
0 commit comments