@@ -13,6 +13,7 @@ if minetest.place_schematic then
13
13
end
14
14
15
15
dofile (minetest .get_modpath (" worldedit_commands" ) .. " /mark.lua" )
16
+ dofile (minetest .get_modpath (" worldedit_commands" ) .. " /safe.lua" )
16
17
17
18
local get_position = function (name )
18
19
local pos1 = worldedit .pos1 [name ]
@@ -31,71 +32,6 @@ local get_node = function(name, nodename)
31
32
return node
32
33
end
33
34
34
-
35
- -- `callback` is a callback to run when the user confirms
36
- -- `nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed
37
- local safe_region
38
- do -- safe region wrapper function
39
- local safe_region_callback
40
- local safe_region_name
41
- local safe_region_param
42
- safe_region = function (callback , nodes_needed )
43
- nodes_needed = nodes_needed or worldedit .volume
44
- return function (name , param )
45
- -- obtain positions
46
- local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
47
- if pos1 == nil or pos2 == nil then
48
- worldedit .player_notify (name , " no region selected" )
49
- return nil
50
- end
51
-
52
- -- check volume
53
- local count = nodes_needed (pos1 , pos2 , name , param )
54
- if not count or count < 10000 then
55
- return callback (name , param , pos1 , pos2 )
56
- end
57
-
58
- -- save callback to call later
59
- safe_region_callback , safe_region_name , safe_region_param = callback , name , param
60
- worldedit .player_notify (name , " WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel" )
61
- end
62
- end
63
-
64
- minetest .register_chatcommand (" /y" , {
65
- params = " " ,
66
- description = " Confirm a pending operation" ,
67
- func = function ()
68
- local callback , name , param = safe_region_callback , safe_region_name , safe_region_param
69
- if not callback then
70
- worldedit .player_notify (name , " no operation pending" )
71
- return
72
- end
73
-
74
- -- obtain positions
75
- local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
76
- if pos1 == nil or pos2 == nil then
77
- worldedit .player_notify (name , " no region selected" )
78
- return
79
- end
80
-
81
- safe_region_callback , safe_region_name , safe_region_param = nil , nil , nil -- reset pending operation
82
- callback (name , param , pos1 , pos2 )
83
- end ,
84
- })
85
-
86
- minetest .register_chatcommand (" /n" , {
87
- params = " " ,
88
- description = " Confirm a pending operation" ,
89
- func = function ()
90
- if not safe_region_callback then
91
- worldedit .player_notify (name , " no operation pending" )
92
- return
93
- end
94
- safe_region_callback , safe_region_name , safe_region_param = nil , nil , nil
95
- end ,
96
- })
97
- end
98
-
99
35
worldedit .player_notify = function (name , message )
100
36
minetest .chat_send_player (name , " WorldEdit -!- " .. message , false )
101
37
end
@@ -135,7 +71,16 @@ worldedit.player_axis = function(name)
135
71
return " z" , dir .z > 0 and 1 or - 1
136
72
end
137
73
74
+ local check_region = function (name , param )
75
+ -- obtain positions
76
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
77
+ if pos1 == nil or pos2 == nil then
78
+ worldedit .player_notify (name , " no region selected" )
79
+ return nil
80
+ end
138
81
82
+ return worldedit .volume (pos1 , pos2 )
83
+ end
139
84
140
85
minetest .register_chatcommand (" /about" , {
141
86
params = " " ,
@@ -344,259 +289,270 @@ minetest.register_chatcommand("/volume", {
344
289
end ,
345
290
})
346
291
292
+ local check_set = function (name , param )
293
+ local node = get_node (name , param )
294
+ if not node then return nil end
295
+ return check_region (name , param )
296
+ end
297
+
347
298
minetest .register_chatcommand (" /set" , {
348
299
params = " <node>" ,
349
300
description = " Set the current WorldEdit region to <node>" ,
350
301
privs = {worldedit = true },
351
- func = safe_region (function (name , param , pos1 , pos2 )
302
+ func = safe_region (function (name , param )
303
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
352
304
local node = get_node (name , param )
353
- if not node then return end
354
-
355
305
local count = worldedit .set (pos1 , pos2 , node )
356
306
worldedit .player_notify (name , count .. " nodes set" )
357
- end ),
307
+ end , check_set ),
358
308
})
359
309
310
+ local check_replace = function (name , param )
311
+ local found , _ , searchnode , replacenode = param :find (" ^([^%s]+)%s+(.+)$" )
312
+ if found == nil then
313
+ worldedit .player_notify (name , " invalid usage: " .. param )
314
+ return nil
315
+ end
316
+ local newsearchnode = worldedit .normalize_nodename (searchnode )
317
+ if not newsearchnode then
318
+ worldedit .player_notify (name , " invalid search node name: " .. searchnode )
319
+ return nil
320
+ end
321
+ local newreplacenode = worldedit .normalize_nodename (replacenode )
322
+ if not newreplacenode then
323
+ worldedit .player_notify (name , " invalid replace node name: " .. replacenode )
324
+ return nil
325
+ end
326
+ return check_region (name , param )
327
+ end
328
+
360
329
minetest .register_chatcommand (" /replace" , {
361
330
params = " <search node> <replace node>" ,
362
331
description = " Replace all instances of <search node> with <replace node> in the current WorldEdit region" ,
363
332
privs = {worldedit = true },
364
- func = safe_region (function (name , param , pos1 , pos2 )
333
+ func = safe_region (function (name , param )
334
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
365
335
local found , _ , searchnode , replacenode = param :find (" ^([^%s]+)%s+(.+)$" )
366
- if found == nil then
367
- worldedit .player_notify (name , " invalid usage: " .. param )
368
- return
369
- end
370
336
local newsearchnode = worldedit .normalize_nodename (searchnode )
371
- if not newsearchnode then
372
- worldedit .player_notify (name , " invalid search node name: " .. searchnode )
373
- return
374
- end
375
337
local newreplacenode = worldedit .normalize_nodename (replacenode )
376
- if not newreplacenode then
377
- worldedit .player_notify (name , " invalid replace node name: " .. replacenode )
378
- return
379
- end
380
-
381
338
local count = worldedit .replace (pos1 , pos2 , newsearchnode , newreplacenode )
382
339
worldedit .player_notify (name , count .. " nodes replaced" )
383
- end ),
340
+ end , check_replace ),
384
341
})
385
342
386
343
minetest .register_chatcommand (" /replaceinverse" , {
387
344
params = " <search node> <replace node>" ,
388
345
description = " Replace all nodes other than <search node> with <replace node> in the current WorldEdit region" ,
389
346
privs = {worldedit = true },
390
- func = safe_region (function (name , param , pos1 , pos2 )
347
+ func = safe_region (function (name , param )
348
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
391
349
local found , _ , searchnode , replacenode = param :find (" ^([^%s]+)%s+(.+)$" )
392
- if found == nil then
393
- worldedit .player_notify (name , " invalid usage: " .. param )
394
- return
395
- end
396
350
local newsearchnode = worldedit .normalize_nodename (searchnode )
397
- if not newsearchnode then
398
- worldedit .player_notify (name , " invalid search node name: " .. searchnode )
399
- return
400
- end
401
351
local newreplacenode = worldedit .normalize_nodename (replacenode )
402
- if not newreplacenode then
403
- worldedit .player_notify (name , " invalid replace node name: " .. replacenode )
404
- return
405
- end
406
-
407
352
local count = worldedit .replaceinverse (pos1 , pos2 , searchnode , replacenode )
408
353
worldedit .player_notify (name , count .. " nodes replaced" )
409
- end ),
354
+ end , check_replace ),
410
355
})
411
356
357
+ local check_sphere = function (name , param )
358
+ if worldedit .pos1 [name ] == nil then
359
+ worldedit .player_notify (name , " no position 1 selected" )
360
+ return nil
361
+ end
362
+ local found , _ , radius , nodename = param :find (" ^(%d+)%s+(.+)$" )
363
+ if found == nil then
364
+ worldedit .player_notify (name , " invalid usage: " .. param )
365
+ return nil
366
+ end
367
+ local node = get_node (name , nodename )
368
+ if not node then return nil end
369
+ return math.ceil ((4 * math.pi * (tonumber (radius ) ^ 3 )) / 3 ) -- volume of sphere
370
+ end
371
+
412
372
minetest .register_chatcommand (" /hollowsphere" , {
413
373
params = " <radius> <node>" ,
414
374
description = " Add hollow sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>" ,
415
375
privs = {worldedit = true },
416
- func = function (name , param )
417
- local pos = get_position (name )
418
- if pos == nil then return end
419
-
376
+ func = safe_region (function (name , param )
377
+ local pos = worldedit .pos1 [name ]
420
378
local found , _ , radius , nodename = param :find (" ^(%d+)%s+(.+)$" )
421
- if found == nil then
422
- worldedit .player_notify (name , " invalid usage: " .. param )
423
- return
424
- end
425
379
local node = get_node (name , nodename )
426
- if not node then return end
427
-
428
380
local count = worldedit .hollow_sphere (pos , tonumber (radius ), node )
429
381
worldedit .player_notify (name , count .. " nodes added" )
430
- end ,
382
+ end , check_sphere ),
431
383
})
432
384
433
385
minetest .register_chatcommand (" /sphere" , {
434
386
params = " <radius> <node>" ,
435
387
description = " Add sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>" ,
436
388
privs = {worldedit = true },
437
- func = function (name , param )
438
- local pos = get_position (name )
439
- if pos == nil then return end
440
-
389
+ func = safe_region (function (name , param )
390
+ local pos = worldedit .pos1 [name ]
441
391
local found , _ , radius , nodename = param :find (" ^(%d+)%s+(.+)$" )
442
- if found == nil then
443
- worldedit .player_notify (name , " invalid usage: " .. param )
444
- return
445
- end
446
392
local node = get_node (name , nodename )
447
- if not node then return end
448
-
449
393
local count = worldedit .sphere (pos , tonumber (radius ), node )
450
394
worldedit .player_notify (name , count .. " nodes added" )
451
- end ,
395
+ end , check_sphere ),
452
396
})
453
397
398
+ local check_dome = function (name , param )
399
+ if worldedit .pos1 [name ] == nil then
400
+ worldedit .player_notify (name , " no position 1 selected" )
401
+ return nil
402
+ end
403
+ local found , _ , radius , nodename = param :find (" ^(%d+)%s+(.+)$" )
404
+ if found == nil then
405
+ worldedit .player_notify (name , " invalid usage: " .. param )
406
+ return nil
407
+ end
408
+ local node = get_node (name , nodename )
409
+ if not node then return nil end
410
+ return math.ceil ((2 * math.pi * (tonumber (radius ) ^ 3 )) / 3 ) -- volume of dome
411
+ end
412
+
454
413
minetest .register_chatcommand (" /hollowdome" , {
455
414
params = " <radius> <node>" ,
456
415
description = " Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>" ,
457
416
privs = {worldedit = true },
458
- func = function (name , param )
459
- local pos = get_position (name )
460
- if pos == nil then return end
461
-
462
- local found , _ , radius , nodename = param :find (" ^([+-]?%d+)%s+(.+)$" )
463
- if found == nil then
464
- worldedit .player_notify (name , " invalid usage: " .. param )
465
- return
466
- end
417
+ func = safe_region (function (name , param )
418
+ local pos = worldedit .pos1 [name ]
419
+ local found , _ , radius , nodename = param :find (" ^(%d+)%s+(.+)$" )
467
420
local node = get_node (name , nodename )
468
- if not node then return end
469
-
470
421
local count = worldedit .hollow_dome (pos , tonumber (radius ), node )
471
422
worldedit .player_notify (name , count .. " nodes added" )
472
- end ,
423
+ end , check_dome ),
473
424
})
474
425
475
426
minetest .register_chatcommand (" /dome" , {
476
427
params = " <radius> <node>" ,
477
428
description = " Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node>" ,
478
429
privs = {worldedit = true },
479
- func = function (name , param )
480
- local pos = get_position (name )
481
- if pos == nil then return end
482
-
483
- local found , _ , radius , nodename = param :find (" ^([+-]?%d+)%s+(.+)$" )
484
- if found == nil then
485
- worldedit .player_notify (name , " invalid usage: " .. param )
486
- return
487
- end
430
+ func = safe_region (function (name , param )
431
+ local pos = worldedit .pos1 [name ]
432
+ local found , _ , radius , nodename = param :find (" ^(%d+)%s+(.+)$" )
488
433
local node = get_node (name , nodename )
489
- if not node then return end
490
-
491
434
local count = worldedit .dome (pos , tonumber (radius ), node )
492
435
worldedit .player_notify (name , count .. " nodes added" )
493
- end ,
436
+ end , check_dome ),
494
437
})
495
438
439
+ local check_cylinder = function (name , param )
440
+ if worldedit .pos1 [name ] == nil then
441
+ worldedit .player_notify (name , " no position 1 selected" )
442
+ return nil
443
+ end
444
+ local found , _ , axis , length , radius , nodename = param :find (" ^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$" )
445
+ if found == nil then
446
+ worldedit .player_notify (name , " invalid usage: " .. param )
447
+ return nil
448
+ end
449
+ local node = get_node (name , nodename )
450
+ if not node then return nil end
451
+ return math.ceil (math.pi * (tonumber (radius ) ^ 2 ) * tonumber (length ))
452
+ end
453
+
496
454
minetest .register_chatcommand (" /hollowcylinder" , {
497
455
params = " x/y/z/? <length> <radius> <node>" ,
498
456
description = " Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>" ,
499
457
privs = {worldedit = true },
500
- func = function (name , param )
501
- local pos = get_position (name )
502
- if pos == nil then return end
503
-
458
+ func = safe_region (function (name , param )
459
+ local pos = worldedit .pos1 [name ]
504
460
local found , _ , axis , length , radius , nodename = param :find (" ^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$" )
505
- if found == nil then
506
- worldedit .player_notify (name , " invalid usage: " .. param )
507
- return
508
- end
509
- length , radius = tonumber (length ), tonumber (radius )
461
+ length = tonumber (length )
510
462
if axis == " ?" then
511
463
axis , sign = worldedit .player_axis (name )
512
464
length = length * sign
513
465
end
514
466
local node = get_node (name , nodename )
515
- if not node then return end
516
-
517
- local count = worldedit .hollow_cylinder (pos , axis , length , radius , node )
467
+ local count = worldedit .hollow_cylinder (pos , axis , length , tonumber (radius ), node )
518
468
worldedit .player_notify (name , count .. " nodes added" )
519
- end ,
469
+ end , check_cylinder ),
520
470
})
521
471
522
472
minetest .register_chatcommand (" /cylinder" , {
523
473
params = " x/y/z/? <length> <radius> <node>" ,
524
474
description = " Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>" ,
525
475
privs = {worldedit = true },
526
- func = function (name , param )
527
- local pos = get_position (name )
528
- if pos == nil then return end
529
-
476
+ func = safe_region (function (name , param )
477
+ local pos = worldedit .pos1 [name ]
530
478
local found , _ , axis , length , radius , nodename = param :find (" ^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$" )
531
- if found == nil then
532
- worldedit .player_notify (name , " invalid usage: " .. param )
533
- return
534
- end
535
- length , radius = tonumber (length ), tonumber (radius )
479
+ length = tonumber (length )
536
480
if axis == " ?" then
537
481
axis , sign = worldedit .player_axis (name )
538
482
length = length * sign
539
483
end
540
484
local node = get_node (name , nodename )
541
- if not node then return end
542
-
543
- local count = worldedit .cylinder (pos , axis , length , radius , node )
485
+ local count = worldedit .cylinder (pos , axis , length , tonumber (radius ), node )
544
486
worldedit .player_notify (name , count .. " nodes added" )
545
- end ,
487
+ end , check_cylinder ),
546
488
})
547
489
548
490
minetest .register_chatcommand (" /pyramid" , {
549
491
params = " x/y/z/? <height> <node>" ,
550
492
description = " Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>" ,
551
493
privs = {worldedit = true },
552
- func = function (name , param )
494
+ func = safe_region ( function (name , param )
553
495
local pos = get_position (name )
554
- if pos == nil then return end
555
-
556
496
local found , _ , axis , height , nodename = param :find (" ^([xyz%?])%s+([+-]?%d+)%s+(.+)$" )
557
- if found == nil then
558
- worldedit .player_notify (name , " invalid usage: " .. param )
559
- return
560
- end
561
497
height = tonumber (height )
562
498
if axis == " ?" then
563
499
axis , sign = worldedit .player_axis (name )
564
500
height = height * sign
565
501
end
566
502
local node = get_node (name , nodename )
567
- if not node then return end
568
-
569
503
local count = worldedit .pyramid (pos , axis , height , node )
570
504
worldedit .player_notify (name , count .. " nodes added" )
571
505
end ,
506
+ function (name , param )
507
+ if worldedit .pos1 [name ] == nil then
508
+ worldedit .player_notify (name , " no position 1 selected" )
509
+ return nil
510
+ end
511
+ local found , _ , axis , height , nodename = param :find (" ^([xyz%?])%s+([+-]?%d+)%s+(.+)$" )
512
+ if found == nil then
513
+ worldedit .player_notify (name , " invalid usage: " .. param )
514
+ return nil
515
+ end
516
+ local node = get_node (name , nodename )
517
+ if not node then return nil end
518
+ height = tonumber (height )
519
+ return math.ceil (((height * 2 + 1 ) ^ 2 ) * height / 3 )
520
+ end ),
572
521
})
573
522
574
523
minetest .register_chatcommand (" /spiral" , {
575
524
params = " <length> <height> <space> <node>" ,
576
525
description = " Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <space>, composed of <node>" ,
577
526
privs = {worldedit = true },
578
- func = function (name , param )
579
- local pos = get_position (name )
580
- if pos == nil then return end
581
-
527
+ func = safe_region (function (name , param )
528
+ local pos = worldedit .pos1 [name ]
582
529
local found , _ , length , height , space , nodename = param :find (" ^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$" )
583
- if found == nil then
584
- worldedit .player_notify (name , " invalid usage: " .. param )
585
- return
586
- end
587
530
local node = get_node (name , nodename )
588
- if not node then return end
589
-
590
531
local count = worldedit .spiral (pos , tonumber (length ), tonumber (height ), tonumber (space ), node )
591
532
worldedit .player_notify (name , count .. " nodes added" )
592
533
end ,
534
+ function (name , param )
535
+ if worldedit .pos1 [name ] == nil then
536
+ worldedit .player_notify (name , " no position 1 selected" )
537
+ return nil
538
+ end
539
+ local found , _ , length , height , space , nodename = param :find (" ^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$" )
540
+ if found == nil then
541
+ worldedit .player_notify (name , " invalid usage: " .. param )
542
+ return nil
543
+ end
544
+ local node = get_node (name , nodename )
545
+ if not node then return nil end
546
+ return check_region (name , param )
547
+ end ),
593
548
})
594
549
595
550
minetest .register_chatcommand (" /copy" , {
596
551
params = " x/y/z/? <amount>" ,
597
552
description = " Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes" ,
598
553
privs = {worldedit = true },
599
- func = safe_region (function (name , param , pos1 , pos2 )
554
+ func = safe_region (function (name , param )
555
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
600
556
local found , _ , axis , amount = param :find (" ^([xyz%?])%s+([+-]?%d+)$" )
601
557
if found == nil then
602
558
worldedit .player_notify (name , " invalid usage: " .. param )
@@ -610,14 +566,19 @@ minetest.register_chatcommand("/copy", {
610
566
611
567
local count = worldedit .copy (pos1 , pos2 , axis , amount )
612
568
worldedit .player_notify (name , count .. " nodes copied" )
569
+ end ,
570
+ function (name , param )
571
+ local volume = check_region (name , param )
572
+ return volume and volume * 2 or volume
613
573
end ),
614
574
})
615
575
616
576
minetest .register_chatcommand (" /move" , {
617
577
params = " x/y/z/? <amount>" ,
618
578
description = " Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes" ,
619
579
privs = {worldedit = true },
620
- func = safe_region (function (name , param , pos1 , pos2 )
580
+ func = safe_region (function (name , param )
581
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
621
582
local found , _ , axis , amount = param :find (" ^([xyz%?])%s+([+-]?%d+)$" )
622
583
if found == nil then
623
584
worldedit .player_notify (name , " invalid usage: " .. param )
@@ -636,51 +597,43 @@ minetest.register_chatcommand("/move", {
636
597
worldedit .mark_pos1 (name )
637
598
worldedit .mark_pos2 (name )
638
599
worldedit .player_notify (name , count .. " nodes moved" )
639
- end ),
600
+ end , check_region ),
640
601
})
641
602
642
603
minetest .register_chatcommand (" /stack" , {
643
604
params = " x/y/z/? <count>" ,
644
605
description = " Stack the current WorldEdit region along the x/y/z/? axis <count> times" ,
645
606
privs = {worldedit = true },
646
- func = safe_region (function (name , param , pos1 , pos2 )
607
+ func = safe_region (function (name , param )
608
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
647
609
local found , _ , axis , repetitions = param :find (" ^([xyz%?])%s+([+-]?%d+)$" )
648
- if found == nil then
649
- worldedit .player_notify (name , " invalid usage: " .. param )
650
- return
651
- end
652
610
repetitions = tonumber (repetitions )
653
611
if axis == " ?" then
654
612
axis , sign = worldedit .player_axis (name )
655
613
repetitions = repetitions * sign
656
614
end
657
-
658
615
local count = worldedit .stack (pos1 , pos2 , axis , repetitions )
659
616
worldedit .player_notify (name , count .. " nodes stacked" )
660
617
end ,
661
- function (pos1 , pos2 , name , param )
618
+ function (name , param )
662
619
local found , _ , axis , repetitions = param :find (" ^([xyz%?])%s+([+-]?%d+)$" )
663
- if found then
664
- return tonumber ( repetitions ) * worldedit .volume ( pos1 , pos2 )
620
+ if found == nil then
621
+ worldedit .player_notify ( name , " invalid usage: " .. param )
665
622
end
623
+ local count = check_region (name , param )
624
+ if count then return (tonumber (repetitions ) + 1 ) * count end
625
+ return nil
666
626
end ),
667
627
})
668
628
669
629
minetest .register_chatcommand (" /stretch" , {
670
630
params = " <stretchx> <stretchy> <stretchz>" ,
671
631
description = " Scale the current WorldEdit positions and region by a factor of <stretchx>, <stretchy>, <stretchz> along the X, Y, and Z axes, repectively, with position 1 as the origin" ,
672
632
privs = {worldedit = true },
673
- func = safe_region (function (name , param , pos1 , pos2 )
633
+ func = safe_region (function (name , param )
634
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
674
635
local found , _ , stretchx , stretchy , stretchz = param :find (" ^(%d+)%s+(%d+)%s+(%d+)$" )
675
- if found == nil then
676
- worldedit .player_notify (name , " invalid usage: " .. param )
677
- return
678
- end
679
636
stretchx , stretchy , stretchz = tonumber (stretchx ), tonumber (stretchy ), tonumber (stretchz )
680
- if stretchx == 0 or stretchy == 0 or stretchz == 0 then
681
- worldedit .player_notify (name , " invalid scaling factors: " .. param )
682
- end
683
-
684
637
local count , pos1 , pos2 = worldedit .stretch (pos1 , pos2 , stretchx , stretchy , stretchz )
685
638
686
639
-- reset markers to scaled positions
@@ -691,35 +644,31 @@ minetest.register_chatcommand("/stretch", {
691
644
692
645
worldedit .player_notify (name , count .. " nodes stretched" )
693
646
end ,
694
- function (pos1 , pos2 , name , param )
647
+ function (name , param )
695
648
local found , _ , stretchx , stretchy , stretchz = param :find (" ^(%d+)%s+(%d+)%s+(%d+)$" )
696
- if found then
697
- return tonumber (stretchx ) * tonumber (stretchy ) * tonumber (stretchz ) * worldedit .volume (pos1 , pos2 )
649
+ if found == nil then
650
+ worldedit .player_notify (name , " invalid usage: " .. param )
651
+ return nil
698
652
end
653
+ stretchx , stretchy , stretchz = tonumber (stretchx ), tonumber (stretchy ), tonumber (stretchz )
654
+ if stretchx == 0 or stretchy == 0 or stretchz == 0 then
655
+ worldedit .player_notify (name , " invalid scaling factors: " .. param )
656
+ end
657
+ local count = check_region (name , param )
658
+ if count then return tonumber (stretchx ) * tonumber (stretchy ) * tonumber (stretchz ) * count end
659
+ return nil
699
660
end ),
700
661
})
701
662
702
663
minetest .register_chatcommand (" /transpose" , {
703
664
params = " x/y/z/? x/y/z/?" ,
704
665
description = " Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes" ,
705
666
privs = {worldedit = true },
706
- func = safe_region (function (name , param , pos1 , pos2 )
667
+ func = safe_region (function (name , param )
668
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
707
669
local found , _ , axis1 , axis2 = param :find (" ^([xyz%?])%s+([xyz%?])$" )
708
- if found == nil then
709
- worldedit .player_notify (name , " invalid usage: " .. param )
710
- return
711
- end
712
- if axis1 == " ?" then
713
- axis1 = worldedit .player_axis (name )
714
- end
715
- if axis2 == " ?" then
716
- axis2 = worldedit .player_axis (name )
717
- end
718
- if axis1 == axis2 then
719
- worldedit .player_notify (name , " invalid usage: axes must be different" )
720
- return
721
- end
722
-
670
+ if axis1 == " ?" then axis1 = worldedit .player_axis (name ) end
671
+ if axis2 == " ?" then axis2 = worldedit .player_axis (name ) end
723
672
local count , pos1 , pos2 = worldedit .transpose (pos1 , pos2 , axis1 , axis2 )
724
673
725
674
-- reset markers to transposed positions
@@ -729,45 +678,48 @@ minetest.register_chatcommand("/transpose", {
729
678
worldedit .mark_pos2 (name )
730
679
731
680
worldedit .player_notify (name , count .. " nodes transposed" )
681
+ end ,
682
+ function (name , param )
683
+ local found , _ , axis1 , axis2 = param :find (" ^([xyz%?])%s+([xyz%?])$" )
684
+ if found == nil then
685
+ worldedit .player_notify (name , " invalid usage: " .. param )
686
+ return nil
687
+ end
688
+ if axis1 == axis2 then
689
+ worldedit .player_notify (name , " invalid usage: axes must be different" )
690
+ return nil
691
+ end
692
+ return check_region (name , param )
732
693
end ),
733
694
})
734
695
735
696
minetest .register_chatcommand (" /flip" , {
736
697
params = " x/y/z/?" ,
737
698
description = " Flip the current WorldEdit region along the x/y/z/? axis" ,
738
699
privs = {worldedit = true },
739
- func = safe_region (function (name , param , pos1 , pos2 )
740
- if param == " ?" then
741
- param = worldedit .player_axis (name )
742
- end
743
- if param ~= " x" and param ~= " y" and param ~= " z" then
744
- worldedit .player_notify (name , " invalid usage: " .. param )
745
- return
746
- end
747
-
700
+ func = safe_region (function (name , param )
701
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
702
+ if param == " ?" then param = worldedit .player_axis (name ) end
748
703
local count = worldedit .flip (pos1 , pos2 , param )
749
704
worldedit .player_notify (name , count .. " nodes flipped" )
705
+ end ,
706
+ function (name , param )
707
+ if param ~= " x" and param ~= " y" and param ~= " z" and param ~= " ?" then
708
+ worldedit .player_notify (name , " invalid usage: " .. param )
709
+ return nil
710
+ end
711
+ return check_region (name , param )
750
712
end ),
751
713
})
752
714
753
715
minetest .register_chatcommand (" /rotate" , {
754
716
params = " <axis> <angle>" ,
755
717
description = " Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)" ,
756
718
privs = {worldedit = true },
757
- func = safe_region (function (name , param , pos1 , pos2 )
719
+ func = safe_region (function (name , param )
720
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
758
721
local found , _ , axis , angle = param :find (" ^([xyz%?])%s+([+-]?%d+)$" )
759
- if found == nil then
760
- worldedit .player_notify (name , " invalid usage: " .. param )
761
- return
762
- end
763
- if axis == " ?" then
764
- axis = worldedit .player_axis (name )
765
- end
766
- if angle % 90 ~= 0 then
767
- worldedit .player_notify (name , " invalid usage: angle must be multiple of 90" )
768
- return
769
- end
770
-
722
+ if axis == " ?" then axis = worldedit .player_axis (name ) end
771
723
local count , pos1 , pos2 = worldedit .rotate (pos1 , pos2 , axis , angle )
772
724
773
725
-- reset markers to rotated positions
@@ -777,35 +729,51 @@ minetest.register_chatcommand("/rotate", {
777
729
worldedit .mark_pos2 (name )
778
730
779
731
worldedit .player_notify (name , count .. " nodes rotated" )
732
+ end ,
733
+ function (name , param )
734
+ local found , _ , axis , angle = param :find (" ^([xyz%?])%s+([+-]?%d+)$" )
735
+ if found == nil then
736
+ worldedit .player_notify (name , " invalid usage: " .. param )
737
+ return nil
738
+ end
739
+ if angle % 90 ~= 0 then
740
+ worldedit .player_notify (name , " invalid usage: angle must be multiple of 90" )
741
+ return nil
742
+ end
743
+ return check_region (name , param )
780
744
end ),
781
745
})
782
746
783
747
minetest .register_chatcommand (" /orient" , {
784
748
params = " <angle>" ,
785
749
description = " Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)" ,
786
750
privs = {worldedit = true },
787
- func = safe_region (function (name , param , pos1 , pos2 )
751
+ func = safe_region (function (name , param )
752
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
753
+ local found , _ , angle = param :find (" ^([+-]?%d+)$" )
754
+ local count = worldedit .orient (pos1 , pos2 , angle )
755
+ worldedit .player_notify (name , count .. " nodes oriented" )
756
+ end ,
757
+ function (name , param )
788
758
local found , _ , angle = param :find (" ^([+-]?%d+)$" )
789
759
if found == nil then
790
760
worldedit .player_notify (name , " invalid usage: " .. param )
791
- return
761
+ return nil
792
762
end
793
763
if angle % 90 ~= 0 then
794
764
worldedit .player_notify (name , " invalid usage: angle must be multiple of 90" )
795
- return
765
+ return nil
796
766
end
797
-
798
- local count = worldedit .orient (pos1 , pos2 , angle )
799
-
800
- worldedit .player_notify (name , count .. " nodes oriented" )
767
+ return check_region (name , param )
801
768
end ),
802
769
})
803
770
804
771
minetest .register_chatcommand (" /fixlight" , {
805
772
params = " " ,
806
773
description = " Fix the lighting in the current WorldEdit region" ,
807
774
privs = {worldedit = true },
808
- func = safe_region (function (name , param , pos1 , pos2 )
775
+ func = safe_region (function (name , param )
776
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
809
777
local count = worldedit .fixlight (pos1 , pos2 )
810
778
worldedit .player_notify (name , count .. " nodes updated" )
811
779
end ),
@@ -815,7 +783,8 @@ minetest.register_chatcommand("/hide", {
815
783
params = " " ,
816
784
description = " Hide all nodes in the current WorldEdit region non-destructively" ,
817
785
privs = {worldedit = true },
818
- func = safe_region (function (name , param , pos1 , pos2 )
786
+ func = safe_region (function (name , param )
787
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
819
788
local count = worldedit .hide (pos1 , pos2 )
820
789
worldedit .player_notify (name , count .. " nodes hidden" )
821
790
end ),
@@ -825,33 +794,32 @@ minetest.register_chatcommand("/suppress", {
825
794
params = " <node>" ,
826
795
description = " Suppress all <node> in the current WorldEdit region non-destructively" ,
827
796
privs = {worldedit = true },
828
- func = safe_region (function (name , param , pos1 , pos2 )
797
+ func = safe_region (function (name , param )
798
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
829
799
local node = get_node (name , param )
830
- if not node then return end
831
-
832
800
local count = worldedit .suppress (pos1 , pos2 , node )
833
801
worldedit .player_notify (name , count .. " nodes suppressed" )
834
- end ),
802
+ end , check_set ),
835
803
})
836
804
837
805
minetest .register_chatcommand (" /highlight" , {
838
806
params = " <node>" ,
839
807
description = " Highlight <node> in the current WorldEdit region by hiding everything else non-destructively" ,
840
808
privs = {worldedit = true },
841
- func = safe_region (function (name , param , pos1 , pos2 )
809
+ func = safe_region (function (name , param )
810
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
842
811
local node = get_node (name , param )
843
- if not node then return end
844
-
845
812
local count = worldedit .highlight (pos1 , pos2 , node )
846
813
worldedit .player_notify (name , count .. " nodes highlighted" )
847
- end ),
814
+ end , check_set ),
848
815
})
849
816
850
817
minetest .register_chatcommand (" /restore" , {
851
818
params = " " ,
852
819
description = " Restores nodes hidden with WorldEdit in the current WorldEdit region" ,
853
820
privs = {worldedit = true },
854
- func = safe_region (function (name , param , pos1 , pos2 )
821
+ func = safe_region (function (name , param )
822
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
855
823
local count = worldedit .restore (pos1 , pos2 )
856
824
worldedit .player_notify (name , count .. " nodes restored" )
857
825
end ),
@@ -861,7 +829,8 @@ minetest.register_chatcommand("/save", {
861
829
params = " <file>" ,
862
830
description = " Save the current WorldEdit region to \" (world folder)/schems/<file>.we\" " ,
863
831
privs = {worldedit = true },
864
- func = safe_region (function (name , param , pos1 , pos2 )
832
+ func = safe_region (function (name , param )
833
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
865
834
if param == " " then
866
835
worldedit .player_notify (name , " invalid usage: " .. param )
867
836
return
@@ -1002,7 +971,8 @@ minetest.register_chatcommand("/luatransform", {
1002
971
params = " <code>" ,
1003
972
description = " Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region" ,
1004
973
privs = {worldedit = true , server = true },
1005
- func = safe_region (function (name , param , pos1 , pos2 )
974
+ func = safe_region (function (name , param )
975
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
1006
976
local admin = minetest .setting_get (" name" )
1007
977
if not admin or not name == admin then
1008
978
worldedit .player_notify (name , " this command can only be run by the server administrator" )
@@ -1022,7 +992,8 @@ minetest.register_chatcommand("/mtschemcreate", {
1022
992
params = " <file>" ,
1023
993
description = " Save the current WorldEdit region using the Minetest Schematic format to \" (world folder)/schems/<filename>.mts\" " ,
1024
994
privs = {worldedit = true },
1025
- func = safe_region (function (name , param , pos1 , pos2 )
995
+ func = safe_region (function (name , param )
996
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
1026
997
if param == nil then
1027
998
worldedit .player_notify (name , " No filename specified" )
1028
999
return
@@ -1111,7 +1082,8 @@ minetest.register_chatcommand("/clearobjects", {
1111
1082
params = " " ,
1112
1083
description = " Clears all objects within the WorldEdit region" ,
1113
1084
privs = {worldedit = true },
1114
- func = safe_region (function (name , param , pos1 , pos2 )
1085
+ func = safe_region (function (name , param )
1086
+ local pos1 , pos2 = worldedit .pos1 [name ], worldedit .pos2 [name ]
1115
1087
local count = worldedit .clearobjects (pos1 , pos2 )
1116
1088
worldedit .player_notify (name , count .. " objects cleared" )
1117
1089
end ),
0 commit comments