Skip to content

Commit 74018da

Browse files
committedJun 12, 2013
Support descriptions and partial node names in chat commands (e.g., //set blue lightstone, //replace piston_normal_off bronze block).
1 parent f1cfc47 commit 74018da

File tree

3 files changed

+130
-91
lines changed

3 files changed

+130
-91
lines changed
 

‎Chat Commands.md

+43-43
Original file line numberDiff line numberDiff line change
@@ -51,93 +51,93 @@ Display the volume of the current WorldEdit region.
5151

5252
Set the current WorldEdit region to <node>.
5353

54-
//set dirt
55-
//set default:glass
56-
//set mesecons:mesecon
54+
//set cactus
55+
//set Bronze Block
56+
//set mesecons:wire_00000000_off
5757

5858
### //replace <search node> <replace node>
5959

6060
Replace all instances of <search node> with <replace node> in the current WorldEdit region.
6161

62-
//replace cobble stone
63-
//replace default:steelblock glass
64-
//replace dirt flowers:flower_waterlily
65-
//replace flowers:flower_rose flowers:flower_tulip
62+
//replace Cobblestone cactus
63+
//replace lightstone_blue glass
64+
//replace dirt Bronze Block
65+
//replace mesecons:wire_00000000_off flowers:flower_tulip
6666

6767
### //replaceinverse <search node> <replace node>
6868

6969
Replace all nodes other than <search node> with <replace node> in the current WorldEdit region.
7070

71-
//replaceinverse air stone
72-
//replaceinverse water_source default:dirt
73-
//replaceinverse mesecons:mesecon air
74-
//replaceinverse default:steelblock default:glass
71+
//replaceinverse Cobblestone cactus
72+
//replaceinverse flowers:flower_waterlily glass
73+
//replaceinverse dirt Bronze Block
74+
//replaceinverse mesecons:wire_00000000_off flowers:flower_tulip
7575

7676
### //hollowsphere <radius> <node>
7777

7878
Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>.
7979

80-
//hollowsphere 5 dirt
81-
//hollowsphere 12 default:glass
82-
//hollowsphere 17 mesecons:mesecon
80+
//hollowsphere 5 Diamond Block
81+
//hollowsphere 12 glass
82+
//hollowsphere 17 mesecons:wire_00000000_off
8383

8484
### //sphere <radius> <node>
8585

8686
Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>.
8787

88-
//sphere 5 dirt
89-
//sphere 12 default:glass
90-
//sphere 17 mesecons:mesecon
88+
//sphere 5 Diamond Block
89+
//sphere 12 glass
90+
//sphere 17 mesecons:wire_00000000_off
9191

9292
### //hollowdome <radius> <node>
9393

9494
Add hollow dome at WorldEdit position 1 with radius <radius>, composed of <node>.
9595

96-
//hollowdome 5 dirt
97-
//hollowdome 12 default:glass
98-
//hollowdome 17 mesecons:mesecon
96+
//hollowdome 5 Diamond Block
97+
//hollowdome 12 glass
98+
//hollowdome 17 mesecons:wire_00000000_off
9999

100100
### //dome <radius> <node>
101101

102102
Add dome at WorldEdit position 1 with radius <radius>, composed of <node>.
103103

104-
//dome 5 dirt
105-
//dome 12 default:glass
106-
//dome 17 mesecons:mesecon
104+
//dome 5 Diamond Block
105+
//dome 12 glass
106+
//dome 17 mesecons:wire_00000000_off
107107

108108
### //hollowcylinder x/y/z/? <length> <radius> <node>
109109

110110
Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>.
111111

112-
//hollowcylinder x +5 8 dirt
113-
//hollowcylinder y 28 10 default:glass
114-
//hollowcylinder z -12 3 mesecons:mesecon
115-
//hollowcylinder ? 2 4 stone
112+
//hollowcylinder x +5 8 Bronze Block
113+
//hollowcylinder y 28 10 glass
114+
//hollowcylinder z -12 3 mesecons:wire_00000000_off
115+
//hollowcylinder ? 2 4 default:stone
116116

117117
### //cylinder x/y/z/? <length> <radius> <node>
118118

119119
Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>.
120120

121-
//cylinder x +5 8 dirt
122-
//cylinder y 28 10 default:glass
123-
//cylinder z -12 3 mesecons:mesecon
124-
//cylinder ? 2 4 stone
121+
//cylinder x +5 8 Bronze Block
122+
//cylinder y 28 10 glass
123+
//cylinder z -12 3 mesecons:wire_00000000_off
124+
//cylinder ? 2 4 default:stone
125125

126126
### //pyramid <height> <node>
127127

128128
Add pyramid at WorldEdit position 1 with height <height>, composed of <node>.
129129

130-
//pyramid 8 dirt
131-
//pyramid 5 default:glass
132-
//pyramid 2 stone
130+
//pyramid 8 Diamond Block
131+
//pyramid 5 glass
132+
//pyramid 2 mesecons:wire_00000000_off
133133

134134
### //spiral <width> <height> <spacer> <node>
135135

136136
Add spiral at WorldEdit position 1 with width <width>, height <height>, space between walls <spacer>, composed of <node>.
137137

138-
//spiral 20 5 3 dirt
139-
//spiral 5 2 1 default:glass
140-
//spiral 7 1 5 stone
138+
//spiral 20 5 3 Diamond Block
139+
//spiral 5 2 1 glass
140+
//spiral 7 1 5 mesecons:wire_00000000_off
141141

142142
### //copy x/y/z/? <amount>
143143

@@ -218,17 +218,17 @@ Hide all nodes in the current WorldEdit region non-destructively.
218218

219219
Suppress all <node> in the current WorldEdit region non-destructively.
220220

221-
//suppress dirt
222-
//suppress default:glass
223-
//suppress mesecons:mesecon
221+
//suppress Diamond Block
222+
//suppress glass
223+
//suppress mesecons:wire_00000000_off
224224

225225
### //highlight <node>
226226

227227
Highlight <node> in the current WorldEdit region by hiding everything else non-destructively.
228228

229-
//highlight dirt
230-
//highlight default:glass
231-
//highlight mesecons:mesecon
229+
//highlight Diamond Block
230+
//highlight glass
231+
//highlight mesecons:wire_00000000_off
232232

233233
### //restore
234234

‎README.md

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ When an axis is specified in a WorldEdit command, it is specified as one of the
2020

2121
The value ? represents the axis the player is currently facing. If the player is facing more than one axis, the axis the player face direction is closest to will be used.
2222

23+
Nodes
24+
-----
25+
Node names are required for many types of commands that identify or modify specific types of nodes. They can be specified in a number of ways.
26+
27+
First, by description - the tooltip that appears when hovering over the item in an inventory. This is case insensitive and includes values such as "Cobblestone" and "bronze block". Note that certain commands (namely, `//replace` and `//replaceinverse`) do not support descriptions that contain spaces in the `<searchnode>` field.
28+
29+
Second, by name - the node name that is defined by code, but without the mod name prefix. This is case sensitive and includes values such as "piston_normal_off" and "cactus". Nodes defined in the `default` mod always take precedence over other nodes when searching for the correct one, and if there are multiple possible nodes (such as "a:celery" and "b:celery"), one is chosen in no particular order.
30+
31+
Finally, by full name - the unambiguous identifier of the node, prefixes and all. This is case sensitive and includes values such as "default:stone" and "mesecons:wire_00000000_off".
32+
2333
Regions
2434
-------
2535
Most WorldEdit commands operate on regions. Regions are a set of two positions that define a 3D cube. They are local to each player and chat commands affect only the region for the player giving the commands.

‎worldedit_commands/init.lua

+77-48
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,23 @@ worldedit.player_notify = function(name, message)
1212
end
1313

1414
--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
1832
end
1933

2034
--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", {
178192
return
179193
end
180194

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
182197
worldedit.player_notify(name, "invalid node name: " .. param)
183198
return
184199
end
@@ -188,7 +203,7 @@ minetest.register_chatcommand("/set", {
188203
tenv = worldedit.queue_aliasenv
189204
end
190205

191-
local count = worldedit.set(pos1, pos2, param, tenv)
206+
local count = worldedit.set(pos1, pos2, node, tenv)
192207
worldedit.player_notify(name, count .. " nodes set")
193208
end,
194209
})
@@ -204,16 +219,18 @@ minetest.register_chatcommand("/replace", {
204219
return
205220
end
206221

207-
local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")
222+
local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
208223
if found == nil then
209224
worldedit.player_notify(name, "invalid usage: " .. param)
210225
return
211226
end
212-
if not worldedit.node_is_valid(searchnode) then
227+
local newsearchnode = worldedit.normalize_nodename(searchnode)
228+
if not newsearchnode then
213229
worldedit.player_notify(name, "invalid search node name: " .. searchnode)
214230
return
215231
end
216-
if not worldedit.node_is_valid(replacenode) then
232+
local newreplacenode = worldedit.normalize_nodename(replacenode)
233+
if not newreplacenode then
217234
worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
218235
return
219236
end
@@ -222,7 +239,7 @@ minetest.register_chatcommand("/replace", {
222239
if worldedit.ENABLE_QUEUE then
223240
tenv = worldedit.queue_aliasenv
224241
end
225-
local count = worldedit.replace(pos1, pos2, searchnode, replacenode, tenv)
242+
local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode, tenv)
226243
worldedit.player_notify(name, count .. " nodes replaced")
227244
end,
228245
})
@@ -238,16 +255,18 @@ minetest.register_chatcommand("/replaceinverse", {
238255
return
239256
end
240257

241-
local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")
258+
local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
242259
if found == nil then
243260
worldedit.player_notify(name, "invalid usage: " .. param)
244261
return
245262
end
246-
if not worldedit.node_is_valid(searchnode) then
263+
local newsearchnode = worldedit.normalize_nodename(searchnode)
264+
if not newsearchnode then
247265
worldedit.player_notify(name, "invalid search node name: " .. searchnode)
248266
return
249267
end
250-
if not worldedit.node_is_valid(replacenode) then
268+
local newreplacenode = worldedit.normalize_nodename(replacenode)
269+
if not newreplacenode then
251270
worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
252271
return
253272
end
@@ -272,21 +291,22 @@ minetest.register_chatcommand("/hollowsphere", {
272291
return
273292
end
274293

275-
local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
294+
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
276295
if found == nil then
277296
worldedit.player_notify(name, "invalid usage: " .. param)
278297
return
279298
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)
282302
return
283303
end
284304

285305
local tenv = minetest.env
286306
if worldedit.ENABLE_QUEUE then
287307
tenv = worldedit.queue_aliasenv
288308
end
289-
local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename, tenv)
309+
local count = worldedit.hollow_sphere(pos, tonumber(radius), node, tenv)
290310
worldedit.player_notify(name, count .. " nodes added")
291311
end,
292312
})
@@ -302,21 +322,22 @@ minetest.register_chatcommand("/sphere", {
302322
return
303323
end
304324

305-
local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
325+
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
306326
if found == nil then
307327
worldedit.player_notify(name, "invalid usage: " .. param)
308328
return
309329
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)
312333
return
313334
end
314335

315336
local tenv = minetest.env
316337
if worldedit.ENABLE_QUEUE then
317338
tenv = worldedit.queue_aliasenv
318339
end
319-
local count = worldedit.sphere(pos, tonumber(radius), nodename, tenv)
340+
local count = worldedit.sphere(pos, tonumber(radius), node, tenv)
320341
worldedit.player_notify(name, count .. " nodes added")
321342
end,
322343
})
@@ -332,21 +353,22 @@ minetest.register_chatcommand("/hollowdome", {
332353
return
333354
end
334355

335-
local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
356+
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
336357
if found == nil then
337358
worldedit.player_notify(name, "invalid usage: " .. param)
338359
return
339360
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)
342364
return
343365
end
344366

345367
local tenv = minetest.env
346368
if worldedit.ENABLE_QUEUE then
347369
tenv = worldedit.queue_aliasenv
348370
end
349-
local count = worldedit.hollow_dome(pos, tonumber(radius), nodename, tenv)
371+
local count = worldedit.hollow_dome(pos, tonumber(radius), node, tenv)
350372
worldedit.player_notify(name, count .. " nodes added")
351373
end,
352374
})
@@ -362,21 +384,22 @@ minetest.register_chatcommand("/dome", {
362384
return
363385
end
364386

365-
local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
387+
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
366388
if found == nil then
367389
worldedit.player_notify(name, "invalid usage: " .. param)
368390
return
369391
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)
372395
return
373396
end
374397

375398
local tenv = minetest.env
376399
if worldedit.ENABLE_QUEUE then
377400
tenv = worldedit.queue_aliasenv
378401
end
379-
local count = worldedit.dome(pos, tonumber(radius), nodename, tenv)
402+
local count = worldedit.dome(pos, tonumber(radius), node, tenv)
380403
worldedit.player_notify(name, count .. " nodes added")
381404
end,
382405
})
@@ -392,7 +415,7 @@ minetest.register_chatcommand("/hollowcylinder", {
392415
return
393416
end
394417

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+(.+)$")
396419
if found == nil then
397420
worldedit.player_notify(name, "invalid usage: " .. param)
398421
return
@@ -401,16 +424,17 @@ minetest.register_chatcommand("/hollowcylinder", {
401424
axis, sign = worldedit.player_axis(name)
402425
length = length * sign
403426
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)
406430
return
407431
end
408432

409433
local tenv = minetest.env
410434
if worldedit.ENABLE_QUEUE then
411435
tenv = worldedit.queue_aliasenv
412436
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)
414438
worldedit.player_notify(name, count .. " nodes added")
415439
end,
416440
})
@@ -426,7 +450,7 @@ minetest.register_chatcommand("/cylinder", {
426450
return
427451
end
428452

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+(.+)$")
430454
if found == nil then
431455
worldedit.player_notify(name, "invalid usage: " .. param)
432456
return
@@ -435,16 +459,17 @@ minetest.register_chatcommand("/cylinder", {
435459
axis, sign = worldedit.player_axis(name)
436460
length = length * sign
437461
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)
440465
return
441466
end
442467

443468
local tenv = minetest.env
444469
if worldedit.ENABLE_QUEUE then
445470
tenv = worldedit.queue_aliasenv
446471
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)
448473
worldedit.player_notify(name, count .. " nodes added")
449474
end,
450475
})
@@ -460,21 +485,22 @@ minetest.register_chatcommand("/pyramid", {
460485
return
461486
end
462487

463-
local found, _, size, nodename = param:find("(%d+)%s+([^%s]+)$")
488+
local found, _, size, nodename = param:find("(%d+)%s+(.+)$")
464489
if found == nil then
465490
worldedit.player_notify(name, "invalid usage: " .. param)
466491
return
467492
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)
470496
return
471497
end
472498

473499
local tenv = minetest.env
474500
if worldedit.ENABLE_QUEUE then
475501
tenv = worldedit.queue_aliasenv
476502
end
477-
local count = worldedit.pyramid(pos, tonumber(size), nodename, tenv)
503+
local count = worldedit.pyramid(pos, tonumber(size), node, tenv)
478504
worldedit.player_notify(name, count .. " nodes added")
479505
end,
480506
})
@@ -490,21 +516,22 @@ minetest.register_chatcommand("/spiral", {
490516
return
491517
end
492518

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+(.+)$")
494520
if found == nil then
495521
worldedit.player_notify(name, "invalid usage: " .. param)
496522
return
497523
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)
500527
return
501528
end
502529

503530
local tenv = minetest.env
504531
if worldedit.ENABLE_QUEUE then
505532
tenv = worldedit.queue_aliasenv
506533
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)
508535
worldedit.player_notify(name, count .. " nodes added")
509536
end,
510537
})
@@ -793,7 +820,8 @@ minetest.register_chatcommand("/suppress", {
793820
return
794821
end
795822

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
797825
worldedit.player_notify(name, "invalid node name: " .. param)
798826
return
799827
end
@@ -802,7 +830,7 @@ minetest.register_chatcommand("/suppress", {
802830
if worldedit.ENABLE_QUEUE then
803831
tenv = worldedit.queue_aliasenv
804832
end
805-
local count = worldedit.suppress(pos1, pos2, param, tenv)
833+
local count = worldedit.suppress(pos1, pos2, node, tenv)
806834
worldedit.player_notify(name, count .. " nodes suppressed")
807835
end,
808836
})
@@ -818,7 +846,8 @@ minetest.register_chatcommand("/highlight", {
818846
return
819847
end
820848

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
822851
worldedit.player_notify(name, "invalid node name: " .. param)
823852
return
824853
end
@@ -827,7 +856,7 @@ minetest.register_chatcommand("/highlight", {
827856
if worldedit.ENABLE_QUEUE then
828857
tenv = worldedit.queue_aliasenv
829858
end
830-
local count = worldedit.highlight(pos1, pos2, param, tenv)
859+
local count = worldedit.highlight(pos1, pos2, node, tenv)
831860
worldedit.player_notify(name, count .. " nodes highlighted")
832861
end,
833862
})

0 commit comments

Comments
 (0)
Please sign in to comment.