@@ -48,8 +48,16 @@ worldedit.set = function(pos1, pos2, nodenames)
48
48
for i ,v in ipairs (nodenames ) do
49
49
node_ids [i ] = minetest .get_content_id (nodenames [i ])
50
50
end
51
- for i in area :iterp (pos1 , pos2 ) do
52
- nodes [i ] = node_ids [math.random (# node_ids )]
51
+ if # node_ids == 1 then -- only one type of node
52
+ local id = node_ids [1 ]
53
+ for i in area :iterp (pos1 , pos2 ) do
54
+ nodes [i ] = node_ids [id ]
55
+ end
56
+ else -- fill randomly with all types of specified nodes
57
+ local id_count , rand = # node_ids , math.random
58
+ for i in area :iterp (pos1 , pos2 ) do
59
+ nodes [i ] = node_ids [rand (id_count )]
60
+ end
53
61
end
54
62
55
63
-- update map nodes
@@ -173,126 +181,126 @@ worldedit.copy = function(pos1, pos2, axis, amount) --wip: replace the old versi
173
181
end
174
182
175
183
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
-
184
+ -- the overlap shouldn't matter as long as we
185
+ -- 1) start at the furthest separated corner
186
+ -- 2) complete an edge before moving inward, either edge works
187
+ -- 3) complete a face before moving inward, similarly
188
+ --
189
+ -- to do this I
190
+ -- 1) find the furthest destination in the direction, of each axis
191
+ -- 2) call those the furthest separated corner
192
+ -- 3) make sure to iterate inward from there
193
+ -- 4) nested loop to make sure complete edge, complete face, then complete cube.
194
+
187
195
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
196
+ local somemeta = get_meta (pos1 ) -- hax lol
197
+ local to_table = somemeta .to_table
198
+ local from_table = somemeta .from_table
199
+ somemeta = nil
192
200
193
201
local pos1 , pos2 = worldedit .sort_pos (pos1 , pos2 )
194
202
local manip = minetest .get_voxel_manip ()
195
203
manip :read_from_map (pos1 , pos2 )
196
204
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
205
+ local sx , sy , sz -- direction sign
206
+ local ix , iy , iz -- initial destination
207
+ local ex , ey , ez -- final destination
208
+ local originalx , originaly , originalz -- source
209
+ -- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g
210
+ if direction .x > 0 then
211
+ originalx = pos2 .x
212
+ ix = originalx + direction .x
213
+ ex = pos1 .x + direction .x
214
+ sx = - 1
215
+ elseif direction .x < 0 then
216
+ originalx = pos1 .x
217
+ ix = originalx + direction .x
218
+ ex = pos2 .x + direction .x
219
+ sx = 1
220
+ else
221
+ originalx = pos1 .x
222
+ ix = originalx -- whatever
223
+ ex = pos2 .x
224
+ sx = 1
225
+ end
218
226
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
227
+ if direction .y > 0 then
228
+ originaly = pos2 .y
229
+ iy = originaly + direction .y
230
+ ey = pos1 .y + direction .y
231
+ sy = - 1
232
+ elseif direction .y < 0 then
233
+ originaly = pos1 .y
234
+ iy = originaly + direction .y
235
+ ey = pos2 .y + direction .y
236
+ sy = 1
237
+ else
238
+ originaly = pos1 .y
239
+ iy = originaly -- whatever
240
+ ey = pos2 .y
241
+ sy = 1
242
+ end
235
243
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 )
244
+ if direction .z > 0 then
245
+ originalz = pos2 .z
246
+ iz = originalz + direction .z
247
+ ez = pos1 .z + direction .z
248
+ sz = - 1
249
+ elseif direction .z < 0 then
250
+ originalz = pos1 .z
251
+ iz = originalz + direction .z
252
+ ez = pos2 .z + direction .z
253
+ sz = 1
254
+ else
255
+ originalz = pos1 .z
256
+ iz = originalz -- whatever
257
+ ez = pos2 .z
258
+ sz = 1
259
+ end
260
+ -- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz)
261
+
262
+ local ox ,oy ,oz
263
+
264
+ ox = originalx
265
+ for x = ix , ex , sx do
266
+ oy = originaly
267
+ for y = iy , ey , sy do
268
+ oz = originalz
269
+ for z = iz , ez , sz do
270
+ -- reusing pos1/pos2 as source/dest here
271
+ pos1 .x , pos1 .y , pos1 .z = ox , oy , oz
272
+ pos2 .x , pos2 .y , pos2 .z = x , y , z
273
+ local node = get_node (pos1 )
266
274
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
275
+ add_node (pos2 ,node )
276
+ from_table (get_meta (pos2 ),meta )
277
+ oz = oz + sz
278
+ end
279
+ oy = oy + sy
280
+ end
281
+ ox = ox + sx
282
+ end
283
+ end
284
+
285
+ worldedit .stack2 = function (pos1 , pos2 , direction , amount , finished )
286
+ local i = 0
287
+ local translated = {x = 0 ,y = 0 ,z = 0 }
288
+ local function nextone ()
289
+ if i <= amount then
290
+ i = i + 1
291
+ translated .x = translated .x + direction .x
292
+ translated .y = translated .y + direction .y
293
+ translated .z = translated .z + direction .z
294
+ worldedit .copy2 (pos1 , pos2 , translated , volume )
295
+ minetest .after (0 , nextone )
296
+ else
297
+ if finished then
298
+ finished ()
299
+ end
300
+ end
301
+ end
302
+ nextone ()
303
+ return nil
296
304
end
297
305
298
306
-- 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
0 commit comments