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 worldedit.player_notify = function(name, message)
\r
11 minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)
\r
14 --determines whether `nodename` is a valid node name, returning a boolean
\r
15 worldedit.normalize_nodename = function(nodename)
\r
16 if minetest.registered_nodes[nodename] then --directly found node name
\r
18 elseif minetest.registered_nodes["default:" .. nodename] then --found node name in default
\r
19 return "default:" .. nodename
\r
21 for key, value in pairs(minetest.registered_nodes) do
\r
22 if key:find(":" .. nodename, 1, true) then --found in mod
\r
26 for key, value in pairs(minetest.registered_nodes) do
\r
27 if value.description:lower() == nodename:lower() then --found in description
\r
34 --determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
\r
35 worldedit.player_axis = function(name)
\r
36 local dir = minetest.env:get_player_by_name(name):get_look_dir()
\r
37 local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
\r
40 return "x", dir.x > 0 and 1 or -1
\r
43 return "y", dir.y > 0 and 1 or -1
\r
45 return "z", dir.z > 0 and 1 or -1
\r
48 minetest.register_chatcommand("/reset", {
\r
50 description = "Reset the region so that it is empty",
\r
51 privs = {worldedit=true},
\r
52 func = function(name, param)
\r
53 worldedit.pos1[name] = nil
\r
54 worldedit.pos2[name] = nil
\r
55 worldedit.mark_pos1(name)
\r
56 worldedit.mark_pos2(name)
\r
57 worldedit.set_pos[name] = nil
\r
58 worldedit.player_notify(name, "region reset")
\r
62 minetest.register_chatcommand("/mark", {
\r
64 description = "Show markers at the region positions",
\r
65 privs = {worldedit=true},
\r
66 func = function(name, param)
\r
67 worldedit.mark_pos1(name)
\r
68 worldedit.mark_pos2(name)
\r
69 worldedit.player_notify(name, "region marked")
\r
73 minetest.register_chatcommand("/unmark", {
\r
75 description = "Hide markers if currently shown",
\r
76 privs = {worldedit=true},
\r
77 func = function(name, param)
\r
78 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
79 worldedit.pos1[name] = nil
\r
80 worldedit.pos2[name] = nil
\r
81 worldedit.mark_pos1(name)
\r
82 worldedit.mark_pos2(name)
\r
83 worldedit.pos1[name] = pos1
\r
84 worldedit.pos2[name] = pos2
\r
85 worldedit.player_notify(name, "region unmarked")
\r
89 minetest.register_chatcommand("/pos1", {
\r
91 description = "Set WorldEdit region position 1 to the player's location",
\r
92 privs = {worldedit=true},
\r
93 func = function(name, param)
\r
94 local pos = minetest.env:get_player_by_name(name):getpos()
\r
95 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
96 worldedit.pos1[name] = pos
\r
97 worldedit.mark_pos1(name)
\r
98 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
102 minetest.register_chatcommand("/pos2", {
\r
104 description = "Set WorldEdit region position 2 to the player's location",
\r
105 privs = {worldedit=true},
\r
106 func = function(name, param)
\r
107 local pos = minetest.env:get_player_by_name(name):getpos()
\r
108 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
109 worldedit.pos2[name] = pos
\r
110 worldedit.mark_pos2(name)
\r
111 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
\r
115 minetest.register_chatcommand("/p", {
\r
116 params = "set/set1/set2/get",
\r
117 description = "Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region",
\r
118 privs = {worldedit=true},
\r
119 func = function(name, param)
\r
120 if param == "set" then --set both WorldEdit positions
\r
121 worldedit.set_pos[name] = "pos1"
\r
122 worldedit.player_notify(name, "select positions by punching two nodes")
\r
123 elseif param == "set1" then --set WorldEdit position 1
\r
124 worldedit.set_pos[name] = "pos1only"
\r
125 worldedit.player_notify(name, "select position 1 by punching a node")
\r
126 elseif param == "set2" then --set WorldEdit position 2
\r
127 worldedit.set_pos[name] = "pos2"
\r
128 worldedit.player_notify(name, "select position 2 by punching a node")
\r
129 elseif param == "get" then --display current WorldEdit positions
\r
130 if worldedit.pos1[name] ~= nil then
\r
131 worldedit.player_notify(name, "position 1: " .. minetest.pos_to_string(worldedit.pos1[name]))
\r
133 worldedit.player_notify(name, "position 1 not set")
\r
135 if worldedit.pos2[name] ~= nil then
\r
136 worldedit.player_notify(name, "position 2: " .. minetest.pos_to_string(worldedit.pos2[name]))
\r
138 worldedit.player_notify(name, "position 2 not set")
\r
141 worldedit.player_notify(name, "unknown subcommand: " .. param)
\r
146 minetest.register_on_punchnode(function(pos, node, puncher)
\r
147 local name = puncher:get_player_name()
\r
148 if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position
\r
149 if worldedit.set_pos[name] == "pos1" then --setting position 1
\r
150 worldedit.pos1[name] = pos
\r
151 worldedit.mark_pos1(name)
\r
152 worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation
\r
153 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
154 elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only
\r
155 worldedit.pos1[name] = pos
\r
156 worldedit.mark_pos1(name)
\r
157 worldedit.set_pos[name] = nil --finished setting positions
\r
158 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
159 elseif worldedit.set_pos[name] == "pos2" then --setting position 2
\r
160 worldedit.pos2[name] = pos
\r
161 worldedit.mark_pos2(name)
\r
162 worldedit.set_pos[name] = nil --finished setting positions
\r
163 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
\r
168 minetest.register_chatcommand("/volume", {
\r
170 description = "Display the volume of the current WorldEdit region",
\r
171 privs = {worldedit=true},
\r
172 func = function(name, param)
\r
173 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
174 if pos1 == nil or pos2 == nil then
\r
175 worldedit.player_notify(name, "no region selected")
\r
179 local volume = worldedit.volume(pos1, pos2)
\r
180 worldedit.player_notify(name, "current region has a volume of " .. volume .. " nodes (" .. pos2.x - pos1.x .. "*" .. pos2.y - pos1.y .. "*" .. pos2.z - pos1.z .. ")")
\r
184 minetest.register_chatcommand("/set", {
\r
186 description = "Set the current WorldEdit region to <node>",
\r
187 privs = {worldedit=true},
\r
188 func = function(name, param)
\r
189 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
190 if pos1 == nil or pos2 == nil then
\r
191 worldedit.player_notify(name, "no region selected")
\r
195 local node = worldedit.normalize_nodename(param)
\r
196 if param == "" or not node then
\r
197 worldedit.player_notify(name, "invalid node name: " .. param)
\r
201 local tenv = minetest.env
\r
202 if worldedit.ENABLE_QUEUE then
\r
203 tenv = worldedit.queue_aliasenv
\r
206 local count = worldedit.set(pos1, pos2, node, tenv)
\r
207 worldedit.player_notify(name, count .. " nodes set")
\r
211 minetest.register_chatcommand("/replace", {
\r
212 params = "<search node> <replace node>",
\r
213 description = "Replace all instances of <search node> with <replace node> in the current WorldEdit region",
\r
214 privs = {worldedit=true},
\r
215 func = function(name, param)
\r
216 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
217 if pos1 == nil or pos2 == nil then
\r
218 worldedit.player_notify(name, "no region selected")
\r
222 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
\r
223 if found == nil then
\r
224 worldedit.player_notify(name, "invalid usage: " .. param)
\r
227 local newsearchnode = worldedit.normalize_nodename(searchnode)
\r
228 if not newsearchnode then
\r
229 worldedit.player_notify(name, "invalid search node name: " .. searchnode)
\r
232 local newreplacenode = worldedit.normalize_nodename(replacenode)
\r
233 if not newreplacenode then
\r
234 worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
\r
238 local tenv = minetest.env
\r
239 if worldedit.ENABLE_QUEUE then
\r
240 tenv = worldedit.queue_aliasenv
\r
242 local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode, tenv)
\r
243 worldedit.player_notify(name, count .. " nodes replaced")
\r
247 minetest.register_chatcommand("/replaceinverse", {
\r
248 params = "<search node> <replace node>",
\r
249 description = "Replace all nodes other than <search node> with <replace node> in the current WorldEdit region",
\r
250 privs = {worldedit=true},
\r
251 func = function(name, param)
\r
252 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
253 if pos1 == nil or pos2 == nil then
\r
254 worldedit.player_notify(name, "no region selected")
\r
258 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
\r
259 if found == nil then
\r
260 worldedit.player_notify(name, "invalid usage: " .. param)
\r
263 local newsearchnode = worldedit.normalize_nodename(searchnode)
\r
264 if not newsearchnode then
\r
265 worldedit.player_notify(name, "invalid search node name: " .. searchnode)
\r
268 local newreplacenode = worldedit.normalize_nodename(replacenode)
\r
269 if not newreplacenode then
\r
270 worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
\r
274 local tenv = minetest.env
\r
275 if worldedit.ENABLE_QUEUE then
\r
276 tenv = worldedit.queue_aliasenv
\r
278 local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode, tenv)
\r
279 worldedit.player_notify(name, count .. " nodes replaced")
\r
283 minetest.register_chatcommand("/hollowsphere", {
\r
284 params = "<radius> <node>",
\r
285 description = "Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
286 privs = {worldedit=true},
\r
287 func = function(name, param)
\r
288 local pos = worldedit.pos1[name]
\r
290 worldedit.player_notify(name, "no region selected")
\r
294 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
295 if found == nil then
\r
296 worldedit.player_notify(name, "invalid usage: " .. param)
\r
299 local node = worldedit.normalize_nodename(nodename)
\r
301 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
305 local tenv = minetest.env
\r
306 if worldedit.ENABLE_QUEUE then
\r
307 tenv = worldedit.queue_aliasenv
\r
309 local count = worldedit.hollow_sphere(pos, tonumber(radius), node, tenv)
\r
310 worldedit.player_notify(name, count .. " nodes added")
\r
314 minetest.register_chatcommand("/sphere", {
\r
315 params = "<radius> <node>",
\r
316 description = "Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
317 privs = {worldedit=true},
\r
318 func = function(name, param)
\r
319 local pos = worldedit.pos1[name]
\r
321 worldedit.player_notify(name, "no region selected")
\r
325 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
326 if found == nil then
\r
327 worldedit.player_notify(name, "invalid usage: " .. param)
\r
330 local node = worldedit.normalize_nodename(nodename)
\r
332 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
336 local tenv = minetest.env
\r
337 if worldedit.ENABLE_QUEUE then
\r
338 tenv = worldedit.queue_aliasenv
\r
340 local count = worldedit.sphere(pos, tonumber(radius), node, tenv)
\r
341 worldedit.player_notify(name, count .. " nodes added")
\r
345 minetest.register_chatcommand("/hollowdome", {
\r
346 params = "<radius> <node>",
\r
347 description = "Add hollow dome at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
348 privs = {worldedit=true},
\r
349 func = function(name, param)
\r
350 local pos = worldedit.pos1[name]
\r
352 worldedit.player_notify(name, "no region selected")
\r
356 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
357 if found == nil then
\r
358 worldedit.player_notify(name, "invalid usage: " .. param)
\r
361 local node = worldedit.normalize_nodename(nodename)
\r
363 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
367 local tenv = minetest.env
\r
368 if worldedit.ENABLE_QUEUE then
\r
369 tenv = worldedit.queue_aliasenv
\r
371 local count = worldedit.hollow_dome(pos, tonumber(radius), node, tenv)
\r
372 worldedit.player_notify(name, count .. " nodes added")
\r
376 minetest.register_chatcommand("/dome", {
\r
377 params = "<radius> <node>",
\r
378 description = "Add dome at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
379 privs = {worldedit=true},
\r
380 func = function(name, param)
\r
381 local pos = worldedit.pos1[name]
\r
383 worldedit.player_notify(name, "no region selected")
\r
387 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
388 if found == nil then
\r
389 worldedit.player_notify(name, "invalid usage: " .. param)
\r
392 local node = worldedit.normalize_nodename(nodename)
\r
394 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
398 local tenv = minetest.env
\r
399 if worldedit.ENABLE_QUEUE then
\r
400 tenv = worldedit.queue_aliasenv
\r
402 local count = worldedit.dome(pos, tonumber(radius), node, tenv)
\r
403 worldedit.player_notify(name, count .. " nodes added")
\r
407 minetest.register_chatcommand("/hollowcylinder", {
\r
408 params = "x/y/z/? <length> <radius> <node>",
\r
409 description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
\r
410 privs = {worldedit=true},
\r
411 func = function(name, param)
\r
412 local pos = worldedit.pos1[name]
\r
414 worldedit.player_notify(name, "no region selected")
\r
418 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
\r
419 if found == nil then
\r
420 worldedit.player_notify(name, "invalid usage: " .. param)
\r
423 if axis == "?" then
\r
424 axis, sign = worldedit.player_axis(name)
\r
425 length = length * sign
\r
427 local node = worldedit.normalize_nodename(nodename)
\r
429 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
433 local tenv = minetest.env
\r
434 if worldedit.ENABLE_QUEUE then
\r
435 tenv = worldedit.queue_aliasenv
\r
437 local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)
\r
438 worldedit.player_notify(name, count .. " nodes added")
\r
442 minetest.register_chatcommand("/cylinder", {
\r
443 params = "x/y/z/? <length> <radius> <node>",
\r
444 description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
\r
445 privs = {worldedit=true},
\r
446 func = function(name, param)
\r
447 local pos = worldedit.pos1[name]
\r
449 worldedit.player_notify(name, "no region selected")
\r
453 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
\r
454 if found == nil then
\r
455 worldedit.player_notify(name, "invalid usage: " .. param)
\r
458 if axis == "?" then
\r
459 axis, sign = worldedit.player_axis(name)
\r
460 length = length * sign
\r
462 local node = worldedit.normalize_nodename(nodename)
\r
464 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
468 local tenv = minetest.env
\r
469 if worldedit.ENABLE_QUEUE then
\r
470 tenv = worldedit.queue_aliasenv
\r
472 local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)
\r
473 worldedit.player_notify(name, count .. " nodes added")
\r
477 minetest.register_chatcommand("/pyramid", {
\r
478 params = "<height> <node>",
\r
479 description = "Add pyramid at WorldEdit position 1 with height <height>, composed of <node>",
\r
480 privs = {worldedit=true},
\r
481 func = function(name, param)
\r
482 local pos = worldedit.pos1[name]
\r
484 worldedit.player_notify(name, "no region selected")
\r
488 local found, _, size, nodename = param:find("(%d+)%s+(.+)$")
\r
489 if found == nil then
\r
490 worldedit.player_notify(name, "invalid usage: " .. param)
\r
493 local node = worldedit.normalize_nodename(nodename)
\r
495 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
499 local tenv = minetest.env
\r
500 if worldedit.ENABLE_QUEUE then
\r
501 tenv = worldedit.queue_aliasenv
\r
503 local count = worldedit.pyramid(pos, tonumber(size), node, tenv)
\r
504 worldedit.player_notify(name, count .. " nodes added")
\r
508 minetest.register_chatcommand("/spiral", {
\r
509 params = "<width> <height> <space> <node>",
\r
510 description = "Add spiral at WorldEdit position 1 with width <width>, height <height>, space between walls <space>, composed of <node>",
\r
511 privs = {worldedit=true},
\r
512 func = function(name, param)
\r
513 local pos = worldedit.pos1[name]
\r
515 worldedit.player_notify(name, "no region selected")
\r
519 local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
\r
520 if found == nil then
\r
521 worldedit.player_notify(name, "invalid usage: " .. param)
\r
524 local node = worldedit.normalize_nodename(nodename)
\r
526 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
530 local tenv = minetest.env
\r
531 if worldedit.ENABLE_QUEUE then
\r
532 tenv = worldedit.queue_aliasenv
\r
534 local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), node, tenv)
\r
535 worldedit.player_notify(name, count .. " nodes added")
\r
539 minetest.register_chatcommand("/copy", {
\r
540 params = "x/y/z/? <amount>",
\r
541 description = "Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
542 privs = {worldedit=true},
\r
543 func = function(name, param)
\r
544 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
545 if pos1 == nil or pos2 == nil then
\r
546 worldedit.player_notify(name, "no region selected")
\r
550 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
551 if found == nil then
\r
552 worldedit.player_notify(name, "invalid usage: " .. param)
\r
555 if axis == "?" then
\r
556 axis, sign = worldedit.player_axis(name)
\r
557 amount = amount * sign
\r
560 local tenv = minetest.env
\r
561 if worldedit.ENABLE_QUEUE then
\r
562 tenv = worldedit.queue_aliasenv
\r
564 local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)
\r
565 worldedit.player_notify(name, count .. " nodes copied")
\r
569 minetest.register_chatcommand("/move", {
\r
570 params = "x/y/z/? <amount>",
\r
571 description = "Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
572 privs = {worldedit=true},
\r
573 func = function(name, param)
\r
574 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
575 if pos1 == nil or pos2 == nil then
\r
576 worldedit.player_notify(name, "no region selected")
\r
580 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
581 if found == nil then
\r
582 worldedit.player_notify(name, "invalid usage: " .. param)
\r
585 if axis == "?" then
\r
586 axis, sign = worldedit.player_axis(name)
\r
587 amount = amount * sign
\r
590 local tenv = minetest.env
\r
591 if worldedit.ENABLE_QUEUE then
\r
592 tenv = worldedit.queue_aliasenv
\r
594 local count = worldedit.move(pos1, pos2, axis, tonumber(amount), tenv)
\r
596 pos1[axis] = pos1[axis] + amount
\r
597 pos2[axis] = pos2[axis] + amount
\r
598 worldedit.mark_pos1(name)
\r
599 worldedit.mark_pos2(name)
\r
600 worldedit.player_notify(name, count .. " nodes moved")
\r
604 minetest.register_chatcommand("/stack", {
\r
605 params = "x/y/z/? <count>",
\r
606 description = "Stack the current WorldEdit region along the x/y/z/? axis <count> times",
\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 worldedit.player_notify(name, "no region selected")
\r
615 local found, _, axis, count = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
616 if found == nil then
\r
617 worldedit.player_notify(name, "invalid usage: " .. param)
\r
620 if axis == "?" then
\r
621 axis, sign = worldedit.player_axis(name)
\r
622 count = count * sign
\r
625 local tenv = minetest.env
\r
626 if worldedit.ENABLE_QUEUE then
\r
627 tenv = worldedit.queue_aliasenv
\r
629 local count = worldedit.stack(pos1, pos2, axis, tonumber(count), tenv)
\r
630 worldedit.player_notify(name, count .. " nodes stacked")
\r
634 minetest.register_chatcommand("/transpose", {
\r
635 params = "x/y/z/? x/y/z/?",
\r
636 description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",
\r
637 privs = {worldedit=true},
\r
638 func = function(name, param)
\r
639 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
640 if pos1 == nil or pos2 == nil then
\r
641 worldedit.player_notify(name, "no region selected")
\r
645 local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")
\r
646 if found == nil then
\r
647 worldedit.player_notify(name, "invalid usage: " .. param)
\r
650 if axis1 == "?" then
\r
651 axis1 = worldedit.player_axis(name)
\r
653 if axis2 == "?" then
\r
654 axis2 = worldedit.player_axis(name)
\r
656 if axis1 == axis2 then
\r
657 worldedit.player_notify(name, "invalid usage: axes must be different")
\r
661 local tenv = minetest.env
\r
662 if worldedit.ENABLE_QUEUE then
\r
663 tenv = worldedit.queue_aliasenv
\r
665 local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, tenv)
\r
667 --reset markers to transposed positions
\r
668 worldedit.pos1[name] = pos1
\r
669 worldedit.pos2[name] = pos2
\r
670 worldedit.mark_pos1(name)
\r
671 worldedit.mark_pos2(name)
\r
673 worldedit.player_notify(name, count .. " nodes transposed")
\r
677 minetest.register_chatcommand("/flip", {
\r
678 params = "x/y/z/?",
\r
679 description = "Flip the current WorldEdit region along the x/y/z/? axis",
\r
680 privs = {worldedit=true},
\r
681 func = function(name, param)
\r
682 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
683 if pos1 == nil or pos2 == nil then
\r
684 worldedit.player_notify(name, "no region selected")
\r
688 if param == "?" then
\r
689 param = worldedit.player_axis(name)
\r
691 if param ~= "x" and param ~= "y" and param ~= "z" then
\r
692 worldedit.player_notify(name, "invalid usage: " .. param)
\r
696 local tenv = minetest.env
\r
697 if worldedit.ENABLE_QUEUE then
\r
698 tenv = worldedit.queue_aliasenv
\r
700 local count = worldedit.flip(pos1, pos2, param, tenv)
\r
701 worldedit.player_notify(name, count .. " nodes flipped")
\r
705 minetest.register_chatcommand("/rotate", {
\r
706 params = "<axis> <angle>",
\r
707 description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",
\r
708 privs = {worldedit=true},
\r
709 func = function(name, param)
\r
710 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
711 if pos1 == nil or pos2 == nil then
\r
712 worldedit.player_notify(name, "no region selected")
\r
716 local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
717 if found == nil then
\r
718 worldedit.player_notify(name, "invalid usage: " .. param)
\r
721 if axis == "?" then
\r
722 axis = worldedit.player_axis(name)
\r
724 if angle % 90 ~= 0 then
\r
725 worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")
\r
729 local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)
\r
731 --reset markers to rotated positions
\r
732 worldedit.pos1[name] = pos1
\r
733 worldedit.pos2[name] = pos2
\r
734 worldedit.mark_pos1(name)
\r
735 worldedit.mark_pos2(name)
\r
737 worldedit.player_notify(name, count .. " nodes rotated")
\r
741 minetest.register_chatcommand("/orient", {
\r
742 params = "<angle>",
\r
743 description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)",
\r
744 privs = {worldedit=true},
\r
745 func = function(name, param)
\r
746 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
747 if pos1 == nil or pos2 == nil then
\r
748 worldedit.player_notify(name, "no region selected")
\r
752 local found, _, angle = param:find("^([+-]?%d+)$")
\r
753 if found == nil then
\r
754 worldedit.player_notify(name, "invalid usage: " .. param)
\r
757 if angle % 90 ~= 0 then
\r
758 worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")
\r
762 local tenv = minetest.env
\r
763 if worldedit.ENABLE_QUEUE then
\r
764 tenv = worldedit.queue_aliasenv
\r
766 local count = worldedit.orient(pos1, pos2, angle, tenv)
\r
768 worldedit.player_notify(name, count .. " nodes oriented")
\r
772 minetest.register_chatcommand("/fixlight", {
\r
774 description = "Fix the lighting in the current WorldEdit region",
\r
775 privs = {worldedit=true},
\r
776 func = function(name, param)
\r
777 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
778 if pos1 == nil or pos2 == nil then
\r
779 worldedit.player_notify(name, "no region selected")
\r
783 local tenv = minetest.env
\r
784 if worldedit.ENABLE_QUEUE then
\r
785 tenv = worldedit.queue_aliasenv
\r
787 local count = worldedit.fixlight(pos1, pos2, tenv)
\r
788 worldedit.player_notify(name, count .. " nodes updated")
\r
792 minetest.register_chatcommand("/hide", {
\r
794 description = "Hide all nodes in the current WorldEdit region non-destructively",
\r
795 privs = {worldedit=true},
\r
796 func = function(name, param)
\r
797 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
798 if pos1 == nil or pos2 == nil then
\r
799 worldedit.player_notify(name, "no region selected")
\r
803 local tenv = minetest.env
\r
804 if worldedit.ENABLE_QUEUE then
\r
805 tenv = worldedit.queue_aliasenv
\r
807 local count = worldedit.hide(pos1, pos2, tenv)
\r
808 worldedit.player_notify(name, count .. " nodes hidden")
\r
812 minetest.register_chatcommand("/suppress", {
\r
814 description = "Suppress all <node> in the current WorldEdit region non-destructively",
\r
815 privs = {worldedit=true},
\r
816 func = function(name, param)
\r
817 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
818 if pos1 == nil or pos2 == nil then
\r
819 worldedit.player_notify(name, "no region selected")
\r
823 local node = worldedit.node_is_valid(param)
\r
824 if param == "" or not node then
\r
825 worldedit.player_notify(name, "invalid node name: " .. param)
\r
829 local tenv = minetest.env
\r
830 if worldedit.ENABLE_QUEUE then
\r
831 tenv = worldedit.queue_aliasenv
\r
833 local count = worldedit.suppress(pos1, pos2, node, tenv)
\r
834 worldedit.player_notify(name, count .. " nodes suppressed")
\r
838 minetest.register_chatcommand("/highlight", {
\r
840 description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",
\r
841 privs = {worldedit=true},
\r
842 func = function(name, param)
\r
843 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
844 if pos1 == nil or pos2 == nil then
\r
845 worldedit.player_notify(name, "no region selected")
\r
849 local node = worldedit.node_is_valid(param)
\r
850 if param == "" or not node then
\r
851 worldedit.player_notify(name, "invalid node name: " .. param)
\r
855 local tenv = minetest.env
\r
856 if worldedit.ENABLE_QUEUE then
\r
857 tenv = worldedit.queue_aliasenv
\r
859 local count = worldedit.highlight(pos1, pos2, node, tenv)
\r
860 worldedit.player_notify(name, count .. " nodes highlighted")
\r
864 minetest.register_chatcommand("/restore", {
\r
866 description = "Restores nodes hidden with WorldEdit in the current WorldEdit region",
\r
867 privs = {worldedit=true},
\r
868 func = function(name, param)
\r
869 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
870 if pos1 == nil or pos2 == nil then
\r
871 worldedit.player_notify(name, "no region selected")
\r
875 local tenv = minetest.env
\r
876 if worldedit.ENABLE_QUEUE then
\r
877 tenv = worldedit.queue_aliasenv
\r
879 local count = worldedit.restore(pos1, pos2, tenv)
\r
880 worldedit.player_notify(name, count .. " nodes restored")
\r
884 minetest.register_chatcommand("/save", {
\r
886 description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",
\r
887 privs = {worldedit=true},
\r
888 func = function(name, param)
\r
889 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
890 if pos1 == nil or pos2 == nil then
\r
891 worldedit.player_notify(name, "no region selected")
\r
895 if param == "" then
\r
896 worldedit.player_notify(name, "invalid usage: " .. param)
\r
900 local result, count = worldedit.serialize(pos1, pos2)
\r
902 local path = minetest.get_worldpath() .. "/schems"
\r
903 local filename = path .. "/" .. param .. ".we"
\r
904 os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
\r
905 local file, err = io.open(filename, "wb")
\r
907 worldedit.player_notify(name, "could not save file to \"" .. filename .. "\"")
\r
914 worldedit.player_notify(name, count .. " nodes saved")
\r
918 minetest.register_chatcommand("/allocate", {
\r
920 description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",
\r
921 privs = {worldedit=true},
\r
922 func = function(name, param)
\r
923 local pos1 = worldedit.pos1[name]
\r
924 if pos1 == nil then
\r
925 worldedit.player_notify(name, "no region selected")
\r
929 if param == "" then
\r
930 worldedit.player_notify(name, "invalid usage: " .. param)
\r
934 local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"
\r
935 local file, err = io.open(filename, "rb")
\r
937 worldedit.player_notify(name, "could not open file \"" .. filename .. "\"")
\r
940 local value = file:read("*a")
\r
943 if worldedit.valueversion(value) == 0 then --unknown version
\r
944 worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
\r
947 local nodepos1, nodepos2, count = worldedit.allocate(pos1, value)
\r
949 worldedit.pos1[name] = nodepos1
\r
950 worldedit.mark_pos1(name)
\r
951 worldedit.pos2[name] = nodepos2
\r
952 worldedit.mark_pos2(name)
\r
954 worldedit.player_notify(name, count .. " nodes allocated")
\r
958 minetest.register_chatcommand("/load", {
\r
960 description = "Load nodes from \"(world folder)/schems/<file>[.we[m]]\" with position 1 of the current WorldEdit region as the origin",
\r
961 privs = {worldedit=true},
\r
962 func = function(name, param)
\r
963 local pos1 = worldedit.pos1[name]
\r
964 if pos1 == nil then
\r
965 worldedit.player_notify(name, "no region selected")
\r
969 if param == "" then
\r
970 worldedit.player_notify(name, "invalid usage: " .. param)
\r
974 --find the file in the world path
\r
975 local testpaths = {
\r
976 minetest.get_worldpath() .. "/schems/" .. param,
\r
977 minetest.get_worldpath() .. "/schems/" .. param .. ".we",
\r
978 minetest.get_worldpath() .. "/schems/" .. param .. ".wem",
\r
981 for index, path in ipairs(testpaths) do
\r
982 file, err = io.open(path, "rb")
\r
988 worldedit.player_notify(name, "could not open file \"" .. param .. "\"")
\r
991 local value = file:read("*a")
\r
994 if worldedit.valueversion(value) == 0 then --unknown version
\r
995 worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
\r
999 local tenv = minetest.env
\r
1000 if worldedit.ENABLE_QUEUE then
\r
1001 tenv = worldedit.queue_aliasenv
\r
1003 local count = worldedit.deserialize(pos1, value, tenv)
\r
1005 worldedit.player_notify(name, count .. " nodes loaded")
\r
1009 minetest.register_chatcommand("/lua", {
\r
1010 params = "<code>",
\r
1011 description = "Executes <code> as a Lua chunk in the global namespace",
\r
1012 privs = {worldedit=true, server=true},
\r
1013 func = function(name, param)
\r
1014 local err = worldedit.lua(param)
\r
1016 worldedit.player_notify(name, "code error: " .. err)
\r
1018 worldedit.player_notify(name, "code successfully executed", false)
\r
1023 minetest.register_chatcommand("/luatransform", {
\r
1024 params = "<code>",
\r
1025 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
1026 privs = {worldedit=true, server=true},
\r
1027 func = function(name, param)
\r
1028 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
1029 if pos1 == nil or pos2 == nil then
\r
1030 worldedit.player_notify(name, "no region selected")
\r
1034 local err = worldedit.luatransform(pos1, pos2, param)
\r
1036 worldedit.player_notify(name, "code error: " .. err, false)
\r
1038 worldedit.player_notify(name, "code successfully executed", false)
\r