1 minetest.register_privilege("worldedit", "Can use WorldEdit commands")
\r
3 worldedit.set_pos = {}
\r
8 dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")
\r
10 --determines whether `nodename` is a valid node name, returning a boolean
\r
11 worldedit.node_is_valid = function(nodename)
\r
12 return minetest.registered_nodes[nodename] ~= nil
\r
13 or minetest.registered_nodes["default:" .. nodename] ~= nil
\r
16 --determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
\r
17 worldedit.player_axis = function(name)
\r
18 local dir = minetest.env:get_player_by_name(name):get_look_dir()
\r
19 local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
\r
22 return "x", dir.x > 0 and 1 or -1
\r
25 return "y", dir.y > 0 and 1 or -1
\r
27 return "z", dir.z > 0 and 1 or -1
\r
30 minetest.register_chatcommand("/reset", {
\r
32 description = "Reset the region so that it is empty",
\r
33 privs = {worldedit=true},
\r
34 func = function(name, param)
\r
35 worldedit.pos1[name] = nil
\r
36 worldedit.pos2[name] = nil
\r
37 worldedit.mark_pos1(name)
\r
38 worldedit.mark_pos2(name)
\r
39 worldedit.set_pos[name] = nil
\r
40 minetest.chat_send_player(name, "WorldEdit region reset", false)
\r
44 minetest.register_chatcommand("/mark", {
\r
46 description = "Show markers at the region positions",
\r
47 privs = {worldedit=true},
\r
48 func = function(name, param)
\r
49 worldedit.mark_pos1(name)
\r
50 worldedit.mark_pos2(name)
\r
51 minetest.chat_send_player(name, "WorldEdit region marked", false)
\r
55 minetest.register_chatcommand("/unmark", {
\r
57 description = "Hide markers if currently shown",
\r
58 privs = {worldedit=true},
\r
59 func = function(name, param)
\r
60 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
61 worldedit.pos1[name] = nil
\r
62 worldedit.pos2[name] = nil
\r
63 worldedit.mark_pos1(name)
\r
64 worldedit.mark_pos2(name)
\r
65 worldedit.pos1[name] = pos1
\r
66 worldedit.pos2[name] = pos2
\r
67 minetest.chat_send_player(name, "WorldEdit region unmarked", false)
\r
71 minetest.register_chatcommand("/pos1", {
\r
73 description = "Set WorldEdit region position 1 to the player's location",
\r
74 privs = {worldedit=true},
\r
75 func = function(name, param)
\r
76 local pos = minetest.env:get_player_by_name(name):getpos()
\r
77 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
78 worldedit.pos1[name] = pos
\r
79 worldedit.mark_pos1(name)
\r
80 minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos), false)
\r
84 minetest.register_chatcommand("/pos2", {
\r
86 description = "Set WorldEdit region position 2 to the player's location",
\r
87 privs = {worldedit=true},
\r
88 func = function(name, param)
\r
89 local pos = minetest.env:get_player_by_name(name):getpos()
\r
90 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
91 worldedit.pos2[name] = pos
\r
92 worldedit.mark_pos2(name)
\r
93 minetest.chat_send_player(name, "WorldEdit position 2 set to " .. minetest.pos_to_string(pos), false)
\r
97 minetest.register_chatcommand("/p", {
\r
98 params = "set/set1/set2/get",
\r
99 description = "Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region",
\r
100 privs = {worldedit=true},
\r
101 func = function(name, param)
\r
102 if param == "set" then --set both WorldEdit positions
\r
103 worldedit.set_pos[name] = "pos1"
\r
104 minetest.chat_send_player(name, "Select positions by punching two nodes", false)
\r
105 elseif param == "set1" then --set WorldEdit position 1
\r
106 worldedit.set_pos[name] = "pos1only"
\r
107 minetest.chat_send_player(name, "Select position 1 by punching a node", false)
\r
108 elseif param == "set2" then --set WorldEdit position 2
\r
109 worldedit.set_pos[name] = "pos2"
\r
110 minetest.chat_send_player(name, "Select position 2 by punching a node", false)
\r
111 elseif param == "get" then --display current WorldEdit positions
\r
112 if worldedit.pos1[name] ~= nil then
\r
113 minetest.chat_send_player(name, "WorldEdit position 1: " .. minetest.pos_to_string(worldedit.pos1[name]), false)
\r
115 minetest.chat_send_player(name, "WorldEdit position 1 not set", false)
\r
117 if worldedit.pos2[name] ~= nil then
\r
118 minetest.chat_send_player(name, "WorldEdit position 2: " .. minetest.pos_to_string(worldedit.pos2[name]), false)
\r
120 minetest.chat_send_player(name, "WorldEdit position 2 not set", false)
\r
123 minetest.chat_send_player(name, "Unknown subcommand: " .. param, false)
\r
128 minetest.register_on_punchnode(function(pos, node, puncher)
\r
129 local name = puncher:get_player_name()
\r
130 if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position
\r
131 if worldedit.set_pos[name] == "pos1" then --setting position 1
\r
132 worldedit.pos1[name] = pos
\r
133 worldedit.mark_pos1(name)
\r
134 worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation
\r
135 minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos), false)
\r
136 elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only
\r
137 worldedit.pos1[name] = pos
\r
138 worldedit.mark_pos1(name)
\r
139 worldedit.set_pos[name] = nil --finished setting positions
\r
140 minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos), false)
\r
141 elseif worldedit.set_pos[name] == "pos2" then --setting position 2
\r
142 worldedit.pos2[name] = pos
\r
143 worldedit.mark_pos2(name)
\r
144 worldedit.set_pos[name] = nil --finished setting positions
\r
145 minetest.chat_send_player(name, "WorldEdit position 2 set to " .. minetest.pos_to_string(pos), false)
\r
150 minetest.register_chatcommand("/volume", {
\r
152 description = "Display the volume of the current WorldEdit region",
\r
153 privs = {worldedit=true},
\r
154 func = function(name, param)
\r
155 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
156 if pos1 == nil or pos2 == nil then
\r
157 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
161 local volume = worldedit.volume(pos1, pos2)
\r
162 minetest.chat_send_player(name, "Current WorldEdit region has a volume of " .. volume .. " nodes (" .. pos2.x - pos1.x .. "*" .. pos2.y - pos1.y .. "*" .. pos2.z - pos1.z .. ")", false)
\r
166 minetest.register_chatcommand("/set", {
\r
168 description = "Set the current WorldEdit region to <node>",
\r
169 privs = {worldedit=true},
\r
170 func = function(name, param)
\r
171 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
172 if pos1 == nil or pos2 == nil then
\r
173 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
177 if param == "" or not worldedit.node_is_valid(param) then
\r
178 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
182 local tenv = minetest.env
\r
183 if worldedit.ENABLE_QUEUE then
\r
184 tenv = worldedit.quene_aliasenv
\r
186 local count = worldedit.set(pos1, pos2, param, tenv)
\r
187 minetest.chat_send_player(name, count .. " nodes set", false)
\r
191 minetest.register_chatcommand("/replace", {
\r
192 params = "<search node> <replace node>",
\r
193 description = "Replace all instances of <search node> with <replace node> in the current WorldEdit region",
\r
194 privs = {worldedit=true},
\r
195 func = function(name, param)
\r
196 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
197 if pos1 == nil or pos2 == nil then
\r
198 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
202 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")
\r
203 if found == nil then
\r
204 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
207 if not worldedit.node_is_valid(searchnode) then
\r
208 minetest.chat_send_player(name, "Invalid search node name: " .. searchnode, false)
\r
211 if not worldedit.node_is_valid(replacenode) then
\r
212 minetest.chat_send_player(name, "Invalid replace node name: " .. replacenode, false)
\r
216 local tenv = minetest.env
\r
217 if worldedit.ENABLE_QUEUE then
\r
218 tenv = worldedit.quene_aliasenv
\r
220 local count = worldedit.replace(pos1, pos2, searchnode, replacenode, tenv)
\r
221 minetest.chat_send_player(name, count .. " nodes replaced", false)
\r
225 minetest.register_chatcommand("/replaceinverse", {
\r
226 params = "<search node> <replace node>",
\r
227 description = "Replace all nodes other than <search node> with <replace node> in the current WorldEdit region",
\r
228 privs = {worldedit=true},
\r
229 func = function(name, param)
\r
230 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
231 if pos1 == nil or pos2 == nil then
\r
232 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
236 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")
\r
237 if found == nil then
\r
238 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
241 if not worldedit.node_is_valid(searchnode) then
\r
242 minetest.chat_send_player(name, "Invalid search node name: " .. searchnode, false)
\r
245 if not worldedit.node_is_valid(replacenode) then
\r
246 minetest.chat_send_player(name, "Invalid replace node name: " .. replacenode, false)
\r
250 local tenv = minetest.env
\r
251 if worldedit.ENABLE_QUEUE then
\r
252 tenv = worldedit.quene_aliasenv
\r
254 local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode, tenv)
\r
255 minetest.chat_send_player(name, count .. " nodes replaced", false)
\r
259 minetest.register_chatcommand("/hollowsphere", {
\r
260 params = "<radius> <node>",
\r
261 description = "Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
262 privs = {worldedit=true},
\r
263 func = function(name, param)
\r
264 local pos = worldedit.pos1[name]
\r
266 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
270 local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
\r
271 if found == nil then
\r
272 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
275 if not worldedit.node_is_valid(nodename) then
\r
276 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
280 local tenv = minetest.env
\r
281 if worldedit.ENABLE_QUEUE then
\r
282 tenv = worldedit.quene_aliasenv
\r
284 local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename, tenv)
\r
285 minetest.chat_send_player(name, count .. " nodes added", false)
\r
289 minetest.register_chatcommand("/sphere", {
\r
290 params = "<radius> <node>",
\r
291 description = "Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
292 privs = {worldedit=true},
\r
293 func = function(name, param)
\r
294 local pos = worldedit.pos1[name]
\r
296 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
300 local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
\r
301 if found == nil then
\r
302 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
305 if not worldedit.node_is_valid(nodename) then
\r
306 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
310 local tenv = minetest.env
\r
311 if worldedit.ENABLE_QUEUE then
\r
312 tenv = worldedit.quene_aliasenv
\r
314 local count = worldedit.sphere(pos, tonumber(radius), nodename, tenv)
\r
315 minetest.chat_send_player(name, count .. " nodes added", false)
\r
319 minetest.register_chatcommand("/hollowdome", {
\r
320 params = "<radius> <node>",
\r
321 description = "Add hollow dome at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
322 privs = {worldedit=true},
\r
323 func = function(name, param)
\r
324 local pos = worldedit.pos1[name]
\r
326 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
330 local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
\r
331 if found == nil then
\r
332 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
335 if not worldedit.node_is_valid(nodename) then
\r
336 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
340 local tenv = minetest.env
\r
341 if worldedit.ENABLE_QUEUE then
\r
342 tenv = worldedit.quene_aliasenv
\r
344 local count = worldedit.hollow_dome(pos, tonumber(radius), nodename, tenv)
\r
345 minetest.chat_send_player(name, count .. " nodes added", false)
\r
349 minetest.register_chatcommand("/dome", {
\r
350 params = "<radius> <node>",
\r
351 description = "Add dome at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
352 privs = {worldedit=true},
\r
353 func = function(name, param)
\r
354 local pos = worldedit.pos1[name]
\r
356 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
360 local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
\r
361 if found == nil then
\r
362 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
365 if not worldedit.node_is_valid(nodename) then
\r
366 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
370 local tenv = minetest.env
\r
371 if worldedit.ENABLE_QUEUE then
\r
372 tenv = worldedit.quene_aliasenv
\r
374 local count = worldedit.dome(pos, tonumber(radius), nodename, tenv)
\r
375 minetest.chat_send_player(name, count .. " nodes added", false)
\r
379 minetest.register_chatcommand("/hollowcylinder", {
\r
380 params = "x/y/z/? <length> <radius> <node>",
\r
381 description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
\r
382 privs = {worldedit=true},
\r
383 func = function(name, param)
\r
384 local pos = worldedit.pos1[name]
\r
386 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
390 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")
\r
391 if found == nil then
\r
392 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
395 if axis == "?" then
\r
396 axis, sign = worldedit.player_axis(name)
\r
397 length = length * sign
\r
399 if not worldedit.node_is_valid(nodename) then
\r
400 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
404 local tenv = minetest.env
\r
405 if worldedit.ENABLE_QUEUE then
\r
406 tenv = worldedit.quene_aliasenv
\r
408 local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), nodename, tenv)
\r
409 minetest.chat_send_player(name, count .. " nodes added", false)
\r
413 minetest.register_chatcommand("/cylinder", {
\r
414 params = "x/y/z/? <length> <radius> <node>",
\r
415 description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
\r
416 privs = {worldedit=true},
\r
417 func = function(name, param)
\r
418 local pos = worldedit.pos1[name]
\r
420 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
424 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")
\r
425 if found == nil then
\r
426 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
429 if axis == "?" then
\r
430 axis, sign = worldedit.player_axis(name)
\r
431 length = length * sign
\r
433 if not worldedit.node_is_valid(nodename) then
\r
434 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
438 local tenv = minetest.env
\r
439 if worldedit.ENABLE_QUEUE then
\r
440 tenv = worldedit.quene_aliasenv
\r
442 local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), nodename, tenv)
\r
443 minetest.chat_send_player(name, count .. " nodes added", false)
\r
447 minetest.register_chatcommand("/pyramid", {
\r
448 params = "<height> <node>",
\r
449 description = "Add pyramid at WorldEdit position 1 with height <height>, composed of <node>",
\r
450 privs = {worldedit=true},
\r
451 func = function(name, param)
\r
452 local pos = worldedit.pos1[name]
\r
454 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
458 local found, _, size, nodename = param:find("(%d+)%s+([^%s]+)$")
\r
459 if found == nil then
\r
460 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
463 if not worldedit.node_is_valid(nodename) then
\r
464 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
468 local tenv = minetest.env
\r
469 if worldedit.ENABLE_QUEUE then
\r
470 tenv = worldedit.quene_aliasenv
\r
472 local count = worldedit.pyramid(pos, tonumber(size), nodename, tenv)
\r
473 minetest.chat_send_player(name, count .. " nodes added", false)
\r
477 minetest.register_chatcommand("/spiral", {
\r
478 params = "<width> <height> <space> <node>",
\r
479 description = "Add spiral at WorldEdit position 1 with width <width>, height <height>, space between walls <space>, composed of <node>",
\r
480 privs = {worldedit=true},
\r
481 func = function(name, param)
\r
482 local pos = worldedit.pos1[name]
\r
484 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
488 local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+([^%s]+)$")
\r
489 if found == nil then
\r
490 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
493 if not worldedit.node_is_valid(nodename) then
\r
494 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
498 local tenv = minetest.env
\r
499 if worldedit.ENABLE_QUEUE then
\r
500 tenv = worldedit.quene_aliasenv
\r
502 local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), nodename, tenv)
\r
503 minetest.chat_send_player(name, count .. " nodes changed", false)
\r
507 minetest.register_chatcommand("/copy", {
\r
508 params = "x/y/z/? <amount>",
\r
509 description = "Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
510 privs = {worldedit=true},
\r
511 func = function(name, param)
\r
512 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
513 if pos1 == nil or pos2 == nil then
\r
514 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
518 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
519 if found == nil then
\r
520 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
523 if axis == "?" then
\r
524 axis, sign = worldedit.player_axis(name)
\r
525 amount = amount * sign
\r
528 local tenv = minetest.env
\r
529 if worldedit.ENABLE_QUEUE then
\r
530 tenv = worldedit.quene_aliasenv
\r
532 local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)
\r
533 minetest.chat_send_player(name, count .. " nodes copied", false)
\r
537 minetest.register_chatcommand("/move", {
\r
538 params = "x/y/z/? <amount>",
\r
539 description = "Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
540 privs = {worldedit=true},
\r
541 func = function(name, param)
\r
542 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
543 if pos1 == nil or pos2 == nil then
\r
544 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
548 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
549 if found == nil then
\r
550 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
553 if axis == "?" then
\r
554 axis, sign = worldedit.player_axis(name)
\r
555 amount = amount * sign
\r
558 local count = worldedit.move(pos1, pos2, axis, tonumber(amount))
\r
560 pos1[axis] = pos1[axis] + amount
\r
561 pos2[axis] = pos2[axis] + amount
\r
562 worldedit.mark_pos1(name)
\r
563 worldedit.mark_pos2(name)
\r
565 local tenv = minetest.env
\r
566 if worldedit.ENABLE_QUEUE then
\r
567 tenv = worldedit.quene_aliasenv
\r
569 local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)
\r
570 minetest.chat_send_player(name, count .. " nodes moved", false)
\r
574 minetest.register_chatcommand("/stack", {
\r
575 params = "x/y/z/? <count>",
\r
576 description = "Stack the current WorldEdit region along the x/y/z/? axis <count> times",
\r
577 privs = {worldedit=true},
\r
578 func = function(name, param)
\r
579 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
580 if pos1 == nil or pos2 == nil then
\r
581 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
585 local found, _, axis, count = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
586 if found == nil then
\r
587 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
590 if axis == "?" then
\r
591 axis, sign = worldedit.player_axis(name)
\r
592 count = count * sign
\r
595 local tenv = minetest.env
\r
596 if worldedit.ENABLE_QUEUE then
\r
597 tenv = worldedit.quene_aliasenv
\r
599 local count = worldedit.stack(pos1, pos2, axis, tonumber(count), tenv)
\r
600 minetest.chat_send_player(name, count .. " nodes stacked", false)
\r
604 minetest.register_chatcommand("/transpose", {
\r
605 params = "x/y/z/? x/y/z/?",
\r
606 description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",
\r
607 privs = {worldedit=true},
\r
608 func = function(name, param)
\r
609 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
610 if pos1 == nil or pos2 == nil then
\r
611 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
615 local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")
\r
616 if found == nil then
\r
617 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
620 if axis1 == "?" then
\r
621 axis1 = worldedit.player_axis(name)
\r
623 if axis2 == "?" then
\r
624 axis2 = worldedit.player_axis(name)
\r
626 if axis1 == axis2 then
\r
627 minetest.chat_send_player(name, "Invalid usage: axes are the same", false)
\r
631 local tenv = minetest.env
\r
632 if worldedit.ENABLE_QUEUE then
\r
633 tenv = worldedit.quene_aliasenv
\r
635 local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, tenv)
\r
637 --reset markers to transposed positions
\r
638 worldedit.pos1[name] = pos1
\r
639 worldedit.pos2[name] = pos2
\r
640 worldedit.mark_pos1(name)
\r
641 worldedit.mark_pos2(name)
\r
643 minetest.chat_send_player(name, count .. " nodes transposed", false)
\r
647 minetest.register_chatcommand("/flip", {
\r
648 params = "x/y/z/?",
\r
649 description = "Flip the current WorldEdit region along the x/y/z/? axis",
\r
650 privs = {worldedit=true},
\r
651 func = function(name, param)
\r
652 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
653 if pos1 == nil or pos2 == nil then
\r
654 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
658 if param == "?" then
\r
659 param = worldedit.player_axis(name)
\r
661 if param ~= "x" and param ~= "y" and param ~= "z" then
\r
662 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
666 local tenv = minetest.env
\r
667 if worldedit.ENABLE_QUEUE then
\r
668 tenv = worldedit.quene_aliasenv
\r
670 local count = worldedit.flip(pos1, pos2, param, tenv)
\r
671 minetest.chat_send_player(name, count .. " nodes flipped", false)
\r
675 minetest.register_chatcommand("/rotate", {
\r
676 params = "<axis> <angle>",
\r
677 description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",
\r
678 privs = {worldedit=true},
\r
679 func = function(name, param)
\r
680 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
681 if pos1 == nil or pos2 == nil then
\r
682 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
686 local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
687 if found == nil then
\r
688 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
691 if axis == "?" then
\r
692 axis = worldedit.player_axis(name)
\r
694 if angle % 90 ~= 0 then
\r
695 minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90", false)
\r
699 local tenv = minetest.env
\r
700 if worldedit.ENABLE_QUEUE then
\r
701 tenv = worldedit.quene_aliasenv
\r
703 local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle, tenv)
\r
705 --reset markers to rotated positions
\r
706 worldedit.pos1[name] = pos1
\r
707 worldedit.pos2[name] = pos2
\r
708 worldedit.mark_pos1(name)
\r
709 worldedit.mark_pos2(name)
\r
711 minetest.chat_send_player(name, count .. " nodes rotated", false)
\r
715 minetest.register_chatcommand("/orient", {
\r
716 params = "<angle>",
\r
717 description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)",
\r
718 privs = {worldedit=true},
\r
719 func = function(name, param)
\r
720 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
721 if pos1 == nil or pos2 == nil then
\r
722 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
726 local found, _, angle = param:find("^([+-]?%d+)$")
\r
727 if found == nil then
\r
728 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
731 if angle % 90 ~= 0 then
\r
732 minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90", false)
\r
736 local tenv = minetest.env
\r
737 if worldedit.ENABLE_QUEUE then
\r
738 tenv = worldedit.quene_aliasenv
\r
740 local count = worldedit.orient(pos1, pos2, angle, tenv)
\r
742 minetest.chat_send_player(name, count .. " nodes oriented", false)
\r
746 minetest.register_chatcommand("/fixlight", {
\r
748 description = "Fix the lighting in the current WorldEdit region",
\r
749 privs = {worldedit=true},
\r
750 func = function(name, param)
\r
751 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
752 if pos1 == nil or pos2 == nil then
\r
753 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
757 local tenv = minetest.env
\r
758 if worldedit.ENABLE_QUEUE then
\r
759 tenv = worldedit.quene_aliasenv
\r
761 local count = worldedit.fixlight(pos1, pos2, tenv)
\r
762 minetest.chat_send_player(name, count .. " nodes updated", false)
\r
766 minetest.register_chatcommand("/hide", {
\r
768 description = "Hide all nodes in the current WorldEdit region non-destructively",
\r
769 privs = {worldedit=true},
\r
770 func = function(name, param)
\r
771 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
772 if pos1 == nil or pos2 == nil then
\r
773 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
777 local tenv = minetest.env
\r
778 if worldedit.ENABLE_QUEUE then
\r
779 tenv = worldedit.quene_aliasenv
\r
781 local count = worldedit.hide(pos1, pos2, tenv)
\r
782 minetest.chat_send_player(name, count .. " nodes hidden", false)
\r
786 minetest.register_chatcommand("/suppress", {
\r
788 description = "Suppress all <node> in the current WorldEdit region non-destructively",
\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 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
797 if param == "" or not worldedit.node_is_valid(param) then
\r
798 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
802 local tenv = minetest.env
\r
803 if worldedit.ENABLE_QUEUE then
\r
804 tenv = worldedit.quene_aliasenv
\r
806 local count = worldedit.suppress(pos1, pos2, param, tenv)
\r
807 minetest.chat_send_player(name, count .. " nodes suppressed", false)
\r
811 minetest.register_chatcommand("/highlight", {
\r
813 description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",
\r
814 privs = {worldedit=true},
\r
815 func = function(name, param)
\r
816 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
817 if pos1 == nil or pos2 == nil then
\r
818 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
822 if param == "" or not worldedit.node_is_valid(param) then
\r
823 minetest.chat_send_player(name, "Invalid node name: " .. param, false)
\r
827 local tenv = minetest.env
\r
828 if worldedit.ENABLE_QUEUE then
\r
829 tenv = worldedit.quene_aliasenv
\r
831 local count = worldedit.highlight(pos1, pos2, param, tenv)
\r
832 minetest.chat_send_player(name, count .. " nodes highlighted", false)
\r
836 minetest.register_chatcommand("/restore", {
\r
838 description = "Restores nodes hidden with WorldEdit in the current WorldEdit region",
\r
839 privs = {worldedit=true},
\r
840 func = function(name, param)
\r
841 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
842 if pos1 == nil or pos2 == nil then
\r
843 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
847 local tenv = minetest.env
\r
848 if worldedit.ENABLE_QUEUE then
\r
849 tenv = worldedit.quene_aliasenv
\r
851 local count = worldedit.restore(pos1, pos2, tenv)
\r
852 minetest.chat_send_player(name, count .. " nodes restored", false)
\r
856 minetest.register_chatcommand("/save", {
\r
858 description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",
\r
859 privs = {worldedit=true},
\r
860 func = function(name, param)
\r
861 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
862 if pos1 == nil or pos2 == nil then
\r
863 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
867 if param == "" then
\r
868 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
872 local result, count = worldedit.serialize(pos1, pos2)
\r
874 local path = minetest.get_worldpath() .. "/schems"
\r
875 local filename = path .. "/" .. param .. ".we"
\r
876 os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
\r
877 local file, err = io.open(filename, "wb")
\r
879 minetest.chat_send_player(name, "Could not save file to \"" .. filename .. "\"", false)
\r
886 minetest.chat_send_player(name, count .. " nodes saved", false)
\r
890 minetest.register_chatcommand("/allocate", {
\r
892 description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",
\r
893 privs = {worldedit=true},
\r
894 func = function(name, param)
\r
895 local pos1 = worldedit.pos1[name]
\r
896 if pos1 == nil then
\r
897 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
901 if param == "" then
\r
902 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
906 local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"
\r
907 local file, err = io.open(filename, "rb")
\r
909 minetest.chat_send_player(name, "Could not open file \"" .. filename .. "\"", false)
\r
912 local value = file:read("*a")
\r
915 if worldedit.valueversion(value) == 0 then --unknown version
\r
916 minetest.chat_send_player(name, "Invalid file: file is invalid or created with newer version of WorldEdit", false)
\r
919 local nodepos1, nodepos2, count = worldedit.allocate(pos1, value)
\r
921 worldedit.pos1[name] = nodepos1
\r
922 worldedit.mark_pos1(name)
\r
923 worldedit.pos2[name] = nodepos2
\r
924 worldedit.mark_pos2(name)
\r
926 minetest.chat_send_player(name, count .. " nodes allocated", false)
\r
930 minetest.register_chatcommand("/load", {
\r
932 description = "Load nodes from \"(world folder)/schems/<file>[.we[m]]\" with position 1 of the current WorldEdit region as the origin",
\r
933 privs = {worldedit=true},
\r
934 func = function(name, param)
\r
935 local pos1 = worldedit.pos1[name]
\r
936 if pos1 == nil then
\r
937 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
941 if param == "" then
\r
942 minetest.chat_send_player(name, "Invalid usage: " .. param, false)
\r
946 --find the file in the world path
\r
947 local testpaths = {
\r
948 minetest.get_worldpath() .. "/schems/" .. param,
\r
949 minetest.get_worldpath() .. "/schems/" .. param .. ".we",
\r
950 minetest.get_worldpath() .. "/schems/" .. param .. ".wem",
\r
953 for index, path in ipairs(testpaths) do
\r
954 file, err = io.open(path, "rb")
\r
960 minetest.chat_send_player(name, "Could not open file \"" .. param .. "\"", false)
\r
963 local value = file:read("*a")
\r
966 if worldedit.valueversion(value) == 0 then --unknown version
\r
967 minetest.chat_send_player(name, "Invalid file: file is invalid or created with newer version of WorldEdit", false)
\r
971 local tenv = minetest.env
\r
972 if worldedit.ENABLE_QUEUE then
\r
973 tenv = worldedit.quene_aliasenv
\r
975 local count = worldedit.deserialize(pos1, value, tenv)
\r
977 minetest.chat_send_player(name, count .. " nodes loaded", false)
\r
981 minetest.register_chatcommand("/lua", {
\r
983 description = "Executes <code> as a Lua chunk in the global namespace",
\r
984 privs = {worldedit=true, server=true},
\r
985 func = function(name, param)
\r
986 local err = worldedit.lua(param)
\r
988 minetest.chat_send_player(name, "Code error: " .. err, false)
\r
990 minetest.chat_send_player(name, "Code successfully executed", false)
\r
995 minetest.register_chatcommand("/luatransform", {
\r
997 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
998 privs = {worldedit=true, server=true},
\r
999 func = function(name, param)
\r
1000 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
1001 if pos1 == nil or pos2 == nil then
\r
1002 minetest.chat_send_player(name, "No WorldEdit region selected", false)
\r
1006 local err = worldedit.luatransform(pos1, pos2, param)
\r
1008 minetest.chat_send_player(name, "Code error: " .. err, false)
\r
1010 minetest.chat_send_player(name, "Code successfully executed", false)
\r