]> git.lizzy.rs Git - worldedit.git/blob - worldedit_commands/init.lua
Add //about.
[worldedit.git] / worldedit_commands / init.lua
1 minetest.register_privilege("worldedit", "Can use WorldEdit commands")\r
2 \r
3 worldedit.set_pos = {}\r
4 worldedit.inspect = {}\r
5 \r
6 worldedit.pos1 = {}\r
7 worldedit.pos2 = {}\r
8 if minetest.place_schematic then\r
9         worldedit.prob_pos = {}\r
10         worldedit.prob_list = {}\r
11 end\r
12 \r
13 dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")\r
14 \r
15 worldedit.player_notify = function(name, message)\r
16         minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)\r
17 end\r
18 \r
19 --determines whether `nodename` is a valid node name, returning a boolean\r
20 worldedit.normalize_nodename = function(nodename)\r
21         local fullname = ItemStack({name=nodename}):get_name() --resolve aliases of node names to full names\r
22         if minetest.registered_nodes[fullname] then --directly found node name or alias of nodename\r
23                 return fullname\r
24         end\r
25         for key, value in pairs(minetest.registered_nodes) do\r
26                 if key:find(":" .. nodename, 1, true) then --found in mod\r
27                         return key\r
28                 end\r
29         end\r
30         nodename = nodename:lower() --lowercase both for case insensitive comparison\r
31         for key, value in pairs(minetest.registered_nodes) do\r
32                 if value.description:lower() == nodename then --found in description\r
33                         return key\r
34                 end\r
35         end\r
36         return nil\r
37 end\r
38 \r
39 --determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)\r
40 worldedit.player_axis = function(name)\r
41         local dir = minetest.get_player_by_name(name):get_look_dir()\r
42         local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)\r
43         if x > y then\r
44                 if x > z then\r
45                         return "x", dir.x > 0 and 1 or -1\r
46                 end\r
47         elseif y > z then\r
48                 return "y", dir.y > 0 and 1 or -1\r
49         end\r
50         return "z", dir.z > 0 and 1 or -1\r
51 end\r
52 \r
53 minetest.register_chatcommand("/about", {\r
54         params = "",\r
55         description = "Get information about the mod",\r
56         func = function(name, param)\r
57                 worldedit.player_notify(name, "WorldEdit 1.0 is available on this server. Type /help to get a list of commands, or get more information at https://github.com/Uberi/MineTest-WorldEdit/")\r
58         end,\r
59 })\r
60 \r
61 minetest.register_chatcommand("/inspect", {\r
62         params = "on/off/1/0/true/false/yes/no/enable/disable",\r
63         description = "Enable or disable node inspection",\r
64         privs = {worldedit=true},\r
65         func = function(name, param)\r
66                 if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" then\r
67                         worldedit.inspect[name] = true\r
68                         worldedit.player_notify(name, "node inspection enabled")\r
69                 elseif param == "off" or param == "0" or param == "false" or param == "no" or param == "disable" then\r
70                         worldedit.inspect[name] = nil\r
71                         worldedit.player_notify(name, "node inspection disabled")\r
72                 else\r
73                         worldedit.player_notify(name, "invalid usage: " .. param)\r
74                 end\r
75         end,\r
76 })\r
77 \r
78 minetest.register_on_punchnode(function(pos, node, puncher)\r
79         local name = puncher:get_player_name()\r
80         if worldedit.inspect[name] then\r
81                 if minetest.check_player_privs(name, {worldedit=true}) then\r
82                         message = "inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"\r
83                 else\r
84                         message = "inspector: worldedit privileges required"\r
85                 end\r
86                 worldedit.player_notify(name, message)\r
87         end\r
88 end)\r
89 \r
90 minetest.register_chatcommand("/reset", {\r
91         params = "",\r
92         description = "Reset the region so that it is empty",\r
93         privs = {worldedit=true},\r
94         func = function(name, param)\r
95                 worldedit.pos1[name] = nil\r
96                 worldedit.pos2[name] = nil\r
97                 worldedit.mark_pos1(name)\r
98                 worldedit.mark_pos2(name)\r
99                 worldedit.set_pos[name] = nil\r
100                 worldedit.player_notify(name, "region reset")\r
101         end,\r
102 })\r
103 \r
104 minetest.register_chatcommand("/mark", {\r
105         params = "",\r
106         description = "Show markers at the region positions",\r
107         privs = {worldedit=true},\r
108         func = function(name, param)\r
109                 worldedit.mark_pos1(name)\r
110                 worldedit.mark_pos2(name)\r
111                 worldedit.player_notify(name, "region marked")\r
112         end,\r
113 })\r
114 \r
115 minetest.register_chatcommand("/unmark", {\r
116         params = "",\r
117         description = "Hide markers if currently shown",\r
118         privs = {worldedit=true},\r
119         func = function(name, param)\r
120                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
121                 worldedit.pos1[name] = nil\r
122                 worldedit.pos2[name] = nil\r
123                 worldedit.mark_pos1(name)\r
124                 worldedit.mark_pos2(name)\r
125                 worldedit.pos1[name] = pos1\r
126                 worldedit.pos2[name] = pos2\r
127                 worldedit.player_notify(name, "region unmarked")\r
128         end,\r
129 })\r
130 \r
131 minetest.register_chatcommand("/pos1", {\r
132         params = "",\r
133         description = "Set WorldEdit region position 1 to the player's location",\r
134         privs = {worldedit=true},\r
135         func = function(name, param)\r
136                 local pos = minetest.get_player_by_name(name):getpos()\r
137                 pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)\r
138                 worldedit.pos1[name] = pos\r
139                 worldedit.mark_pos1(name)\r
140                 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))\r
141         end,\r
142 })\r
143 \r
144 minetest.register_chatcommand("/pos2", {\r
145         params = "",\r
146         description = "Set WorldEdit region position 2 to the player's location",\r
147         privs = {worldedit=true},\r
148         func = function(name, param)\r
149                 local pos = minetest.get_player_by_name(name):getpos()\r
150                 pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)\r
151                 worldedit.pos2[name] = pos\r
152                 worldedit.mark_pos2(name)\r
153                 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))\r
154         end,\r
155 })\r
156 \r
157 minetest.register_chatcommand("/p", {\r
158         params = "set/set1/set2/get",\r
159         description = "Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region",\r
160         privs = {worldedit=true},\r
161         func = function(name, param)\r
162                 if param == "set" then --set both WorldEdit positions\r
163                         worldedit.set_pos[name] = "pos1"\r
164                         worldedit.player_notify(name, "select positions by punching two nodes")\r
165                 elseif param == "set1" then --set WorldEdit position 1\r
166                         worldedit.set_pos[name] = "pos1only"\r
167                         worldedit.player_notify(name, "select position 1 by punching a node")\r
168                 elseif param == "set2" then --set WorldEdit position 2\r
169                         worldedit.set_pos[name] = "pos2"\r
170                         worldedit.player_notify(name, "select position 2 by punching a node")\r
171                 elseif param == "get" then --display current WorldEdit positions\r
172                         if worldedit.pos1[name] ~= nil then\r
173                                 worldedit.player_notify(name, "position 1: " .. minetest.pos_to_string(worldedit.pos1[name]))\r
174                         else\r
175                                 worldedit.player_notify(name, "position 1 not set")\r
176                         end\r
177                         if worldedit.pos2[name] ~= nil then\r
178                                 worldedit.player_notify(name, "position 2: " .. minetest.pos_to_string(worldedit.pos2[name]))\r
179                         else\r
180                                 worldedit.player_notify(name, "position 2 not set")\r
181                         end\r
182                 else\r
183                         worldedit.player_notify(name, "unknown subcommand: " .. param)\r
184                 end\r
185         end,\r
186 })\r
187 \r
188 minetest.register_chatcommand("/fixedpos", {\r
189         params = "set1/set2 x y z",\r
190         description = "Set a WorldEdit region position to the position at (<x>, <y>, <z>)",\r
191         privs = {worldedit=true},\r
192         func = function(name, param)\r
193                 local found, _, flag, x, y, z = param:find("^(set[12])%s+([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)$")\r
194                 if found == nil then\r
195                         worldedit.player_notify(name, "invalid usage: " .. param)\r
196                         return\r
197                 end\r
198                 local pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}\r
199                 if flag == "set1" then\r
200                         worldedit.pos1[name] = pos\r
201                         worldedit.mark_pos1(name)\r
202                         worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))\r
203                 else --flag == "set2"\r
204                         worldedit.pos2[name] = pos\r
205                         worldedit.mark_pos2(name)\r
206                         worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))\r
207                 end\r
208         end,\r
209 })\r
210 \r
211 minetest.register_on_punchnode(function(pos, node, puncher)\r
212         local name = puncher:get_player_name()\r
213         if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position\r
214                 if worldedit.set_pos[name] == "pos1" then --setting position 1\r
215                         worldedit.pos1[name] = pos\r
216                         worldedit.mark_pos1(name)\r
217                         worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation\r
218                         worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))\r
219                 elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only\r
220                         worldedit.pos1[name] = pos\r
221                         worldedit.mark_pos1(name)\r
222                         worldedit.set_pos[name] = nil --finished setting positions\r
223                         worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))\r
224                 elseif worldedit.set_pos[name] == "pos2" then --setting position 2\r
225                         worldedit.pos2[name] = pos\r
226                         worldedit.mark_pos2(name)\r
227                         worldedit.set_pos[name] = nil --finished setting positions\r
228                         worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))\r
229                 elseif worldedit.set_pos[name] == "prob" then --setting Minetest schematic node probabilities\r
230                         worldedit.prob_pos[name] = pos\r
231                         minetest.show_formspec(puncher:get_player_name(), "prob_val_enter", "field[text;;]")\r
232                 end\r
233         end\r
234 end)\r
235 \r
236 minetest.register_chatcommand("/volume", {\r
237         params = "",\r
238         description = "Display the volume of the current WorldEdit region",\r
239         privs = {worldedit=true},\r
240         func = function(name, param)\r
241                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
242                 if pos1 == nil or pos2 == nil then\r
243                         worldedit.player_notify(name, "no region selected")\r
244                         return\r
245                 end\r
246 \r
247                 local volume = worldedit.volume(pos1, pos2)\r
248                 local abs = math.abs\r
249                 worldedit.player_notify(name, "current region has a volume of " .. volume .. " nodes ("\r
250                         .. abs(pos2.x - pos1.x) .. "*"\r
251                         .. abs(pos2.y - pos1.y) .. "*"\r
252                         .. abs(pos2.z - pos1.z) .. ")")\r
253         end,\r
254 })\r
255 \r
256 minetest.register_chatcommand("/set", {\r
257         params = "<node>",\r
258         description = "Set the current WorldEdit region to <node>",\r
259         privs = {worldedit=true},\r
260         func = function(name, param)\r
261                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
262                 if pos1 == nil or pos2 == nil then\r
263                         worldedit.player_notify(name, "no region selected")\r
264                         return\r
265                 end\r
266 \r
267                 local node = worldedit.normalize_nodename(param)\r
268                 if param == "" or not node then\r
269                         worldedit.player_notify(name, "invalid node name: " .. param)\r
270                         return\r
271                 end\r
272 \r
273                 local count = worldedit.set(pos1, pos2, node)\r
274                 worldedit.player_notify(name, count .. " nodes set")\r
275         end,\r
276 })\r
277 \r
278 minetest.register_chatcommand("/replace", {\r
279         params = "<search node> <replace node>",\r
280         description = "Replace all instances of <search node> with <replace node> in the current WorldEdit region",\r
281         privs = {worldedit=true},\r
282         func = function(name, param)\r
283                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
284                 if pos1 == nil or pos2 == nil then\r
285                         worldedit.player_notify(name, "no region selected")\r
286                         return\r
287                 end\r
288 \r
289                 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")\r
290                 if found == nil then\r
291                         worldedit.player_notify(name, "invalid usage: " .. param)\r
292                         return\r
293                 end\r
294                 local newsearchnode = worldedit.normalize_nodename(searchnode)\r
295                 if not newsearchnode then\r
296                         worldedit.player_notify(name, "invalid search node name: " .. searchnode)\r
297                         return\r
298                 end\r
299                 local newreplacenode = worldedit.normalize_nodename(replacenode)\r
300                 if not newreplacenode then\r
301                         worldedit.player_notify(name, "invalid replace node name: " .. replacenode)\r
302                         return\r
303                 end\r
304 \r
305                 local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode)\r
306                 worldedit.player_notify(name, count .. " nodes replaced")\r
307         end,\r
308 })\r
309 \r
310 minetest.register_chatcommand("/replaceinverse", {\r
311         params = "<search node> <replace node>",\r
312         description = "Replace all nodes other than <search node> with <replace node> in the current WorldEdit region",\r
313         privs = {worldedit=true},\r
314         func = function(name, param)\r
315                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
316                 if pos1 == nil or pos2 == nil then\r
317                         worldedit.player_notify(name, "no region selected")\r
318                         return\r
319                 end\r
320 \r
321                 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")\r
322                 if found == nil then\r
323                         worldedit.player_notify(name, "invalid usage: " .. param)\r
324                         return\r
325                 end\r
326                 local newsearchnode = worldedit.normalize_nodename(searchnode)\r
327                 if not newsearchnode then\r
328                         worldedit.player_notify(name, "invalid search node name: " .. searchnode)\r
329                         return\r
330                 end\r
331                 local newreplacenode = worldedit.normalize_nodename(replacenode)\r
332                 if not newreplacenode then\r
333                         worldedit.player_notify(name, "invalid replace node name: " .. replacenode)\r
334                         return\r
335                 end\r
336 \r
337                 local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)\r
338                 worldedit.player_notify(name, count .. " nodes replaced")\r
339         end,\r
340 })\r
341 \r
342 minetest.register_chatcommand("/hollowsphere", {\r
343         params = "<radius> <node>",\r
344         description = "Add hollow sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",\r
345         privs = {worldedit=true},\r
346         func = function(name, param)\r
347                 local pos = worldedit.pos1[name]\r
348                 if pos == nil then\r
349                         worldedit.player_notify(name, "no region selected")\r
350                         return\r
351                 end\r
352 \r
353                 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
354                 if found == nil then\r
355                         worldedit.player_notify(name, "invalid usage: " .. param)\r
356                         return\r
357                 end\r
358                 local node = worldedit.normalize_nodename(nodename)\r
359                 if not node then\r
360                         worldedit.player_notify(name, "invalid node name: " .. nodename)\r
361                         return\r
362                 end\r
363 \r
364                 local count = worldedit.hollow_sphere(pos, tonumber(radius), node)\r
365                 worldedit.player_notify(name, count .. " nodes added")\r
366         end,\r
367 })\r
368 \r
369 minetest.register_chatcommand("/sphere", {\r
370         params = "<radius> <node>",\r
371         description = "Add sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",\r
372         privs = {worldedit=true},\r
373         func = function(name, param)\r
374                 local pos = worldedit.pos1[name]\r
375                 if pos == nil then\r
376                         worldedit.player_notify(name, "no region selected")\r
377                         return\r
378                 end\r
379 \r
380                 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
381                 if found == nil then\r
382                         worldedit.player_notify(name, "invalid usage: " .. param)\r
383                         return\r
384                 end\r
385                 local node = worldedit.normalize_nodename(nodename)\r
386                 if not node then\r
387                         worldedit.player_notify(name, "invalid node name: " .. nodename)\r
388                         return\r
389                 end\r
390 \r
391                 local count = worldedit.sphere(pos, tonumber(radius), node)\r
392                 worldedit.player_notify(name, count .. " nodes added")\r
393         end,\r
394 })\r
395 \r
396 minetest.register_chatcommand("/hollowdome", {\r
397         params = "<radius> <node>",\r
398         description = "Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",\r
399         privs = {worldedit=true},\r
400         func = function(name, param)\r
401                 local pos = worldedit.pos1[name]\r
402                 if pos == nil then\r
403                         worldedit.player_notify(name, "no region selected")\r
404                         return\r
405                 end\r
406 \r
407                 local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")\r
408                 if found == nil then\r
409                         worldedit.player_notify(name, "invalid usage: " .. param)\r
410                         return\r
411                 end\r
412                 local node = worldedit.normalize_nodename(nodename)\r
413                 if not node then\r
414                         worldedit.player_notify(name, "invalid node name: " .. nodename)\r
415                         return\r
416                 end\r
417 \r
418                 local count = worldedit.hollow_dome(pos, tonumber(radius), node)\r
419                 worldedit.player_notify(name, count .. " nodes added")\r
420         end,\r
421 })\r
422 \r
423 minetest.register_chatcommand("/dome", {\r
424         params = "<radius> <node>",\r
425         description = "Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",\r
426         privs = {worldedit=true},\r
427         func = function(name, param)\r
428                 local pos = worldedit.pos1[name]\r
429                 if pos == nil then\r
430                         worldedit.player_notify(name, "no region selected")\r
431                         return\r
432                 end\r
433 \r
434                 local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")\r
435                 if found == nil then\r
436                         worldedit.player_notify(name, "invalid usage: " .. param)\r
437                         return\r
438                 end\r
439                 local node = worldedit.normalize_nodename(nodename)\r
440                 if not node then\r
441                         worldedit.player_notify(name, "invalid node name: " .. nodename)\r
442                         return\r
443                 end\r
444 \r
445                 local count = worldedit.dome(pos, tonumber(radius), node)\r
446                 worldedit.player_notify(name, count .. " nodes added")\r
447         end,\r
448 })\r
449 \r
450 minetest.register_chatcommand("/hollowcylinder", {\r
451         params = "x/y/z/? <length> <radius> <node>",\r
452         description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",\r
453         privs = {worldedit=true},\r
454         func = function(name, param)\r
455                 local pos = worldedit.pos1[name]\r
456                 if pos == nil then\r
457                         worldedit.player_notify(name, "no region selected")\r
458                         return\r
459                 end\r
460 \r
461                 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")\r
462                 if found == nil then\r
463                         worldedit.player_notify(name, "invalid usage: " .. param)\r
464                         return\r
465                 end\r
466                 length, radius = tonumber(length), tonumber(radius)\r
467                 if axis == "?" then\r
468                         axis, sign = worldedit.player_axis(name)\r
469                         length = length * sign\r
470                 end\r
471                 local node = worldedit.normalize_nodename(nodename)\r
472                 if not node then\r
473                         worldedit.player_notify(name, "invalid node name: " .. nodename)\r
474                         return\r
475                 end\r
476 \r
477                 local count = worldedit.hollow_cylinder(pos, axis, length, radius, node)\r
478                 worldedit.player_notify(name, count .. " nodes added")\r
479         end,\r
480 })\r
481 \r
482 minetest.register_chatcommand("/cylinder", {\r
483         params = "x/y/z/? <length> <radius> <node>",\r
484         description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",\r
485         privs = {worldedit=true},\r
486         func = function(name, param)\r
487                 local pos = worldedit.pos1[name]\r
488                 if pos == nil then\r
489                         worldedit.player_notify(name, "no region selected")\r
490                         return\r
491                 end\r
492 \r
493                 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")\r
494                 if found == nil then\r
495                         worldedit.player_notify(name, "invalid usage: " .. param)\r
496                         return\r
497                 end\r
498                 length, radius = tonumber(length), tonumber(radius)\r
499                 if axis == "?" then\r
500                         axis, sign = worldedit.player_axis(name)\r
501                         length = length * sign\r
502                 end\r
503                 local node = worldedit.normalize_nodename(nodename)\r
504                 if not node then\r
505                         worldedit.player_notify(name, "invalid node name: " .. nodename)\r
506                         return\r
507                 end\r
508 \r
509                 local count = worldedit.cylinder(pos, axis, length, radius, node)\r
510                 worldedit.player_notify(name, count .. " nodes added")\r
511         end,\r
512 })\r
513 \r
514 minetest.register_chatcommand("/pyramid", {\r
515         params = "x/y/z/? <height> <node>",\r
516         description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",\r
517         privs = {worldedit=true},\r
518         func = function(name, param)\r
519                 local pos = worldedit.pos1[name]\r
520                 if pos == nil then\r
521                         worldedit.player_notify(name, "no region selected")\r
522                         return\r
523                 end\r
524 \r
525                 local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")\r
526                 if found == nil then\r
527                         worldedit.player_notify(name, "invalid usage: " .. param)\r
528                         return\r
529                 end\r
530                 height = tonumber(height)\r
531                 if axis == "?" then\r
532                         axis, sign = worldedit.player_axis(name)\r
533                         height = height * sign\r
534                 end\r
535                 local node = worldedit.normalize_nodename(nodename)\r
536                 if not node then\r
537                         worldedit.player_notify(name, "invalid node name: " .. nodename)\r
538                         return\r
539                 end\r
540 \r
541                 local count = worldedit.pyramid(pos, axis, height, node)\r
542                 worldedit.player_notify(name, count .. " nodes added")\r
543         end,\r
544 })\r
545 \r
546 minetest.register_chatcommand("/spiral", {\r
547         params = "<length> <height> <space> <node>",\r
548         description = "Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <space>, composed of <node>",\r
549         privs = {worldedit=true},\r
550         func = function(name, param)\r
551                 local pos = worldedit.pos1[name]\r
552                 if pos == nil then\r
553                         worldedit.player_notify(name, "no region selected")\r
554                         return\r
555                 end\r
556 \r
557                 local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
558                 if found == nil then\r
559                         worldedit.player_notify(name, "invalid usage: " .. param)\r
560                         return\r
561                 end\r
562                 local node = worldedit.normalize_nodename(nodename)\r
563                 if not node then\r
564                         worldedit.player_notify(name, "invalid node name: " .. nodename)\r
565                         return\r
566                 end\r
567 \r
568                 local count = worldedit.spiral(pos, tonumber(length), tonumber(height), tonumber(space), node)\r
569                 worldedit.player_notify(name, count .. " nodes added")\r
570         end,\r
571 })\r
572 \r
573 minetest.register_chatcommand("/copy", {\r
574         params = "x/y/z/? <amount>",\r
575         description = "Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes",\r
576         privs = {worldedit=true},\r
577         func = function(name, param)\r
578                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
579                 if pos1 == nil or pos2 == nil then\r
580                         worldedit.player_notify(name, "no region selected")\r
581                         return\r
582                 end\r
583 \r
584                 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
585                 if found == nil then\r
586                         worldedit.player_notify(name, "invalid usage: " .. param)\r
587                         return\r
588                 end\r
589                 amount = tonumber(amount)\r
590                 if axis == "?" then\r
591                         axis, sign = worldedit.player_axis(name)\r
592                         amount = amount * sign\r
593                 end\r
594 \r
595                 local count = worldedit.copy(pos1, pos2, axis, amount)\r
596                 worldedit.player_notify(name, count .. " nodes copied")\r
597         end,\r
598 })\r
599 \r
600 minetest.register_chatcommand("/move", {\r
601         params = "x/y/z/? <amount>",\r
602         description = "Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes",\r
603         privs = {worldedit=true},\r
604         func = function(name, param)\r
605                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
606                 if pos1 == nil or pos2 == nil then\r
607                         worldedit.player_notify(name, "no region selected")\r
608                         return\r
609                 end\r
610 \r
611                 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
612                 if found == nil then\r
613                         worldedit.player_notify(name, "invalid usage: " .. param)\r
614                         return\r
615                 end\r
616                 amount = tonumber(amount)\r
617                 if axis == "?" then\r
618                         axis, sign = worldedit.player_axis(name)\r
619                         amount = amount * sign\r
620                 end\r
621 \r
622                 local count = worldedit.move(pos1, pos2, axis, amount)\r
623 \r
624                 pos1[axis] = pos1[axis] + amount\r
625                 pos2[axis] = pos2[axis] + amount\r
626                 worldedit.mark_pos1(name)\r
627                 worldedit.mark_pos2(name)\r
628                 worldedit.player_notify(name, count .. " nodes moved")\r
629         end,\r
630 })\r
631 \r
632 minetest.register_chatcommand("/stack", {\r
633         params = "x/y/z/? <count>",\r
634         description = "Stack the current WorldEdit region along the x/y/z/? axis <count> times",\r
635         privs = {worldedit=true},\r
636         func = function(name, param)\r
637                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
638                 if pos1 == nil or pos2 == nil then\r
639                         worldedit.player_notify(name, "no region selected")\r
640                         return\r
641                 end\r
642 \r
643                 local found, _, axis, count = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
644                 if found == nil then\r
645                         worldedit.player_notify(name, "invalid usage: " .. param)\r
646                         return\r
647                 end\r
648                 count = tonumber(count)\r
649                 if axis == "?" then\r
650                         axis, sign = worldedit.player_axis(name)\r
651                         count = count * sign\r
652                 end\r
653 \r
654                 local count = worldedit.stack(pos1, pos2, axis, count)\r
655                 worldedit.player_notify(name, count .. " nodes stacked")\r
656         end,\r
657 })\r
658 \r
659 minetest.register_chatcommand("/scale", {\r
660         params = "<factor>",\r
661         description = "Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin",\r
662         privs = {worldedit=true},\r
663         func = function(name, param)\r
664                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
665                 if pos1 == nil or pos2 == nil then\r
666                         worldedit.player_notify(name, "no region selected")\r
667                         return\r
668                 end\r
669 \r
670                 local factor = tonumber(param)\r
671                 if not factor or factor ~= math.floor(factor) or factor <= 0 then\r
672                         worldedit.player_notify(name, "invalid scaling factor: " .. param)\r
673                 end\r
674 \r
675                 local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor)\r
676 \r
677                 --reset markers to scaled positions\r
678                 worldedit.pos1[name] = pos1\r
679                 worldedit.pos2[name] = pos2\r
680                 worldedit.mark_pos1(name)\r
681                 worldedit.mark_pos2(name)\r
682 \r
683                 worldedit.player_notify(name, count .. " nodes scaled")\r
684         end,\r
685 })\r
686 \r
687 minetest.register_chatcommand("/transpose", {\r
688         params = "x/y/z/? x/y/z/?",\r
689         description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",\r
690         privs = {worldedit=true},\r
691         func = function(name, param)\r
692                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
693                 if pos1 == nil or pos2 == nil then\r
694                         worldedit.player_notify(name, "no region selected")\r
695                         return\r
696                 end\r
697 \r
698                 local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")\r
699                 if found == nil then\r
700                         worldedit.player_notify(name, "invalid usage: " .. param)\r
701                         return\r
702                 end\r
703                 if axis1 == "?" then\r
704                         axis1 = worldedit.player_axis(name)\r
705                 end\r
706                 if axis2 == "?" then\r
707                         axis2 = worldedit.player_axis(name)\r
708                 end\r
709                 if axis1 == axis2 then\r
710                         worldedit.player_notify(name, "invalid usage: axes must be different")\r
711                         return\r
712                 end\r
713 \r
714                 local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)\r
715 \r
716                 --reset markers to transposed positions\r
717                 worldedit.pos1[name] = pos1\r
718                 worldedit.pos2[name] = pos2\r
719                 worldedit.mark_pos1(name)\r
720                 worldedit.mark_pos2(name)\r
721 \r
722                 worldedit.player_notify(name, count .. " nodes transposed")\r
723         end,\r
724 })\r
725 \r
726 minetest.register_chatcommand("/flip", {\r
727         params = "x/y/z/?",\r
728         description = "Flip the current WorldEdit region along the x/y/z/? axis",\r
729         privs = {worldedit=true},\r
730         func = function(name, param)\r
731                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
732                 if pos1 == nil or pos2 == nil then\r
733                         worldedit.player_notify(name, "no region selected")\r
734                         return\r
735                 end\r
736 \r
737                 if param == "?" then\r
738                         param = worldedit.player_axis(name)\r
739                 end\r
740                 if param ~= "x" and param ~= "y" and param ~= "z" then\r
741                         worldedit.player_notify(name, "invalid usage: " .. param)\r
742                         return\r
743                 end\r
744 \r
745                 local count = worldedit.flip(pos1, pos2, param)\r
746                 worldedit.player_notify(name, count .. " nodes flipped")\r
747         end,\r
748 })\r
749 \r
750 minetest.register_chatcommand("/rotate", {\r
751         params = "<axis> <angle>",\r
752         description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",\r
753         privs = {worldedit=true},\r
754         func = function(name, param)\r
755                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
756                 if pos1 == nil or pos2 == nil then\r
757                         worldedit.player_notify(name, "no region selected")\r
758                         return\r
759                 end\r
760 \r
761                 local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
762                 if found == nil then\r
763                         worldedit.player_notify(name, "invalid usage: " .. param)\r
764                         return\r
765                 end\r
766                 if axis == "?" then\r
767                         axis = worldedit.player_axis(name)\r
768                 end\r
769                 if angle % 90 ~= 0 then\r
770                         worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")\r
771                         return\r
772                 end\r
773 \r
774                 local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)\r
775 \r
776                 --reset markers to rotated positions\r
777                 worldedit.pos1[name] = pos1\r
778                 worldedit.pos2[name] = pos2\r
779                 worldedit.mark_pos1(name)\r
780                 worldedit.mark_pos2(name)\r
781 \r
782                 worldedit.player_notify(name, count .. " nodes rotated")\r
783         end,\r
784 })\r
785 \r
786 minetest.register_chatcommand("/orient", {\r
787         params = "<angle>",\r
788         description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)",\r
789         privs = {worldedit=true},\r
790         func = function(name, param)\r
791                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
792                 if pos1 == nil or pos2 == nil then\r
793                         worldedit.player_notify(name, "no region selected")\r
794                         return\r
795                 end\r
796 \r
797                 local found, _, angle = param:find("^([+-]?%d+)$")\r
798                 if found == nil then\r
799                         worldedit.player_notify(name, "invalid usage: " .. param)\r
800                         return\r
801                 end\r
802                 if angle % 90 ~= 0 then\r
803                         worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")\r
804                         return\r
805                 end\r
806 \r
807                 local count = worldedit.orient(pos1, pos2, angle)\r
808 \r
809                 worldedit.player_notify(name, count .. " nodes oriented")\r
810         end,\r
811 })\r
812 \r
813 minetest.register_chatcommand("/fixlight", {\r
814         params = "",\r
815         description = "Fix the lighting in the current WorldEdit region",\r
816         privs = {worldedit=true},\r
817         func = function(name, param)\r
818                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
819                 if pos1 == nil or pos2 == nil then\r
820                         worldedit.player_notify(name, "no region selected")\r
821                         return\r
822                 end\r
823 \r
824                 local count = worldedit.fixlight(pos1, pos2)\r
825                 worldedit.player_notify(name, count .. " nodes updated")\r
826         end,\r
827 })\r
828 \r
829 minetest.register_chatcommand("/hide", {\r
830         params = "",\r
831         description = "Hide all nodes in the current WorldEdit region non-destructively",\r
832         privs = {worldedit=true},\r
833         func = function(name, param)\r
834                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
835                 if pos1 == nil or pos2 == nil then\r
836                         worldedit.player_notify(name, "no region selected")\r
837                         return\r
838                 end\r
839 \r
840                 local count = worldedit.hide(pos1, pos2)\r
841                 worldedit.player_notify(name, count .. " nodes hidden")\r
842         end,\r
843 })\r
844 \r
845 minetest.register_chatcommand("/suppress", {\r
846         params = "<node>",\r
847         description = "Suppress all <node> in the current WorldEdit region non-destructively",\r
848         privs = {worldedit=true},\r
849         func = function(name, param)\r
850                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
851                 if pos1 == nil or pos2 == nil then\r
852                         worldedit.player_notify(name, "no region selected")\r
853                         return\r
854                 end\r
855 \r
856                 local node = worldedit.normalize_nodename(param)\r
857                 if param == "" or not node then\r
858                         worldedit.player_notify(name, "invalid node name: " .. param)\r
859                         return\r
860                 end\r
861 \r
862                 local count = worldedit.suppress(pos1, pos2, node)\r
863                 worldedit.player_notify(name, count .. " nodes suppressed")\r
864         end,\r
865 })\r
866 \r
867 minetest.register_chatcommand("/highlight", {\r
868         params = "<node>",\r
869         description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",\r
870         privs = {worldedit=true},\r
871         func = function(name, param)\r
872                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
873                 if pos1 == nil or pos2 == nil then\r
874                         worldedit.player_notify(name, "no region selected")\r
875                         return\r
876                 end\r
877 \r
878                 local node = worldedit.normalize_nodename(param)\r
879                 if param == "" or not node then\r
880                         worldedit.player_notify(name, "invalid node name: " .. param)\r
881                         return\r
882                 end\r
883 \r
884                 local count = worldedit.highlight(pos1, pos2, node)\r
885                 worldedit.player_notify(name, count .. " nodes highlighted")\r
886         end,\r
887 })\r
888 \r
889 minetest.register_chatcommand("/restore", {\r
890         params = "",\r
891         description = "Restores nodes hidden with WorldEdit in the current WorldEdit region",\r
892         privs = {worldedit=true},\r
893         func = function(name, param)\r
894                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
895                 if pos1 == nil or pos2 == nil then\r
896                         worldedit.player_notify(name, "no region selected")\r
897                         return\r
898                 end\r
899 \r
900                 local count = worldedit.restore(pos1, pos2)\r
901                 worldedit.player_notify(name, count .. " nodes restored")\r
902         end,\r
903 })\r
904 \r
905 minetest.register_chatcommand("/save", {\r
906         params = "<file>",\r
907         description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",\r
908         privs = {worldedit=true},\r
909         func = function(name, param)\r
910                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
911                 if pos1 == nil or pos2 == nil then\r
912                         worldedit.player_notify(name, "no region selected")\r
913                         return\r
914                 end\r
915 \r
916                 if param == "" then\r
917                         worldedit.player_notify(name, "invalid usage: " .. param)\r
918                         return\r
919                 end\r
920 \r
921                 local result, count = worldedit.serialize(pos1, pos2)\r
922 \r
923                 local path = minetest.get_worldpath() .. "/schems"\r
924                 local filename = path .. "/" .. param .. ".we"\r
925                 os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist\r
926                 local file, err = io.open(filename, "wb")\r
927                 if err ~= nil then\r
928                         worldedit.player_notify(name, "could not save file to \"" .. filename .. "\"")\r
929                         return\r
930                 end\r
931                 file:write(result)\r
932                 file:flush()\r
933                 file:close()\r
934 \r
935                 worldedit.player_notify(name, count .. " nodes saved")\r
936         end,\r
937 })\r
938 \r
939 minetest.register_chatcommand("/allocate", {\r
940         params = "<file>",\r
941         description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",\r
942         privs = {worldedit=true},\r
943         func = function(name, param)\r
944                 local pos1 = worldedit.pos1[name]\r
945                 if pos1 == nil then\r
946                         worldedit.player_notify(name, "no region selected")\r
947                         return\r
948                 end\r
949 \r
950                 if param == "" then\r
951                         worldedit.player_notify(name, "invalid usage: " .. param)\r
952                         return\r
953                 end\r
954 \r
955                 local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"\r
956                 local file, err = io.open(filename, "rb")\r
957                 if err ~= nil then\r
958                         worldedit.player_notify(name, "could not open file \"" .. filename .. "\"")\r
959                         return\r
960                 end\r
961                 local value = file:read("*a")\r
962                 file:close()\r
963 \r
964                 if worldedit.valueversion(value) == 0 then --unknown version\r
965                         worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")\r
966                         return\r
967                 end\r
968                 local nodepos1, nodepos2, count = worldedit.allocate(pos1, value)\r
969 \r
970                 worldedit.pos1[name] = nodepos1\r
971                 worldedit.mark_pos1(name)\r
972                 worldedit.pos2[name] = nodepos2\r
973                 worldedit.mark_pos2(name)\r
974 \r
975                 worldedit.player_notify(name, count .. " nodes allocated")\r
976         end,\r
977 })\r
978 \r
979 minetest.register_chatcommand("/load", {\r
980         params = "<file>",\r
981         description = "Load nodes from \"(world folder)/schems/<file>[.we[m]]\" with position 1 of the current WorldEdit region as the origin",\r
982         privs = {worldedit=true},\r
983         func = function(name, param)\r
984                 local pos1 = worldedit.pos1[name]\r
985                 if pos1 == nil then\r
986                         worldedit.player_notify(name, "no region selected")\r
987                         return\r
988                 end\r
989 \r
990                 if param == "" then\r
991                         worldedit.player_notify(name, "invalid usage: " .. param)\r
992                         return\r
993                 end\r
994 \r
995                 --find the file in the world path\r
996                 local testpaths = {\r
997                         minetest.get_worldpath() .. "/schems/" .. param,\r
998                         minetest.get_worldpath() .. "/schems/" .. param .. ".we",\r
999                         minetest.get_worldpath() .. "/schems/" .. param .. ".wem",\r
1000                 }\r
1001                 local file, err\r
1002                 for index, path in ipairs(testpaths) do\r
1003                         file, err = io.open(path, "rb")\r
1004                         if not err then\r
1005                                 break\r
1006                         end\r
1007                 end\r
1008                 if err then\r
1009                         worldedit.player_notify(name, "could not open file \"" .. param .. "\"")\r
1010                         return\r
1011                 end\r
1012                 local value = file:read("*a")\r
1013                 file:close()\r
1014 \r
1015                 if worldedit.valueversion(value) == 0 then --unknown version\r
1016                         worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")\r
1017                         return\r
1018                 end\r
1019 \r
1020                 local count = worldedit.deserialize(pos1, value)\r
1021 \r
1022                 worldedit.player_notify(name, count .. " nodes loaded")\r
1023         end,\r
1024 })\r
1025 \r
1026 minetest.register_chatcommand("/lua", {\r
1027         params = "<code>",\r
1028         description = "Executes <code> as a Lua chunk in the global namespace",\r
1029         privs = {worldedit=true, server=true},\r
1030         func = function(name, param)\r
1031                 local err = worldedit.lua(param)\r
1032                 if err then\r
1033                         worldedit.player_notify(name, "code error: " .. err)\r
1034                 else\r
1035                         worldedit.player_notify(name, "code successfully executed", false)\r
1036                 end\r
1037         end,\r
1038 })\r
1039 \r
1040 minetest.register_chatcommand("/luatransform", {\r
1041         params = "<code>",\r
1042         description = "Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region",\r
1043         privs = {worldedit=true, server=true},\r
1044         func = function(name, param)\r
1045                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
1046                 if pos1 == nil or pos2 == nil then\r
1047                         worldedit.player_notify(name, "no region selected")\r
1048                         return\r
1049                 end\r
1050 \r
1051                 local err = worldedit.luatransform(pos1, pos2, param)\r
1052                 if err then\r
1053                         worldedit.player_notify(name, "code error: " .. err, false)\r
1054                 else\r
1055                         worldedit.player_notify(name, "code successfully executed", false)\r
1056                 end\r
1057         end,\r
1058 })\r
1059 \r
1060 if minetest.place_schematic then\r
1061 minetest.register_chatcommand("/mtschemcreate", {\r
1062         params = "<file>",\r
1063         description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/<filename>.mts\"",\r
1064         privs = {worldedit=true},\r
1065         func = function(name, param)\r
1066                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
1067                 if pos1 == nil or pos2 == nil then\r
1068                         worldedit.player_notify(name, "No region selected")\r
1069                         return\r
1070                 end\r
1071                 if param == nil then\r
1072                         worldedit.player_notify(name, "No filename specified")\r
1073                         return\r
1074                 end\r
1075 \r
1076                 local path = minetest.get_worldpath() .. "/schems"\r
1077                 local filename = path .. "/" .. param .. ".mts"\r
1078                 os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist\r
1079 \r
1080                 local ret = minetest.create_schematic(pos1, pos2, worldedit.prob_list[name], filename)\r
1081                 if ret == nil then\r
1082                         worldedit.player_notify(name, "Failed to create Minetest schematic", false)\r
1083                 else\r
1084                         worldedit.player_notify(name, "Saved Minetest schematic to " .. param, false)\r
1085                 end\r
1086                 worldedit.prob_list[name] = {}\r
1087         end,\r
1088 })\r
1089 \r
1090 minetest.register_chatcommand("/mtschemplace", {\r
1091         params = "<file>",\r
1092         description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",\r
1093         privs = {worldedit=true},\r
1094         func = function(name, param)\r
1095                 local pos = worldedit.pos1[name]\r
1096                 if pos == nil then\r
1097                         worldedit.player_notify(name, "No position selected")\r
1098                         return\r
1099                 end\r
1100                 if param == nil then\r
1101                         worldedit.player_notify(name, "No filename specified")\r
1102                         return\r
1103                 end\r
1104 \r
1105                 local path = minetest.get_worldpath() .. "/schems/" .. param .. ".mts"\r
1106                 if minetest.place_schematic(pos, path) == nil then\r
1107                         worldedit.player_notify(name, "Failed to place Minetest schematic", false)\r
1108                 else\r
1109                         worldedit.player_notify(name, "Placed Minetest schematic " .. param ..\r
1110                                 " at " .. minetest.pos_to_string(pos), false)\r
1111                 end\r
1112         end,\r
1113 })\r
1114 \r
1115 minetest.register_chatcommand("/mtschemprob", {\r
1116         params = "start/finish/get",\r
1117         description = "Begins node probability entry for Minetest schematics, gets the nodes that have probabilities set, or ends node probability entry",\r
1118         privs = {worldedit=true},\r
1119         func = function(name, param)\r
1120                 if param == "start" then --start probability setting\r
1121                         worldedit.set_pos[name] = "prob"\r
1122                         worldedit.prob_list[name] = {}\r
1123                         worldedit.player_notify(name, "select Minetest schematic probability values by punching nodes")\r
1124                 elseif param == "finish" then --finish probability setting\r
1125                         worldedit.set_pos[name] = nil\r
1126                         worldedit.player_notify(name, "finished Minetest schematic probability selection")\r
1127                 elseif param == "get" then --get all nodes that had probabilities set on them\r
1128                         local text = ""\r
1129                         local problist = worldedit.prob_list[name]\r
1130                         if problist == nil then\r
1131                                 return\r
1132                         end\r
1133                         for k,v in pairs(problist) do\r
1134                                 local prob = math.floor(((v["prob"] / 256) * 100) * 100 + 0.5) / 100\r
1135                                 text = text .. minetest.pos_to_string(v["pos"]) .. ": " .. prob .. "% | "\r
1136                         end\r
1137                         worldedit.player_notify(name, "Currently set node probabilities:")\r
1138                         worldedit.player_notify(name, text)\r
1139                 else\r
1140                         worldedit.player_notify(name, "unknown subcommand: " .. param)\r
1141                 end\r
1142         end,\r
1143 })\r
1144 \r
1145 minetest.register_on_player_receive_fields(\r
1146         function(player, formname, fields)\r
1147                 if (formname == "prob_val_enter") and (fields.text ~= "") then\r
1148                         local name = player:get_player_name()\r
1149                         local prob_entry = {pos=worldedit.prob_pos[name], prob=tonumber(fields.text)}\r
1150                         local index = table.getn(worldedit.prob_list[name]) + 1\r
1151                         worldedit.prob_list[name][index] = prob_entry\r
1152                 end\r
1153         end\r
1154 )\r
1155 end\r
1156 \r
1157 minetest.register_chatcommand("/clearobjects", {\r
1158         params = "",\r
1159         description = "Clears all objects within the WorldEdit region",\r
1160         privs = {worldedit=true},\r
1161         func = function(name, param)\r
1162                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
1163                 if pos1 == nil or pos2 == nil then\r
1164                         worldedit.player_notify(name, "no region selected")\r
1165                         return\r
1166                 end\r
1167 \r
1168                 local count = worldedit.clearobjects(pos1, pos2)\r
1169                 worldedit.player_notify(name, count .. " objects cleared")\r
1170         end,\r
1171 })\r