@@ -12,9 +12,23 @@ worldedit.player_notify = function(name, message)
12
12
end
13
13
14
14
-- determines whether `nodename` is a valid node name, returning a boolean
15
- worldedit .node_is_valid = function (nodename )
16
- return minetest .registered_nodes [nodename ] ~= nil
17
- or minetest .registered_nodes [" default:" .. nodename ] ~= nil
15
+ worldedit .normalize_nodename = function (nodename )
16
+ if minetest .registered_nodes [nodename ] then -- directly found node name
17
+ return nodename
18
+ elseif minetest .registered_nodes [" default:" .. nodename ] then -- found node name in default
19
+ return " default:" .. nodename
20
+ end
21
+ for key , value in pairs (minetest .registered_nodes ) do
22
+ if key :find (" :" .. nodename , 1 , true ) then -- found in mod
23
+ return key
24
+ end
25
+ end
26
+ for key , value in pairs (minetest .registered_nodes ) do
27
+ if value .description :lower () == nodename :lower () then -- found in description
28
+ return key
29
+ end
30
+ end
31
+ return nil
18
32
end
19
33
20
34
-- determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
@@ -178,7 +192,8 @@ minetest.register_chatcommand("/set", {
178
192
return
179
193
end
180
194
181
- if param == " " or not worldedit .node_is_valid (param ) then
195
+ local node = worldedit .normalize_nodename (param )
196
+ if param == " " or not node then
182
197
worldedit .player_notify (name , " invalid node name: " .. param )
183
198
return
184
199
end
@@ -188,7 +203,7 @@ minetest.register_chatcommand("/set", {
188
203
tenv = worldedit .queue_aliasenv
189
204
end
190
205
191
- local count = worldedit .set (pos1 , pos2 , param , tenv )
206
+ local count = worldedit .set (pos1 , pos2 , node , tenv )
192
207
worldedit .player_notify (name , count .. " nodes set" )
193
208
end ,
194
209
})
@@ -204,16 +219,18 @@ minetest.register_chatcommand("/replace", {
204
219
return
205
220
end
206
221
207
- local found , _ , searchnode , replacenode = param :find (" ^([^%s]+)%s+([^%s] +)$" )
222
+ local found , _ , searchnode , replacenode = param :find (" ^([^%s]+)%s+(. +)$" )
208
223
if found == nil then
209
224
worldedit .player_notify (name , " invalid usage: " .. param )
210
225
return
211
226
end
212
- if not worldedit .node_is_valid (searchnode ) then
227
+ local newsearchnode = worldedit .normalize_nodename (searchnode )
228
+ if not newsearchnode then
213
229
worldedit .player_notify (name , " invalid search node name: " .. searchnode )
214
230
return
215
231
end
216
- if not worldedit .node_is_valid (replacenode ) then
232
+ local newreplacenode = worldedit .normalize_nodename (replacenode )
233
+ if not newreplacenode then
217
234
worldedit .player_notify (name , " invalid replace node name: " .. replacenode )
218
235
return
219
236
end
@@ -222,7 +239,7 @@ minetest.register_chatcommand("/replace", {
222
239
if worldedit .ENABLE_QUEUE then
223
240
tenv = worldedit .queue_aliasenv
224
241
end
225
- local count = worldedit .replace (pos1 , pos2 , searchnode , replacenode , tenv )
242
+ local count = worldedit .replace (pos1 , pos2 , newsearchnode , newreplacenode , tenv )
226
243
worldedit .player_notify (name , count .. " nodes replaced" )
227
244
end ,
228
245
})
@@ -238,16 +255,18 @@ minetest.register_chatcommand("/replaceinverse", {
238
255
return
239
256
end
240
257
241
- local found , _ , searchnode , replacenode = param :find (" ^([^%s]+)%s+([^%s] +)$" )
258
+ local found , _ , searchnode , replacenode = param :find (" ^([^%s]+)%s+(. +)$" )
242
259
if found == nil then
243
260
worldedit .player_notify (name , " invalid usage: " .. param )
244
261
return
245
262
end
246
- if not worldedit .node_is_valid (searchnode ) then
263
+ local newsearchnode = worldedit .normalize_nodename (searchnode )
264
+ if not newsearchnode then
247
265
worldedit .player_notify (name , " invalid search node name: " .. searchnode )
248
266
return
249
267
end
250
- if not worldedit .node_is_valid (replacenode ) then
268
+ local newreplacenode = worldedit .normalize_nodename (replacenode )
269
+ if not newreplacenode then
251
270
worldedit .player_notify (name , " invalid replace node name: " .. replacenode )
252
271
return
253
272
end
@@ -272,21 +291,22 @@ minetest.register_chatcommand("/hollowsphere", {
272
291
return
273
292
end
274
293
275
- local found , _ , radius , nodename = param :find (" ^(%d+)%s+([^%s] +)$" )
294
+ local found , _ , radius , nodename = param :find (" ^(%d+)%s+(. +)$" )
276
295
if found == nil then
277
296
worldedit .player_notify (name , " invalid usage: " .. param )
278
297
return
279
298
end
280
- if not worldedit .node_is_valid (nodename ) then
281
- worldedit .player_notify (name , " invalid node name: " .. param )
299
+ local node = worldedit .normalize_nodename (nodename )
300
+ if not node then
301
+ worldedit .player_notify (name , " invalid node name: " .. nodename )
282
302
return
283
303
end
284
304
285
305
local tenv = minetest .env
286
306
if worldedit .ENABLE_QUEUE then
287
307
tenv = worldedit .queue_aliasenv
288
308
end
289
- local count = worldedit .hollow_sphere (pos , tonumber (radius ), nodename , tenv )
309
+ local count = worldedit .hollow_sphere (pos , tonumber (radius ), node , tenv )
290
310
worldedit .player_notify (name , count .. " nodes added" )
291
311
end ,
292
312
})
@@ -302,21 +322,22 @@ minetest.register_chatcommand("/sphere", {
302
322
return
303
323
end
304
324
305
- local found , _ , radius , nodename = param :find (" ^(%d+)%s+([^%s] +)$" )
325
+ local found , _ , radius , nodename = param :find (" ^(%d+)%s+(. +)$" )
306
326
if found == nil then
307
327
worldedit .player_notify (name , " invalid usage: " .. param )
308
328
return
309
329
end
310
- if not worldedit .node_is_valid (nodename ) then
311
- worldedit .player_notify (name , " invalid node name: " .. param )
330
+ local node = worldedit .normalize_nodename (nodename )
331
+ if not node then
332
+ worldedit .player_notify (name , " invalid node name: " .. nodename )
312
333
return
313
334
end
314
335
315
336
local tenv = minetest .env
316
337
if worldedit .ENABLE_QUEUE then
317
338
tenv = worldedit .queue_aliasenv
318
339
end
319
- local count = worldedit .sphere (pos , tonumber (radius ), nodename , tenv )
340
+ local count = worldedit .sphere (pos , tonumber (radius ), node , tenv )
320
341
worldedit .player_notify (name , count .. " nodes added" )
321
342
end ,
322
343
})
@@ -332,21 +353,22 @@ minetest.register_chatcommand("/hollowdome", {
332
353
return
333
354
end
334
355
335
- local found , _ , radius , nodename = param :find (" ^(%d+)%s+([^%s] +)$" )
356
+ local found , _ , radius , nodename = param :find (" ^(%d+)%s+(. +)$" )
336
357
if found == nil then
337
358
worldedit .player_notify (name , " invalid usage: " .. param )
338
359
return
339
360
end
340
- if not worldedit .node_is_valid (nodename ) then
341
- worldedit .player_notify (name , " invalid node name: " .. param )
361
+ local node = worldedit .normalize_nodename (nodename )
362
+ if not node then
363
+ worldedit .player_notify (name , " invalid node name: " .. nodename )
342
364
return
343
365
end
344
366
345
367
local tenv = minetest .env
346
368
if worldedit .ENABLE_QUEUE then
347
369
tenv = worldedit .queue_aliasenv
348
370
end
349
- local count = worldedit .hollow_dome (pos , tonumber (radius ), nodename , tenv )
371
+ local count = worldedit .hollow_dome (pos , tonumber (radius ), node , tenv )
350
372
worldedit .player_notify (name , count .. " nodes added" )
351
373
end ,
352
374
})
@@ -362,21 +384,22 @@ minetest.register_chatcommand("/dome", {
362
384
return
363
385
end
364
386
365
- local found , _ , radius , nodename = param :find (" ^(%d+)%s+([^%s] +)$" )
387
+ local found , _ , radius , nodename = param :find (" ^(%d+)%s+(. +)$" )
366
388
if found == nil then
367
389
worldedit .player_notify (name , " invalid usage: " .. param )
368
390
return
369
391
end
370
- if not worldedit .node_is_valid (nodename ) then
371
- worldedit .player_notify (name , " invalid node name: " .. param )
392
+ local node = worldedit .normalize_nodename (nodename )
393
+ if not node then
394
+ worldedit .player_notify (name , " invalid node name: " .. nodename )
372
395
return
373
396
end
374
397
375
398
local tenv = minetest .env
376
399
if worldedit .ENABLE_QUEUE then
377
400
tenv = worldedit .queue_aliasenv
378
401
end
379
- local count = worldedit .dome (pos , tonumber (radius ), nodename , tenv )
402
+ local count = worldedit .dome (pos , tonumber (radius ), node , tenv )
380
403
worldedit .player_notify (name , count .. " nodes added" )
381
404
end ,
382
405
})
@@ -392,7 +415,7 @@ minetest.register_chatcommand("/hollowcylinder", {
392
415
return
393
416
end
394
417
395
- local found , _ , axis , length , radius , nodename = param :find (" ^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s] +)$" )
418
+ local found , _ , axis , length , radius , nodename = param :find (" ^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(. +)$" )
396
419
if found == nil then
397
420
worldedit .player_notify (name , " invalid usage: " .. param )
398
421
return
@@ -401,16 +424,17 @@ minetest.register_chatcommand("/hollowcylinder", {
401
424
axis , sign = worldedit .player_axis (name )
402
425
length = length * sign
403
426
end
404
- if not worldedit .node_is_valid (nodename ) then
405
- worldedit .player_notify (name , " invalid node name: " .. param )
427
+ local node = worldedit .normalize_nodename (nodename )
428
+ if not node then
429
+ worldedit .player_notify (name , " invalid node name: " .. nodename )
406
430
return
407
431
end
408
432
409
433
local tenv = minetest .env
410
434
if worldedit .ENABLE_QUEUE then
411
435
tenv = worldedit .queue_aliasenv
412
436
end
413
- local count = worldedit .hollow_cylinder (pos , axis , tonumber (length ), tonumber (radius ), nodename , tenv )
437
+ local count = worldedit .hollow_cylinder (pos , axis , tonumber (length ), tonumber (radius ), node , tenv )
414
438
worldedit .player_notify (name , count .. " nodes added" )
415
439
end ,
416
440
})
@@ -426,7 +450,7 @@ minetest.register_chatcommand("/cylinder", {
426
450
return
427
451
end
428
452
429
- local found , _ , axis , length , radius , nodename = param :find (" ^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s] +)$" )
453
+ local found , _ , axis , length , radius , nodename = param :find (" ^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(. +)$" )
430
454
if found == nil then
431
455
worldedit .player_notify (name , " invalid usage: " .. param )
432
456
return
@@ -435,16 +459,17 @@ minetest.register_chatcommand("/cylinder", {
435
459
axis , sign = worldedit .player_axis (name )
436
460
length = length * sign
437
461
end
438
- if not worldedit .node_is_valid (nodename ) then
439
- worldedit .player_notify (name , " invalid node name: " .. param )
462
+ local node = worldedit .normalize_nodename (nodename )
463
+ if not node then
464
+ worldedit .player_notify (name , " invalid node name: " .. nodename )
440
465
return
441
466
end
442
467
443
468
local tenv = minetest .env
444
469
if worldedit .ENABLE_QUEUE then
445
470
tenv = worldedit .queue_aliasenv
446
471
end
447
- local count = worldedit .cylinder (pos , axis , tonumber (length ), tonumber (radius ), nodename , tenv )
472
+ local count = worldedit .cylinder (pos , axis , tonumber (length ), tonumber (radius ), node , tenv )
448
473
worldedit .player_notify (name , count .. " nodes added" )
449
474
end ,
450
475
})
@@ -460,21 +485,22 @@ minetest.register_chatcommand("/pyramid", {
460
485
return
461
486
end
462
487
463
- local found , _ , size , nodename = param :find (" (%d+)%s+([^%s] +)$" )
488
+ local found , _ , size , nodename = param :find (" (%d+)%s+(. +)$" )
464
489
if found == nil then
465
490
worldedit .player_notify (name , " invalid usage: " .. param )
466
491
return
467
492
end
468
- if not worldedit .node_is_valid (nodename ) then
469
- worldedit .player_notify (name , " invalid node name: " .. param )
493
+ local node = worldedit .normalize_nodename (nodename )
494
+ if not node then
495
+ worldedit .player_notify (name , " invalid node name: " .. nodename )
470
496
return
471
497
end
472
498
473
499
local tenv = minetest .env
474
500
if worldedit .ENABLE_QUEUE then
475
501
tenv = worldedit .queue_aliasenv
476
502
end
477
- local count = worldedit .pyramid (pos , tonumber (size ), nodename , tenv )
503
+ local count = worldedit .pyramid (pos , tonumber (size ), node , tenv )
478
504
worldedit .player_notify (name , count .. " nodes added" )
479
505
end ,
480
506
})
@@ -490,21 +516,22 @@ minetest.register_chatcommand("/spiral", {
490
516
return
491
517
end
492
518
493
- local found , _ , width , height , space , nodename = param :find (" (%d+)%s+(%d+)%s+(%d+)%s+([^%s] +)$" )
519
+ local found , _ , width , height , space , nodename = param :find (" (%d+)%s+(%d+)%s+(%d+)%s+(. +)$" )
494
520
if found == nil then
495
521
worldedit .player_notify (name , " invalid usage: " .. param )
496
522
return
497
523
end
498
- if not worldedit .node_is_valid (nodename ) then
499
- worldedit .player_notify (name , " invalid node name: " .. param )
524
+ local node = worldedit .normalize_nodename (nodename )
525
+ if not node then
526
+ worldedit .player_notify (name , " invalid node name: " .. nodename )
500
527
return
501
528
end
502
529
503
530
local tenv = minetest .env
504
531
if worldedit .ENABLE_QUEUE then
505
532
tenv = worldedit .queue_aliasenv
506
533
end
507
- local count = worldedit .spiral (pos , tonumber (width ), tonumber (height ), tonumber (space ), nodename , tenv )
534
+ local count = worldedit .spiral (pos , tonumber (width ), tonumber (height ), tonumber (space ), node , tenv )
508
535
worldedit .player_notify (name , count .. " nodes added" )
509
536
end ,
510
537
})
@@ -793,7 +820,8 @@ minetest.register_chatcommand("/suppress", {
793
820
return
794
821
end
795
822
796
- if param == " " or not worldedit .node_is_valid (param ) then
823
+ local node = worldedit .node_is_valid (param )
824
+ if param == " " or not node then
797
825
worldedit .player_notify (name , " invalid node name: " .. param )
798
826
return
799
827
end
@@ -802,7 +830,7 @@ minetest.register_chatcommand("/suppress", {
802
830
if worldedit .ENABLE_QUEUE then
803
831
tenv = worldedit .queue_aliasenv
804
832
end
805
- local count = worldedit .suppress (pos1 , pos2 , param , tenv )
833
+ local count = worldedit .suppress (pos1 , pos2 , node , tenv )
806
834
worldedit .player_notify (name , count .. " nodes suppressed" )
807
835
end ,
808
836
})
@@ -818,7 +846,8 @@ minetest.register_chatcommand("/highlight", {
818
846
return
819
847
end
820
848
821
- if param == " " or not worldedit .node_is_valid (param ) then
849
+ local node = worldedit .node_is_valid (param )
850
+ if param == " " or not node then
822
851
worldedit .player_notify (name , " invalid node name: " .. param )
823
852
return
824
853
end
@@ -827,7 +856,7 @@ minetest.register_chatcommand("/highlight", {
827
856
if worldedit .ENABLE_QUEUE then
828
857
tenv = worldedit .queue_aliasenv
829
858
end
830
- local count = worldedit .highlight (pos1 , pos2 , param , tenv )
859
+ local count = worldedit .highlight (pos1 , pos2 , node , tenv )
831
860
worldedit .player_notify (name , count .. " nodes highlighted" )
832
861
end ,
833
862
})
0 commit comments