1 minetest.register_privilege("worldedit", "Can use WorldEdit commands")
\r
3 worldedit.set_pos = {}
\r
7 if minetest.place_schematic then
\r
8 worldedit.prob_pos = {}
\r
9 worldedit.prob_list = {}
\r
12 dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")
\r
14 worldedit.player_notify = function(name, message)
\r
15 minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)
\r
18 --determines whether `nodename` is a valid node name, returning a boolean
\r
19 worldedit.normalize_nodename = function(nodename)
\r
20 local fullname = ItemStack({name=nodename}):get_name() --resolve aliases of node names to full names
\r
21 if minetest.registered_nodes[fullname] then --directly found node name or alias of nodename
\r
24 for key, value in pairs(minetest.registered_nodes) do
\r
25 if key:find(":" .. nodename, 1, true) then --found in mod
\r
29 nodename = nodename:lower() --lowercase both for case insensitive comparison
\r
30 for key, value in pairs(minetest.registered_nodes) do
\r
31 if value.description:lower() == nodename then --found in description
\r
38 --determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
\r
39 worldedit.player_axis = function(name)
\r
40 local dir = minetest.env:get_player_by_name(name):get_look_dir()
\r
41 local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
\r
44 return "x", dir.x > 0 and 1 or -1
\r
47 return "y", dir.y > 0 and 1 or -1
\r
49 return "z", dir.z > 0 and 1 or -1
\r
52 worldedit.inspect = true
\r
54 minetest.register_chatcommand("/inspect", {
\r
55 params = "on/off/1/0/true/false/yes/no/enable/disable",
\r
56 description = "Enable or disable node inspection",
\r
57 privs = {worldedit=true},
\r
58 func = function(name, param)
\r
59 if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" then
\r
60 worldedit.inspect = true
\r
61 worldedit.player_notify(name, "node inspection is now on")
\r
62 elseif param == "off" or param == "0" or param == "false" or param == "no" or param == "disable" then
\r
63 worldedit.inspect = false
\r
64 worldedit.player_notify(name, "node inspection is now off")
\r
66 worldedit.player_notify(name, "invalid usage: " .. param)
\r
71 minetest.register_on_punchnode(function(pos, node, puncher)
\r
72 if worldedit.inspect then
\r
73 message = "node inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"
\r
74 worldedit.player_notify(puncher:get_player_name(), message)
\r
78 minetest.register_chatcommand("/reset", {
\r
80 description = "Reset the region so that it is empty",
\r
81 privs = {worldedit=true},
\r
82 func = function(name, param)
\r
83 worldedit.pos1[name] = nil
\r
84 worldedit.pos2[name] = nil
\r
85 worldedit.mark_pos1(name)
\r
86 worldedit.mark_pos2(name)
\r
87 worldedit.set_pos[name] = nil
\r
88 worldedit.player_notify(name, "region reset")
\r
92 minetest.register_chatcommand("/mark", {
\r
94 description = "Show markers at the region positions",
\r
95 privs = {worldedit=true},
\r
96 func = function(name, param)
\r
97 worldedit.mark_pos1(name)
\r
98 worldedit.mark_pos2(name)
\r
99 worldedit.player_notify(name, "region marked")
\r
103 minetest.register_chatcommand("/unmark", {
\r
105 description = "Hide markers if currently shown",
\r
106 privs = {worldedit=true},
\r
107 func = function(name, param)
\r
108 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
109 worldedit.pos1[name] = nil
\r
110 worldedit.pos2[name] = nil
\r
111 worldedit.mark_pos1(name)
\r
112 worldedit.mark_pos2(name)
\r
113 worldedit.pos1[name] = pos1
\r
114 worldedit.pos2[name] = pos2
\r
115 worldedit.player_notify(name, "region unmarked")
\r
119 minetest.register_chatcommand("/pos1", {
\r
121 description = "Set WorldEdit region position 1 to the player's location",
\r
122 privs = {worldedit=true},
\r
123 func = function(name, param)
\r
124 local pos = minetest.env:get_player_by_name(name):getpos()
\r
125 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
126 worldedit.pos1[name] = pos
\r
127 worldedit.mark_pos1(name)
\r
128 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
132 minetest.register_chatcommand("/pos2", {
\r
134 description = "Set WorldEdit region position 2 to the player's location",
\r
135 privs = {worldedit=true},
\r
136 func = function(name, param)
\r
137 local pos = minetest.env:get_player_by_name(name):getpos()
\r
138 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
139 worldedit.pos2[name] = pos
\r
140 worldedit.mark_pos2(name)
\r
141 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
\r
145 minetest.register_chatcommand("/p", {
\r
146 params = "set/set1/set2/get",
\r
147 description = "Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region",
\r
148 privs = {worldedit=true},
\r
149 func = function(name, param)
\r
150 if param == "set" then --set both WorldEdit positions
\r
151 worldedit.set_pos[name] = "pos1"
\r
152 worldedit.player_notify(name, "select positions by punching two nodes")
\r
153 elseif param == "set1" then --set WorldEdit position 1
\r
154 worldedit.set_pos[name] = "pos1only"
\r
155 worldedit.player_notify(name, "select position 1 by punching a node")
\r
156 elseif param == "set2" then --set WorldEdit position 2
\r
157 worldedit.set_pos[name] = "pos2"
\r
158 worldedit.player_notify(name, "select position 2 by punching a node")
\r
159 elseif param == "get" then --display current WorldEdit positions
\r
160 if worldedit.pos1[name] ~= nil then
\r
161 worldedit.player_notify(name, "position 1: " .. minetest.pos_to_string(worldedit.pos1[name]))
\r
163 worldedit.player_notify(name, "position 1 not set")
\r
165 if worldedit.pos2[name] ~= nil then
\r
166 worldedit.player_notify(name, "position 2: " .. minetest.pos_to_string(worldedit.pos2[name]))
\r
168 worldedit.player_notify(name, "position 2 not set")
\r
171 worldedit.player_notify(name, "unknown subcommand: " .. param)
\r
176 minetest.register_on_punchnode(function(pos, node, puncher)
\r
177 local name = puncher:get_player_name()
\r
178 if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position
\r
179 if worldedit.set_pos[name] == "pos1" then --setting position 1
\r
180 worldedit.pos1[name] = pos
\r
181 worldedit.mark_pos1(name)
\r
182 worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation
\r
183 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
184 elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only
\r
185 worldedit.pos1[name] = pos
\r
186 worldedit.mark_pos1(name)
\r
187 worldedit.set_pos[name] = nil --finished setting positions
\r
188 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
189 elseif worldedit.set_pos[name] == "pos2" then --setting position 2
\r
190 worldedit.pos2[name] = pos
\r
191 worldedit.mark_pos2(name)
\r
192 worldedit.set_pos[name] = nil --finished setting positions
\r
193 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
\r
194 elseif worldedit.set_pos[name] == "prob" then --setting Minetest schematic node probabilities
\r
195 worldedit.prob_pos[name] = pos
\r
196 minetest.show_formspec(puncher:get_player_name(), "prob_val_enter", "field[text;;]")
\r
201 minetest.register_chatcommand("/volume", {
\r
203 description = "Display the volume of the current WorldEdit region",
\r
204 privs = {worldedit=true},
\r
205 func = function(name, param)
\r
206 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
207 if pos1 == nil or pos2 == nil then
\r
208 worldedit.player_notify(name, "no region selected")
\r
212 local volume = worldedit.volume(pos1, pos2)
\r
213 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
217 minetest.register_chatcommand("/set", {
\r
219 description = "Set the current WorldEdit region to <node>",
\r
220 privs = {worldedit=true},
\r
221 func = function(name, param)
\r
222 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
223 if pos1 == nil or pos2 == nil then
\r
224 worldedit.player_notify(name, "no region selected")
\r
228 local node = worldedit.normalize_nodename(param)
\r
229 if param == "" or not node then
\r
230 worldedit.player_notify(name, "invalid node name: " .. param)
\r
234 local count = worldedit.set(pos1, pos2, node)
\r
235 worldedit.player_notify(name, count .. " nodes set")
\r
239 minetest.register_chatcommand("/replace", {
\r
240 params = "<search node> <replace node>",
\r
241 description = "Replace all instances of <search node> with <replace node> in the current WorldEdit region",
\r
242 privs = {worldedit=true},
\r
243 func = function(name, param)
\r
244 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
245 if pos1 == nil or pos2 == nil then
\r
246 worldedit.player_notify(name, "no region selected")
\r
250 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
\r
251 if found == nil then
\r
252 worldedit.player_notify(name, "invalid usage: " .. param)
\r
255 local newsearchnode = worldedit.normalize_nodename(searchnode)
\r
256 if not newsearchnode then
\r
257 worldedit.player_notify(name, "invalid search node name: " .. searchnode)
\r
260 local newreplacenode = worldedit.normalize_nodename(replacenode)
\r
261 if not newreplacenode then
\r
262 worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
\r
266 local tenv = minetest.env
\r
267 if worldedit.ENABLE_QUEUE then
\r
268 tenv = worldedit.queue_aliasenv
\r
270 local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode, tenv)
\r
271 worldedit.player_notify(name, count .. " nodes replaced")
\r
275 minetest.register_chatcommand("/replaceinverse", {
\r
276 params = "<search node> <replace node>",
\r
277 description = "Replace all nodes other than <search node> with <replace node> in the current WorldEdit region",
\r
278 privs = {worldedit=true},
\r
279 func = function(name, param)
\r
280 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
281 if pos1 == nil or pos2 == nil then
\r
282 worldedit.player_notify(name, "no region selected")
\r
286 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
\r
287 if found == nil then
\r
288 worldedit.player_notify(name, "invalid usage: " .. param)
\r
291 local newsearchnode = worldedit.normalize_nodename(searchnode)
\r
292 if not newsearchnode then
\r
293 worldedit.player_notify(name, "invalid search node name: " .. searchnode)
\r
296 local newreplacenode = worldedit.normalize_nodename(replacenode)
\r
297 if not newreplacenode then
\r
298 worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
\r
302 local tenv = minetest.env
\r
303 if worldedit.ENABLE_QUEUE then
\r
304 tenv = worldedit.queue_aliasenv
\r
306 local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode, tenv)
\r
307 worldedit.player_notify(name, count .. " nodes replaced")
\r
311 minetest.register_chatcommand("/hollowsphere", {
\r
312 params = "<radius> <node>",
\r
313 description = "Add hollow sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
314 privs = {worldedit=true},
\r
315 func = function(name, param)
\r
316 local pos = worldedit.pos1[name]
\r
318 worldedit.player_notify(name, "no region selected")
\r
322 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
323 if found == nil then
\r
324 worldedit.player_notify(name, "invalid usage: " .. param)
\r
327 local node = worldedit.normalize_nodename(nodename)
\r
329 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
333 local tenv = minetest.env
\r
334 if worldedit.ENABLE_QUEUE then
\r
335 tenv = worldedit.queue_aliasenv
\r
337 local count = worldedit.hollow_sphere(pos, tonumber(radius), node, tenv)
\r
338 worldedit.player_notify(name, count .. " nodes added")
\r
342 minetest.register_chatcommand("/sphere", {
\r
343 params = "<radius> <node>",
\r
344 description = "Add 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
349 worldedit.player_notify(name, "no region selected")
\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
358 local node = worldedit.normalize_nodename(nodename)
\r
360 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
364 local tenv = minetest.env
\r
365 if worldedit.ENABLE_QUEUE then
\r
366 tenv = worldedit.queue_aliasenv
\r
368 local count = worldedit.sphere(pos, tonumber(radius), node, tenv)
\r
369 worldedit.player_notify(name, count .. " nodes added")
\r
373 minetest.register_chatcommand("/hollowdome", {
\r
374 params = "<radius> <node>",
\r
375 description = "Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
376 privs = {worldedit=true},
\r
377 func = function(name, param)
\r
378 local pos = worldedit.pos1[name]
\r
380 worldedit.player_notify(name, "no region selected")
\r
384 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
385 if found == nil then
\r
386 worldedit.player_notify(name, "invalid usage: " .. param)
\r
389 local node = worldedit.normalize_nodename(nodename)
\r
391 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
395 local tenv = minetest.env
\r
396 if worldedit.ENABLE_QUEUE then
\r
397 tenv = worldedit.queue_aliasenv
\r
399 local count = worldedit.hollow_dome(pos, tonumber(radius), node, tenv)
\r
400 worldedit.player_notify(name, count .. " nodes added")
\r
404 minetest.register_chatcommand("/dome", {
\r
405 params = "<radius> <node>",
\r
406 description = "Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
407 privs = {worldedit=true},
\r
408 func = function(name, param)
\r
409 local pos = worldedit.pos1[name]
\r
411 worldedit.player_notify(name, "no region selected")
\r
415 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
416 if found == nil then
\r
417 worldedit.player_notify(name, "invalid usage: " .. param)
\r
420 local node = worldedit.normalize_nodename(nodename)
\r
422 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
426 local tenv = minetest.env
\r
427 if worldedit.ENABLE_QUEUE then
\r
428 tenv = worldedit.queue_aliasenv
\r
430 local count = worldedit.dome(pos, tonumber(radius), node, tenv)
\r
431 worldedit.player_notify(name, count .. " nodes added")
\r
435 minetest.register_chatcommand("/hollowcylinder", {
\r
436 params = "x/y/z/? <length> <radius> <node>",
\r
437 description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
\r
438 privs = {worldedit=true},
\r
439 func = function(name, param)
\r
440 local pos = worldedit.pos1[name]
\r
442 worldedit.player_notify(name, "no region selected")
\r
446 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
\r
447 if found == nil then
\r
448 worldedit.player_notify(name, "invalid usage: " .. param)
\r
451 if axis == "?" then
\r
452 axis, sign = worldedit.player_axis(name)
\r
453 length = length * sign
\r
455 local node = worldedit.normalize_nodename(nodename)
\r
457 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
461 local tenv = minetest.env
\r
462 if worldedit.ENABLE_QUEUE then
\r
463 tenv = worldedit.queue_aliasenv
\r
465 local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)
\r
466 worldedit.player_notify(name, count .. " nodes added")
\r
470 minetest.register_chatcommand("/cylinder", {
\r
471 params = "x/y/z/? <length> <radius> <node>",
\r
472 description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
\r
473 privs = {worldedit=true},
\r
474 func = function(name, param)
\r
475 local pos = worldedit.pos1[name]
\r
477 worldedit.player_notify(name, "no region selected")
\r
481 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
\r
482 if found == nil then
\r
483 worldedit.player_notify(name, "invalid usage: " .. param)
\r
486 if axis == "?" then
\r
487 axis, sign = worldedit.player_axis(name)
\r
488 length = length * sign
\r
490 local node = worldedit.normalize_nodename(nodename)
\r
492 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
496 local tenv = minetest.env
\r
497 if worldedit.ENABLE_QUEUE then
\r
498 tenv = worldedit.queue_aliasenv
\r
500 local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)
\r
501 worldedit.player_notify(name, count .. " nodes added")
\r
505 minetest.register_chatcommand("/pyramid", {
\r
506 params = "<height> <node>",
\r
507 description = "Add pyramid centered at WorldEdit position 1 with height <height>, composed of <node>",
\r
508 privs = {worldedit=true},
\r
509 func = function(name, param)
\r
510 local pos = worldedit.pos1[name]
\r
512 worldedit.player_notify(name, "no region selected")
\r
516 local found, _, size, nodename = param:find("(%d+)%s+(.+)$")
\r
517 if found == nil then
\r
518 worldedit.player_notify(name, "invalid usage: " .. param)
\r
521 local node = worldedit.normalize_nodename(nodename)
\r
523 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
527 local tenv = minetest.env
\r
528 if worldedit.ENABLE_QUEUE then
\r
529 tenv = worldedit.queue_aliasenv
\r
531 local count = worldedit.pyramid(pos, tonumber(size), node, tenv)
\r
532 worldedit.player_notify(name, count .. " nodes added")
\r
536 minetest.register_chatcommand("/spiral", {
\r
537 params = "<width> <height> <space> <node>",
\r
538 description = "Add spiral centered at WorldEdit position 1 with width <width>, height <height>, space between walls <space>, composed of <node>",
\r
539 privs = {worldedit=true},
\r
540 func = function(name, param)
\r
541 local pos = worldedit.pos1[name]
\r
543 worldedit.player_notify(name, "no region selected")
\r
547 local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
\r
548 if found == nil then
\r
549 worldedit.player_notify(name, "invalid usage: " .. param)
\r
552 local node = worldedit.normalize_nodename(nodename)
\r
554 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
558 local tenv = minetest.env
\r
559 if worldedit.ENABLE_QUEUE then
\r
560 tenv = worldedit.queue_aliasenv
\r
562 local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), node, tenv)
\r
563 worldedit.player_notify(name, count .. " nodes added")
\r
567 minetest.register_chatcommand("/copy", {
\r
568 params = "x/y/z/? <amount>",
\r
569 description = "Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
570 privs = {worldedit=true},
\r
571 func = function(name, param)
\r
572 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
573 if pos1 == nil or pos2 == nil then
\r
574 worldedit.player_notify(name, "no region selected")
\r
578 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
579 if found == nil then
\r
580 worldedit.player_notify(name, "invalid usage: " .. param)
\r
583 if axis == "?" then
\r
584 axis, sign = worldedit.player_axis(name)
\r
585 amount = amount * sign
\r
588 local tenv = minetest.env
\r
589 if worldedit.ENABLE_QUEUE then
\r
590 tenv = worldedit.queue_aliasenv
\r
592 local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)
\r
593 worldedit.player_notify(name, count .. " nodes copied")
\r
597 minetest.register_chatcommand("/move", {
\r
598 params = "x/y/z/? <amount>",
\r
599 description = "Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
600 privs = {worldedit=true},
\r
601 func = function(name, param)
\r
602 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
603 if pos1 == nil or pos2 == nil then
\r
604 worldedit.player_notify(name, "no region selected")
\r
608 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
609 if found == nil then
\r
610 worldedit.player_notify(name, "invalid usage: " .. param)
\r
613 if axis == "?" then
\r
614 axis, sign = worldedit.player_axis(name)
\r
615 amount = amount * sign
\r
618 local tenv = minetest.env
\r
619 if worldedit.ENABLE_QUEUE then
\r
620 tenv = worldedit.queue_aliasenv
\r
622 local count = worldedit.move(pos1, pos2, axis, tonumber(amount), tenv)
\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
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
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
648 if axis == "?" then
\r
649 axis, sign = worldedit.player_axis(name)
\r
650 count = count * sign
\r
653 local tenv = minetest.env
\r
654 if worldedit.ENABLE_QUEUE then
\r
655 tenv = worldedit.queue_aliasenv
\r
657 local count = worldedit.stack(pos1, pos2, axis, tonumber(count), tenv)
\r
658 worldedit.player_notify(name, count .. " nodes stacked")
\r
662 minetest.register_chatcommand("/scale", {
\r
663 params = "<factor>",
\r
664 description = "Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin",
\r
665 privs = {worldedit=true},
\r
666 func = function(name, param)
\r
667 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
668 if pos1 == nil or pos2 == nil then
\r
669 worldedit.player_notify(name, "no region selected")
\r
673 local factor = tonumber(param)
\r
674 if not factor or factor ~= math.floor(factor) or factor <= 0 then
\r
675 worldedit.player_notify(name, "invalid scaling factor: " .. param)
\r
678 local tenv = minetest.env
\r
679 if worldedit.ENABLE_QUEUE then
\r
680 tenv = worldedit.queue_aliasenv
\r
682 local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor, tenv)
\r
684 --reset markers to scaled positions
\r
685 worldedit.pos1[name] = pos1
\r
686 worldedit.pos2[name] = pos2
\r
687 worldedit.mark_pos1(name)
\r
688 worldedit.mark_pos2(name)
\r
690 worldedit.player_notify(name, count .. " nodes scaled")
\r
694 minetest.register_chatcommand("/transpose", {
\r
695 params = "x/y/z/? x/y/z/?",
\r
696 description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",
\r
697 privs = {worldedit=true},
\r
698 func = function(name, param)
\r
699 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
700 if pos1 == nil or pos2 == nil then
\r
701 worldedit.player_notify(name, "no region selected")
\r
705 local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")
\r
706 if found == nil then
\r
707 worldedit.player_notify(name, "invalid usage: " .. param)
\r
710 if axis1 == "?" then
\r
711 axis1 = worldedit.player_axis(name)
\r
713 if axis2 == "?" then
\r
714 axis2 = worldedit.player_axis(name)
\r
716 if axis1 == axis2 then
\r
717 worldedit.player_notify(name, "invalid usage: axes must be different")
\r
721 local tenv = minetest.env
\r
722 if worldedit.ENABLE_QUEUE then
\r
723 tenv = worldedit.queue_aliasenv
\r
725 local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, tenv)
\r
727 --reset markers to transposed positions
\r
728 worldedit.pos1[name] = pos1
\r
729 worldedit.pos2[name] = pos2
\r
730 worldedit.mark_pos1(name)
\r
731 worldedit.mark_pos2(name)
\r
733 worldedit.player_notify(name, count .. " nodes transposed")
\r
737 minetest.register_chatcommand("/flip", {
\r
738 params = "x/y/z/?",
\r
739 description = "Flip the current WorldEdit region along the x/y/z/? axis",
\r
740 privs = {worldedit=true},
\r
741 func = function(name, param)
\r
742 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
743 if pos1 == nil or pos2 == nil then
\r
744 worldedit.player_notify(name, "no region selected")
\r
748 if param == "?" then
\r
749 param = worldedit.player_axis(name)
\r
751 if param ~= "x" and param ~= "y" and param ~= "z" then
\r
752 worldedit.player_notify(name, "invalid usage: " .. param)
\r
756 local tenv = minetest.env
\r
757 if worldedit.ENABLE_QUEUE then
\r
758 tenv = worldedit.queue_aliasenv
\r
760 local count = worldedit.flip(pos1, pos2, param, tenv)
\r
761 worldedit.player_notify(name, count .. " nodes flipped")
\r
765 minetest.register_chatcommand("/rotate", {
\r
766 params = "<axis> <angle>",
\r
767 description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",
\r
768 privs = {worldedit=true},
\r
769 func = function(name, param)
\r
770 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
771 if pos1 == nil or pos2 == nil then
\r
772 worldedit.player_notify(name, "no region selected")
\r
776 local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
777 if found == nil then
\r
778 worldedit.player_notify(name, "invalid usage: " .. param)
\r
781 if axis == "?" then
\r
782 axis = worldedit.player_axis(name)
\r
784 if angle % 90 ~= 0 then
\r
785 worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")
\r
789 local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)
\r
791 --reset markers to rotated positions
\r
792 worldedit.pos1[name] = pos1
\r
793 worldedit.pos2[name] = pos2
\r
794 worldedit.mark_pos1(name)
\r
795 worldedit.mark_pos2(name)
\r
797 worldedit.player_notify(name, count .. " nodes rotated")
\r
801 minetest.register_chatcommand("/orient", {
\r
802 params = "<angle>",
\r
803 description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)",
\r
804 privs = {worldedit=true},
\r
805 func = function(name, param)
\r
806 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
807 if pos1 == nil or pos2 == nil then
\r
808 worldedit.player_notify(name, "no region selected")
\r
812 local found, _, angle = param:find("^([+-]?%d+)$")
\r
813 if found == nil then
\r
814 worldedit.player_notify(name, "invalid usage: " .. param)
\r
817 if angle % 90 ~= 0 then
\r
818 worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")
\r
822 local tenv = minetest.env
\r
823 if worldedit.ENABLE_QUEUE then
\r
824 tenv = worldedit.queue_aliasenv
\r
826 local count = worldedit.orient(pos1, pos2, angle, tenv)
\r
828 worldedit.player_notify(name, count .. " nodes oriented")
\r
832 minetest.register_chatcommand("/fixlight", {
\r
834 description = "Fix the lighting in the current WorldEdit region",
\r
835 privs = {worldedit=true},
\r
836 func = function(name, param)
\r
837 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
838 if pos1 == nil or pos2 == nil then
\r
839 worldedit.player_notify(name, "no region selected")
\r
843 local tenv = minetest.env
\r
844 if worldedit.ENABLE_QUEUE then
\r
845 tenv = worldedit.queue_aliasenv
\r
847 local count = worldedit.fixlight(pos1, pos2, tenv)
\r
848 worldedit.player_notify(name, count .. " nodes updated")
\r
852 minetest.register_chatcommand("/hide", {
\r
854 description = "Hide all nodes in the current WorldEdit region non-destructively",
\r
855 privs = {worldedit=true},
\r
856 func = function(name, param)
\r
857 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
858 if pos1 == nil or pos2 == nil then
\r
859 worldedit.player_notify(name, "no region selected")
\r
863 local tenv = minetest.env
\r
864 if worldedit.ENABLE_QUEUE then
\r
865 tenv = worldedit.queue_aliasenv
\r
867 local count = worldedit.hide(pos1, pos2, tenv)
\r
868 worldedit.player_notify(name, count .. " nodes hidden")
\r
872 minetest.register_chatcommand("/suppress", {
\r
874 description = "Suppress all <node> in the current WorldEdit region non-destructively",
\r
875 privs = {worldedit=true},
\r
876 func = function(name, param)
\r
877 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
878 if pos1 == nil or pos2 == nil then
\r
879 worldedit.player_notify(name, "no region selected")
\r
883 local node = worldedit.node_is_valid(param)
\r
884 if param == "" or not node then
\r
885 worldedit.player_notify(name, "invalid node name: " .. param)
\r
889 local tenv = minetest.env
\r
890 if worldedit.ENABLE_QUEUE then
\r
891 tenv = worldedit.queue_aliasenv
\r
893 local count = worldedit.suppress(pos1, pos2, node, tenv)
\r
894 worldedit.player_notify(name, count .. " nodes suppressed")
\r
898 minetest.register_chatcommand("/highlight", {
\r
900 description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",
\r
901 privs = {worldedit=true},
\r
902 func = function(name, param)
\r
903 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
904 if pos1 == nil or pos2 == nil then
\r
905 worldedit.player_notify(name, "no region selected")
\r
909 local node = worldedit.node_is_valid(param)
\r
910 if param == "" or not node then
\r
911 worldedit.player_notify(name, "invalid node name: " .. param)
\r
915 local tenv = minetest.env
\r
916 if worldedit.ENABLE_QUEUE then
\r
917 tenv = worldedit.queue_aliasenv
\r
919 local count = worldedit.highlight(pos1, pos2, node, tenv)
\r
920 worldedit.player_notify(name, count .. " nodes highlighted")
\r
924 minetest.register_chatcommand("/restore", {
\r
926 description = "Restores nodes hidden with WorldEdit in the current WorldEdit region",
\r
927 privs = {worldedit=true},
\r
928 func = function(name, param)
\r
929 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
930 if pos1 == nil or pos2 == nil then
\r
931 worldedit.player_notify(name, "no region selected")
\r
935 local tenv = minetest.env
\r
936 if worldedit.ENABLE_QUEUE then
\r
937 tenv = worldedit.queue_aliasenv
\r
939 local count = worldedit.restore(pos1, pos2, tenv)
\r
940 worldedit.player_notify(name, count .. " nodes restored")
\r
944 minetest.register_chatcommand("/save", {
\r
946 description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",
\r
947 privs = {worldedit=true},
\r
948 func = function(name, param)
\r
949 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
950 if pos1 == nil or pos2 == nil then
\r
951 worldedit.player_notify(name, "no region selected")
\r
955 if param == "" then
\r
956 worldedit.player_notify(name, "invalid usage: " .. param)
\r
960 local result, count = worldedit.serialize(pos1, pos2)
\r
962 local path = minetest.get_worldpath() .. "/schems"
\r
963 local filename = path .. "/" .. param .. ".we"
\r
964 os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
\r
965 local file, err = io.open(filename, "wb")
\r
967 worldedit.player_notify(name, "could not save file to \"" .. filename .. "\"")
\r
974 worldedit.player_notify(name, count .. " nodes saved")
\r
978 minetest.register_chatcommand("/allocate", {
\r
980 description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",
\r
981 privs = {worldedit=true},
\r
982 func = function(name, param)
\r
983 local pos1 = worldedit.pos1[name]
\r
984 if pos1 == nil then
\r
985 worldedit.player_notify(name, "no region selected")
\r
989 if param == "" then
\r
990 worldedit.player_notify(name, "invalid usage: " .. param)
\r
994 local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"
\r
995 local file, err = io.open(filename, "rb")
\r
997 worldedit.player_notify(name, "could not open file \"" .. filename .. "\"")
\r
1000 local value = file:read("*a")
\r
1003 if worldedit.valueversion(value) == 0 then --unknown version
\r
1004 worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
\r
1007 local nodepos1, nodepos2, count = worldedit.allocate(pos1, value)
\r
1009 worldedit.pos1[name] = nodepos1
\r
1010 worldedit.mark_pos1(name)
\r
1011 worldedit.pos2[name] = nodepos2
\r
1012 worldedit.mark_pos2(name)
\r
1014 worldedit.player_notify(name, count .. " nodes allocated")
\r
1018 minetest.register_chatcommand("/load", {
\r
1019 params = "<file>",
\r
1020 description = "Load nodes from \"(world folder)/schems/<file>[.we[m]]\" with position 1 of the current WorldEdit region as the origin",
\r
1021 privs = {worldedit=true},
\r
1022 func = function(name, param)
\r
1023 local pos1 = worldedit.pos1[name]
\r
1024 if pos1 == nil then
\r
1025 worldedit.player_notify(name, "no region selected")
\r
1029 if param == "" then
\r
1030 worldedit.player_notify(name, "invalid usage: " .. param)
\r
1034 --find the file in the world path
\r
1035 local testpaths = {
\r
1036 minetest.get_worldpath() .. "/schems/" .. param,
\r
1037 minetest.get_worldpath() .. "/schems/" .. param .. ".we",
\r
1038 minetest.get_worldpath() .. "/schems/" .. param .. ".wem",
\r
1041 for index, path in ipairs(testpaths) do
\r
1042 file, err = io.open(path, "rb")
\r
1048 worldedit.player_notify(name, "could not open file \"" .. param .. "\"")
\r
1051 local value = file:read("*a")
\r
1054 if worldedit.valueversion(value) == 0 then --unknown version
\r
1055 worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
\r
1059 local tenv = minetest.env
\r
1060 if worldedit.ENABLE_QUEUE then
\r
1061 tenv = worldedit.queue_aliasenv
\r
1063 local count = worldedit.deserialize(pos1, value, tenv)
\r
1065 worldedit.player_notify(name, count .. " nodes loaded")
\r
1069 minetest.register_chatcommand("/lua", {
\r
1070 params = "<code>",
\r
1071 description = "Executes <code> as a Lua chunk in the global namespace",
\r
1072 privs = {worldedit=true, server=true},
\r
1073 func = function(name, param)
\r
1074 local err = worldedit.lua(param)
\r
1076 worldedit.player_notify(name, "code error: " .. err)
\r
1078 worldedit.player_notify(name, "code successfully executed", false)
\r
1083 minetest.register_chatcommand("/luatransform", {
\r
1084 params = "<code>",
\r
1085 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
1086 privs = {worldedit=true, server=true},
\r
1087 func = function(name, param)
\r
1088 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
1089 if pos1 == nil or pos2 == nil then
\r
1090 worldedit.player_notify(name, "no region selected")
\r
1094 local err = worldedit.luatransform(pos1, pos2, param)
\r
1096 worldedit.player_notify(name, "code error: " .. err, false)
\r
1098 worldedit.player_notify(name, "code successfully executed", false)
\r
1103 if minetest.place_schematic then
\r
1104 minetest.register_chatcommand("/mtschemcreate", {
\r
1105 params = "<filename>",
\r
1106 description = "Creates a Minetest schematic of the box defined by position 1 and position 2, and saves it to <filename>",
\r
1107 privs = {worldedit=true},
\r
1108 func = function(name, param)
\r
1109 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
1110 if pos1 == nil or pos2 == nil then
\r
1111 worldedit.player_notify(name, "No region selected")
\r
1114 if param == nil then
\r
1115 worldedit.player_notify(name, "No filename specified")
\r
1119 local path = minetest.get_worldpath() .. "/schems"
\r
1120 local filename = path .. "/" .. param .. ".mts"
\r
1121 os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
\r
1123 local ret = minetest.create_schematic(pos1, pos2, worldedit.prob_list[name], filename)
\r
1124 if ret == nil then
\r
1125 worldedit.player_notify(name, "Failed to create Minetest schematic", false)
\r
1127 worldedit.player_notify(name, "Saved Minetest schematic to " .. param, false)
\r
1129 worldedit.prob_list[name] = {}
\r
1133 minetest.register_chatcommand("/mtschemplace", {
\r
1134 params = "<filename>",
\r
1135 description = "Places the Minetest schematic identified by <filename> at WorldEdit position 1",
\r
1136 privs = {worldedit=true},
\r
1137 func = function(name, param)
\r
1138 local pos = worldedit.pos1[name]
\r
1139 if pos == nil then
\r
1140 worldedit.player_notify(name, "No position selected")
\r
1143 if param == nil then
\r
1144 worldedit.player_notify(name, "No filename specified")
\r
1148 local path = minetest.get_worldpath() .. "/schems/" .. param .. ".mts"
\r
1149 if minetest.place_schematic(pos, path) == nil then
\r
1150 worldedit.player_notify(name, "Failed to place Minetest schematic", false)
\r
1152 worldedit.player_notify(name, "Placed Minetest schematic " .. param ..
\r
1153 " at " .. minetest.pos_to_string(pos), false)
\r
1158 minetest.register_chatcommand("/mtschemprob", {
\r
1159 params = "start/finish/get",
\r
1160 description = "Begins node probability entry for Minetest schematics, gets the nodes that have probabilities set, or ends node probability entry",
\r
1161 privs = {worldedit=true},
\r
1162 func = function(name, param)
\r
1163 if param == "start" then --start probability setting
\r
1164 worldedit.set_pos[name] = "prob"
\r
1165 worldedit.prob_list[name] = {}
\r
1166 worldedit.player_notify(name, "select Minetest schematic probability values by punching nodes")
\r
1167 elseif param == "finish" then --finish probability setting
\r
1168 worldedit.set_pos[name] = nil
\r
1169 worldedit.player_notify(name, "finished Minetest schematic probability selection")
\r
1170 elseif param == "get" then --get all nodes that had probabilities set on them
\r
1172 local problist = worldedit.prob_list[name]
\r
1173 if problist == nil then
\r
1176 for k,v in pairs(problist) do
\r
1177 local prob = math.floor(((v["prob"] / 256) * 100) * 100 + 0.5) / 100
\r
1178 text = text .. minetest.pos_to_string(v["pos"]) .. ": " .. prob .. "% | "
\r
1180 worldedit.player_notify(name, "Currently set node probabilities:")
\r
1181 worldedit.player_notify(name, text)
\r
1183 worldedit.player_notify(name, "unknown subcommand: " .. param)
\r
1188 minetest.register_on_player_receive_fields(
\r
1189 function(player, formname, fields)
\r
1190 if (formname == "prob_val_enter") and (fields.text ~= "") then
\r
1191 local name = player:get_player_name()
\r
1192 local prob_entry = {pos=worldedit.prob_pos[name], prob=tonumber(fields.text)}
\r
1193 local index = table.getn(worldedit.prob_list[name]) + 1
\r
1194 worldedit.prob_list[name][index] = prob_entry
\r