1 minetest.register_privilege("worldedit", "Can use WorldEdit commands")
\r
3 worldedit.set_pos = {}
\r
4 worldedit.inspect = {}
\r
8 if minetest.place_schematic then
\r
9 worldedit.prob_pos = {}
\r
10 worldedit.prob_list = {}
\r
13 dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")
\r
15 worldedit.player_notify = function(name, message)
\r
16 minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)
\r
19 --determines whether `nodename` is a valid node name, returning a boolean
\r
20 worldedit.normalize_nodename = function(nodename)
\r
21 local fullname = ItemStack({name=nodename}):get_name() --resolve aliases of node names to full names
\r
22 if minetest.registered_nodes[fullname] then --directly found node name or alias of nodename
\r
25 for key, value in pairs(minetest.registered_nodes) do
\r
26 if key:find(":" .. nodename, 1, true) then --found in mod
\r
30 nodename = nodename:lower() --lowercase both for case insensitive comparison
\r
31 for key, value in pairs(minetest.registered_nodes) do
\r
32 if value.description:lower() == nodename then --found in description
\r
39 --determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
\r
40 worldedit.player_axis = function(name)
\r
41 local dir = minetest.get_player_by_name(name):get_look_dir()
\r
42 local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
\r
45 return "x", dir.x > 0 and 1 or -1
\r
48 return "y", dir.y > 0 and 1 or -1
\r
50 return "z", dir.z > 0 and 1 or -1
\r
53 minetest.register_chatcommand("/about", {
\r
55 description = "Get information about the mod",
\r
56 func = function(name, param)
\r
57 worldedit.player_notify(name, "WorldEdit 1.0 is available on this server. Type /help to get a list of commands, or get more information at https://github.com/Uberi/MineTest-WorldEdit/")
\r
61 minetest.register_chatcommand("/inspect", {
\r
62 params = "on/off/1/0/true/false/yes/no/enable/disable",
\r
63 description = "Enable or disable node inspection",
\r
64 privs = {worldedit=true},
\r
65 func = function(name, param)
\r
66 if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" then
\r
67 worldedit.inspect[name] = true
\r
68 worldedit.player_notify(name, "node inspection enabled")
\r
69 elseif param == "off" or param == "0" or param == "false" or param == "no" or param == "disable" then
\r
70 worldedit.inspect[name] = nil
\r
71 worldedit.player_notify(name, "node inspection disabled")
\r
73 worldedit.player_notify(name, "invalid usage: " .. param)
\r
78 minetest.register_on_punchnode(function(pos, node, puncher)
\r
79 local name = puncher:get_player_name()
\r
80 if worldedit.inspect[name] then
\r
81 if minetest.check_player_privs(name, {worldedit=true}) then
\r
82 message = "inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"
\r
84 message = "inspector: worldedit privileges required"
\r
86 worldedit.player_notify(name, message)
\r
90 minetest.register_chatcommand("/reset", {
\r
92 description = "Reset the region so that it is empty",
\r
93 privs = {worldedit=true},
\r
94 func = function(name, param)
\r
95 worldedit.pos1[name] = nil
\r
96 worldedit.pos2[name] = nil
\r
97 worldedit.mark_pos1(name)
\r
98 worldedit.mark_pos2(name)
\r
99 worldedit.set_pos[name] = nil
\r
100 worldedit.player_notify(name, "region reset")
\r
104 minetest.register_chatcommand("/mark", {
\r
106 description = "Show markers at the region positions",
\r
107 privs = {worldedit=true},
\r
108 func = function(name, param)
\r
109 worldedit.mark_pos1(name)
\r
110 worldedit.mark_pos2(name)
\r
111 worldedit.player_notify(name, "region marked")
\r
115 minetest.register_chatcommand("/unmark", {
\r
117 description = "Hide markers if currently shown",
\r
118 privs = {worldedit=true},
\r
119 func = function(name, param)
\r
120 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
121 worldedit.pos1[name] = nil
\r
122 worldedit.pos2[name] = nil
\r
123 worldedit.mark_pos1(name)
\r
124 worldedit.mark_pos2(name)
\r
125 worldedit.pos1[name] = pos1
\r
126 worldedit.pos2[name] = pos2
\r
127 worldedit.player_notify(name, "region unmarked")
\r
131 minetest.register_chatcommand("/pos1", {
\r
133 description = "Set WorldEdit region position 1 to the player's location",
\r
134 privs = {worldedit=true},
\r
135 func = function(name, param)
\r
136 local pos = minetest.get_player_by_name(name):getpos()
\r
137 pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)
\r
138 worldedit.pos1[name] = pos
\r
139 worldedit.mark_pos1(name)
\r
140 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
144 minetest.register_chatcommand("/pos2", {
\r
146 description = "Set WorldEdit region position 2 to the player's location",
\r
147 privs = {worldedit=true},
\r
148 func = function(name, param)
\r
149 local pos = minetest.get_player_by_name(name):getpos()
\r
150 pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)
\r
151 worldedit.pos2[name] = pos
\r
152 worldedit.mark_pos2(name)
\r
153 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
\r
157 minetest.register_chatcommand("/p", {
\r
158 params = "set/set1/set2/get",
\r
159 description = "Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region",
\r
160 privs = {worldedit=true},
\r
161 func = function(name, param)
\r
162 if param == "set" then --set both WorldEdit positions
\r
163 worldedit.set_pos[name] = "pos1"
\r
164 worldedit.player_notify(name, "select positions by punching two nodes")
\r
165 elseif param == "set1" then --set WorldEdit position 1
\r
166 worldedit.set_pos[name] = "pos1only"
\r
167 worldedit.player_notify(name, "select position 1 by punching a node")
\r
168 elseif param == "set2" then --set WorldEdit position 2
\r
169 worldedit.set_pos[name] = "pos2"
\r
170 worldedit.player_notify(name, "select position 2 by punching a node")
\r
171 elseif param == "get" then --display current WorldEdit positions
\r
172 if worldedit.pos1[name] ~= nil then
\r
173 worldedit.player_notify(name, "position 1: " .. minetest.pos_to_string(worldedit.pos1[name]))
\r
175 worldedit.player_notify(name, "position 1 not set")
\r
177 if worldedit.pos2[name] ~= nil then
\r
178 worldedit.player_notify(name, "position 2: " .. minetest.pos_to_string(worldedit.pos2[name]))
\r
180 worldedit.player_notify(name, "position 2 not set")
\r
183 worldedit.player_notify(name, "unknown subcommand: " .. param)
\r
188 minetest.register_chatcommand("/fixedpos", {
\r
189 params = "set1/set2 x y z",
\r
190 description = "Set a WorldEdit region position to the position at (<x>, <y>, <z>)",
\r
191 privs = {worldedit=true},
\r
192 func = function(name, param)
\r
193 local found, _, flag, x, y, z = param:find("^(set[12])%s+([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)$")
\r
194 if found == nil then
\r
195 worldedit.player_notify(name, "invalid usage: " .. param)
\r
198 local pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}
\r
199 if flag == "set1" then
\r
200 worldedit.pos1[name] = pos
\r
201 worldedit.mark_pos1(name)
\r
202 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
203 else --flag == "set2"
\r
204 worldedit.pos2[name] = pos
\r
205 worldedit.mark_pos2(name)
\r
206 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
\r
211 minetest.register_on_punchnode(function(pos, node, puncher)
\r
212 local name = puncher:get_player_name()
\r
213 if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position
\r
214 if worldedit.set_pos[name] == "pos1" then --setting position 1
\r
215 worldedit.pos1[name] = pos
\r
216 worldedit.mark_pos1(name)
\r
217 worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation
\r
218 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
219 elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only
\r
220 worldedit.pos1[name] = pos
\r
221 worldedit.mark_pos1(name)
\r
222 worldedit.set_pos[name] = nil --finished setting positions
\r
223 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
224 elseif worldedit.set_pos[name] == "pos2" then --setting position 2
\r
225 worldedit.pos2[name] = pos
\r
226 worldedit.mark_pos2(name)
\r
227 worldedit.set_pos[name] = nil --finished setting positions
\r
228 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
\r
229 elseif worldedit.set_pos[name] == "prob" then --setting Minetest schematic node probabilities
\r
230 worldedit.prob_pos[name] = pos
\r
231 minetest.show_formspec(puncher:get_player_name(), "prob_val_enter", "field[text;;]")
\r
236 minetest.register_chatcommand("/volume", {
\r
238 description = "Display the volume of the current WorldEdit region",
\r
239 privs = {worldedit=true},
\r
240 func = function(name, param)
\r
241 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
242 if pos1 == nil or pos2 == nil then
\r
243 worldedit.player_notify(name, "no region selected")
\r
247 local volume = worldedit.volume(pos1, pos2)
\r
248 local abs = math.abs
\r
249 worldedit.player_notify(name, "current region has a volume of " .. volume .. " nodes ("
\r
250 .. abs(pos2.x - pos1.x) .. "*"
\r
251 .. abs(pos2.y - pos1.y) .. "*"
\r
252 .. abs(pos2.z - pos1.z) .. ")")
\r
256 minetest.register_chatcommand("/set", {
\r
258 description = "Set the current WorldEdit region to <node>",
\r
259 privs = {worldedit=true},
\r
260 func = function(name, param)
\r
261 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
262 if pos1 == nil or pos2 == nil then
\r
263 worldedit.player_notify(name, "no region selected")
\r
267 local node = worldedit.normalize_nodename(param)
\r
268 if param == "" or not node then
\r
269 worldedit.player_notify(name, "invalid node name: " .. param)
\r
273 local count = worldedit.set(pos1, pos2, node)
\r
274 worldedit.player_notify(name, count .. " nodes set")
\r
278 minetest.register_chatcommand("/replace", {
\r
279 params = "<search node> <replace node>",
\r
280 description = "Replace all instances of <search node> with <replace node> in the current WorldEdit region",
\r
281 privs = {worldedit=true},
\r
282 func = function(name, param)
\r
283 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
284 if pos1 == nil or pos2 == nil then
\r
285 worldedit.player_notify(name, "no region selected")
\r
289 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
\r
290 if found == nil then
\r
291 worldedit.player_notify(name, "invalid usage: " .. param)
\r
294 local newsearchnode = worldedit.normalize_nodename(searchnode)
\r
295 if not newsearchnode then
\r
296 worldedit.player_notify(name, "invalid search node name: " .. searchnode)
\r
299 local newreplacenode = worldedit.normalize_nodename(replacenode)
\r
300 if not newreplacenode then
\r
301 worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
\r
305 local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode)
\r
306 worldedit.player_notify(name, count .. " nodes replaced")
\r
310 minetest.register_chatcommand("/replaceinverse", {
\r
311 params = "<search node> <replace node>",
\r
312 description = "Replace all nodes other than <search node> with <replace node> in the current WorldEdit region",
\r
313 privs = {worldedit=true},
\r
314 func = function(name, param)
\r
315 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
316 if pos1 == nil or pos2 == nil then
\r
317 worldedit.player_notify(name, "no region selected")
\r
321 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
\r
322 if found == nil then
\r
323 worldedit.player_notify(name, "invalid usage: " .. param)
\r
326 local newsearchnode = worldedit.normalize_nodename(searchnode)
\r
327 if not newsearchnode then
\r
328 worldedit.player_notify(name, "invalid search node name: " .. searchnode)
\r
331 local newreplacenode = worldedit.normalize_nodename(replacenode)
\r
332 if not newreplacenode then
\r
333 worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
\r
337 local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)
\r
338 worldedit.player_notify(name, count .. " nodes replaced")
\r
342 minetest.register_chatcommand("/hollowsphere", {
\r
343 params = "<radius> <node>",
\r
344 description = "Add hollow sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
345 privs = {worldedit=true},
\r
346 func = function(name, param)
\r
347 local pos = worldedit.pos1[name]
\r
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 count = worldedit.hollow_sphere(pos, tonumber(radius), node)
\r
365 worldedit.player_notify(name, count .. " nodes added")
\r
369 minetest.register_chatcommand("/sphere", {
\r
370 params = "<radius> <node>",
\r
371 description = "Add sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
372 privs = {worldedit=true},
\r
373 func = function(name, param)
\r
374 local pos = worldedit.pos1[name]
\r
376 worldedit.player_notify(name, "no region selected")
\r
380 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
381 if found == nil then
\r
382 worldedit.player_notify(name, "invalid usage: " .. param)
\r
385 local node = worldedit.normalize_nodename(nodename)
\r
387 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
391 local count = worldedit.sphere(pos, tonumber(radius), node)
\r
392 worldedit.player_notify(name, count .. " nodes added")
\r
396 minetest.register_chatcommand("/hollowdome", {
\r
397 params = "<radius> <node>",
\r
398 description = "Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
399 privs = {worldedit=true},
\r
400 func = function(name, param)
\r
401 local pos = worldedit.pos1[name]
\r
403 worldedit.player_notify(name, "no region selected")
\r
407 local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")
\r
408 if found == nil then
\r
409 worldedit.player_notify(name, "invalid usage: " .. param)
\r
412 local node = worldedit.normalize_nodename(nodename)
\r
414 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
418 local count = worldedit.hollow_dome(pos, tonumber(radius), node)
\r
419 worldedit.player_notify(name, count .. " nodes added")
\r
423 minetest.register_chatcommand("/dome", {
\r
424 params = "<radius> <node>",
\r
425 description = "Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
426 privs = {worldedit=true},
\r
427 func = function(name, param)
\r
428 local pos = worldedit.pos1[name]
\r
430 worldedit.player_notify(name, "no region selected")
\r
434 local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")
\r
435 if found == nil then
\r
436 worldedit.player_notify(name, "invalid usage: " .. param)
\r
439 local node = worldedit.normalize_nodename(nodename)
\r
441 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
445 local count = worldedit.dome(pos, tonumber(radius), node)
\r
446 worldedit.player_notify(name, count .. " nodes added")
\r
450 minetest.register_chatcommand("/hollowcylinder", {
\r
451 params = "x/y/z/? <length> <radius> <node>",
\r
452 description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
\r
453 privs = {worldedit=true},
\r
454 func = function(name, param)
\r
455 local pos = worldedit.pos1[name]
\r
457 worldedit.player_notify(name, "no region selected")
\r
461 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
\r
462 if found == nil then
\r
463 worldedit.player_notify(name, "invalid usage: " .. param)
\r
466 length, radius = tonumber(length), tonumber(radius)
\r
467 if axis == "?" then
\r
468 axis, sign = worldedit.player_axis(name)
\r
469 length = length * sign
\r
471 local node = worldedit.normalize_nodename(nodename)
\r
473 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
477 local count = worldedit.hollow_cylinder(pos, axis, length, radius, node)
\r
478 worldedit.player_notify(name, count .. " nodes added")
\r
482 minetest.register_chatcommand("/cylinder", {
\r
483 params = "x/y/z/? <length> <radius> <node>",
\r
484 description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
\r
485 privs = {worldedit=true},
\r
486 func = function(name, param)
\r
487 local pos = worldedit.pos1[name]
\r
489 worldedit.player_notify(name, "no region selected")
\r
493 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
\r
494 if found == nil then
\r
495 worldedit.player_notify(name, "invalid usage: " .. param)
\r
498 length, radius = tonumber(length), tonumber(radius)
\r
499 if axis == "?" then
\r
500 axis, sign = worldedit.player_axis(name)
\r
501 length = length * sign
\r
503 local node = worldedit.normalize_nodename(nodename)
\r
505 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
509 local count = worldedit.cylinder(pos, axis, length, radius, node)
\r
510 worldedit.player_notify(name, count .. " nodes added")
\r
514 minetest.register_chatcommand("/pyramid", {
\r
515 params = "x/y/z/? <height> <node>",
\r
516 description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",
\r
517 privs = {worldedit=true},
\r
518 func = function(name, param)
\r
519 local pos = worldedit.pos1[name]
\r
521 worldedit.player_notify(name, "no region selected")
\r
525 local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
\r
526 if found == nil then
\r
527 worldedit.player_notify(name, "invalid usage: " .. param)
\r
530 height = tonumber(height)
\r
531 if axis == "?" then
\r
532 axis, sign = worldedit.player_axis(name)
\r
533 height = height * sign
\r
535 local node = worldedit.normalize_nodename(nodename)
\r
537 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
541 local count = worldedit.pyramid(pos, axis, height, node)
\r
542 worldedit.player_notify(name, count .. " nodes added")
\r
546 minetest.register_chatcommand("/spiral", {
\r
547 params = "<length> <height> <space> <node>",
\r
548 description = "Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <space>, composed of <node>",
\r
549 privs = {worldedit=true},
\r
550 func = function(name, param)
\r
551 local pos = worldedit.pos1[name]
\r
553 worldedit.player_notify(name, "no region selected")
\r
557 local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
\r
558 if found == nil then
\r
559 worldedit.player_notify(name, "invalid usage: " .. param)
\r
562 local node = worldedit.normalize_nodename(nodename)
\r
564 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
568 local count = worldedit.spiral(pos, tonumber(length), tonumber(height), tonumber(space), node)
\r
569 worldedit.player_notify(name, count .. " nodes added")
\r
573 minetest.register_chatcommand("/copy", {
\r
574 params = "x/y/z/? <amount>",
\r
575 description = "Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
576 privs = {worldedit=true},
\r
577 func = function(name, param)
\r
578 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
579 if pos1 == nil or pos2 == nil then
\r
580 worldedit.player_notify(name, "no region selected")
\r
584 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
585 if found == nil then
\r
586 worldedit.player_notify(name, "invalid usage: " .. param)
\r
589 amount = tonumber(amount)
\r
590 if axis == "?" then
\r
591 axis, sign = worldedit.player_axis(name)
\r
592 amount = amount * sign
\r
595 local count = worldedit.copy(pos1, pos2, axis, amount)
\r
596 worldedit.player_notify(name, count .. " nodes copied")
\r
600 minetest.register_chatcommand("/move", {
\r
601 params = "x/y/z/? <amount>",
\r
602 description = "Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
603 privs = {worldedit=true},
\r
604 func = function(name, param)
\r
605 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
606 if pos1 == nil or pos2 == nil then
\r
607 worldedit.player_notify(name, "no region selected")
\r
611 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
612 if found == nil then
\r
613 worldedit.player_notify(name, "invalid usage: " .. param)
\r
616 amount = tonumber(amount)
\r
617 if axis == "?" then
\r
618 axis, sign = worldedit.player_axis(name)
\r
619 amount = amount * sign
\r
622 local count = worldedit.move(pos1, pos2, axis, amount)
\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 count = tonumber(count)
\r
649 if axis == "?" then
\r
650 axis, sign = worldedit.player_axis(name)
\r
651 count = count * sign
\r
654 local count = worldedit.stack(pos1, pos2, axis, count)
\r
655 worldedit.player_notify(name, count .. " nodes stacked")
\r
659 minetest.register_chatcommand("/scale", {
\r
660 params = "<factor>",
\r
661 description = "Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin",
\r
662 privs = {worldedit=true},
\r
663 func = function(name, param)
\r
664 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
665 if pos1 == nil or pos2 == nil then
\r
666 worldedit.player_notify(name, "no region selected")
\r
670 local factor = tonumber(param)
\r
671 if not factor or factor ~= math.floor(factor) or factor <= 0 then
\r
672 worldedit.player_notify(name, "invalid scaling factor: " .. param)
\r
675 local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor)
\r
677 --reset markers to scaled positions
\r
678 worldedit.pos1[name] = pos1
\r
679 worldedit.pos2[name] = pos2
\r
680 worldedit.mark_pos1(name)
\r
681 worldedit.mark_pos2(name)
\r
683 worldedit.player_notify(name, count .. " nodes scaled")
\r
687 minetest.register_chatcommand("/transpose", {
\r
688 params = "x/y/z/? x/y/z/?",
\r
689 description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",
\r
690 privs = {worldedit=true},
\r
691 func = function(name, param)
\r
692 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
693 if pos1 == nil or pos2 == nil then
\r
694 worldedit.player_notify(name, "no region selected")
\r
698 local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")
\r
699 if found == nil then
\r
700 worldedit.player_notify(name, "invalid usage: " .. param)
\r
703 if axis1 == "?" then
\r
704 axis1 = worldedit.player_axis(name)
\r
706 if axis2 == "?" then
\r
707 axis2 = worldedit.player_axis(name)
\r
709 if axis1 == axis2 then
\r
710 worldedit.player_notify(name, "invalid usage: axes must be different")
\r
714 local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
\r
716 --reset markers to transposed positions
\r
717 worldedit.pos1[name] = pos1
\r
718 worldedit.pos2[name] = pos2
\r
719 worldedit.mark_pos1(name)
\r
720 worldedit.mark_pos2(name)
\r
722 worldedit.player_notify(name, count .. " nodes transposed")
\r
726 minetest.register_chatcommand("/flip", {
\r
727 params = "x/y/z/?",
\r
728 description = "Flip the current WorldEdit region along the x/y/z/? axis",
\r
729 privs = {worldedit=true},
\r
730 func = function(name, param)
\r
731 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
732 if pos1 == nil or pos2 == nil then
\r
733 worldedit.player_notify(name, "no region selected")
\r
737 if param == "?" then
\r
738 param = worldedit.player_axis(name)
\r
740 if param ~= "x" and param ~= "y" and param ~= "z" then
\r
741 worldedit.player_notify(name, "invalid usage: " .. param)
\r
745 local count = worldedit.flip(pos1, pos2, param)
\r
746 worldedit.player_notify(name, count .. " nodes flipped")
\r
750 minetest.register_chatcommand("/rotate", {
\r
751 params = "<axis> <angle>",
\r
752 description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",
\r
753 privs = {worldedit=true},
\r
754 func = function(name, param)
\r
755 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
756 if pos1 == nil or pos2 == nil then
\r
757 worldedit.player_notify(name, "no region selected")
\r
761 local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
762 if found == nil then
\r
763 worldedit.player_notify(name, "invalid usage: " .. param)
\r
766 if axis == "?" then
\r
767 axis = worldedit.player_axis(name)
\r
769 if angle % 90 ~= 0 then
\r
770 worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")
\r
774 local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)
\r
776 --reset markers to rotated positions
\r
777 worldedit.pos1[name] = pos1
\r
778 worldedit.pos2[name] = pos2
\r
779 worldedit.mark_pos1(name)
\r
780 worldedit.mark_pos2(name)
\r
782 worldedit.player_notify(name, count .. " nodes rotated")
\r
786 minetest.register_chatcommand("/orient", {
\r
787 params = "<angle>",
\r
788 description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)",
\r
789 privs = {worldedit=true},
\r
790 func = function(name, param)
\r
791 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
792 if pos1 == nil or pos2 == nil then
\r
793 worldedit.player_notify(name, "no region selected")
\r
797 local found, _, angle = param:find("^([+-]?%d+)$")
\r
798 if found == nil then
\r
799 worldedit.player_notify(name, "invalid usage: " .. param)
\r
802 if angle % 90 ~= 0 then
\r
803 worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")
\r
807 local count = worldedit.orient(pos1, pos2, angle)
\r
809 worldedit.player_notify(name, count .. " nodes oriented")
\r
813 minetest.register_chatcommand("/fixlight", {
\r
815 description = "Fix the lighting in the current WorldEdit region",
\r
816 privs = {worldedit=true},
\r
817 func = function(name, param)
\r
818 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
819 if pos1 == nil or pos2 == nil then
\r
820 worldedit.player_notify(name, "no region selected")
\r
824 local count = worldedit.fixlight(pos1, pos2)
\r
825 worldedit.player_notify(name, count .. " nodes updated")
\r
829 minetest.register_chatcommand("/hide", {
\r
831 description = "Hide all nodes in the current WorldEdit region non-destructively",
\r
832 privs = {worldedit=true},
\r
833 func = function(name, param)
\r
834 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
835 if pos1 == nil or pos2 == nil then
\r
836 worldedit.player_notify(name, "no region selected")
\r
840 local count = worldedit.hide(pos1, pos2)
\r
841 worldedit.player_notify(name, count .. " nodes hidden")
\r
845 minetest.register_chatcommand("/suppress", {
\r
847 description = "Suppress all <node> in the current WorldEdit region non-destructively",
\r
848 privs = {worldedit=true},
\r
849 func = function(name, param)
\r
850 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
851 if pos1 == nil or pos2 == nil then
\r
852 worldedit.player_notify(name, "no region selected")
\r
856 local node = worldedit.normalize_nodename(param)
\r
857 if param == "" or not node then
\r
858 worldedit.player_notify(name, "invalid node name: " .. param)
\r
862 local count = worldedit.suppress(pos1, pos2, node)
\r
863 worldedit.player_notify(name, count .. " nodes suppressed")
\r
867 minetest.register_chatcommand("/highlight", {
\r
869 description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",
\r
870 privs = {worldedit=true},
\r
871 func = function(name, param)
\r
872 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
873 if pos1 == nil or pos2 == nil then
\r
874 worldedit.player_notify(name, "no region selected")
\r
878 local node = worldedit.normalize_nodename(param)
\r
879 if param == "" or not node then
\r
880 worldedit.player_notify(name, "invalid node name: " .. param)
\r
884 local count = worldedit.highlight(pos1, pos2, node)
\r
885 worldedit.player_notify(name, count .. " nodes highlighted")
\r
889 minetest.register_chatcommand("/restore", {
\r
891 description = "Restores nodes hidden with WorldEdit in the current WorldEdit region",
\r
892 privs = {worldedit=true},
\r
893 func = function(name, param)
\r
894 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
895 if pos1 == nil or pos2 == nil then
\r
896 worldedit.player_notify(name, "no region selected")
\r
900 local count = worldedit.restore(pos1, pos2)
\r
901 worldedit.player_notify(name, count .. " nodes restored")
\r
905 minetest.register_chatcommand("/save", {
\r
907 description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",
\r
908 privs = {worldedit=true},
\r
909 func = function(name, param)
\r
910 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
911 if pos1 == nil or pos2 == nil then
\r
912 worldedit.player_notify(name, "no region selected")
\r
916 if param == "" then
\r
917 worldedit.player_notify(name, "invalid usage: " .. param)
\r
921 local result, count = worldedit.serialize(pos1, pos2)
\r
923 local path = minetest.get_worldpath() .. "/schems"
\r
924 local filename = path .. "/" .. param .. ".we"
\r
925 os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
\r
926 local file, err = io.open(filename, "wb")
\r
928 worldedit.player_notify(name, "could not save file to \"" .. filename .. "\"")
\r
935 worldedit.player_notify(name, count .. " nodes saved")
\r
939 minetest.register_chatcommand("/allocate", {
\r
941 description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",
\r
942 privs = {worldedit=true},
\r
943 func = function(name, param)
\r
944 local pos1 = worldedit.pos1[name]
\r
945 if pos1 == nil then
\r
946 worldedit.player_notify(name, "no region selected")
\r
950 if param == "" then
\r
951 worldedit.player_notify(name, "invalid usage: " .. param)
\r
955 local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"
\r
956 local file, err = io.open(filename, "rb")
\r
958 worldedit.player_notify(name, "could not open file \"" .. filename .. "\"")
\r
961 local value = file:read("*a")
\r
964 if worldedit.valueversion(value) == 0 then --unknown version
\r
965 worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
\r
968 local nodepos1, nodepos2, count = worldedit.allocate(pos1, value)
\r
970 worldedit.pos1[name] = nodepos1
\r
971 worldedit.mark_pos1(name)
\r
972 worldedit.pos2[name] = nodepos2
\r
973 worldedit.mark_pos2(name)
\r
975 worldedit.player_notify(name, count .. " nodes allocated")
\r
979 minetest.register_chatcommand("/load", {
\r
981 description = "Load nodes from \"(world folder)/schems/<file>[.we[m]]\" with position 1 of the current WorldEdit region as the origin",
\r
982 privs = {worldedit=true},
\r
983 func = function(name, param)
\r
984 local pos1 = worldedit.pos1[name]
\r
985 if pos1 == nil then
\r
986 worldedit.player_notify(name, "no region selected")
\r
990 if param == "" then
\r
991 worldedit.player_notify(name, "invalid usage: " .. param)
\r
995 --find the file in the world path
\r
996 local testpaths = {
\r
997 minetest.get_worldpath() .. "/schems/" .. param,
\r
998 minetest.get_worldpath() .. "/schems/" .. param .. ".we",
\r
999 minetest.get_worldpath() .. "/schems/" .. param .. ".wem",
\r
1002 for index, path in ipairs(testpaths) do
\r
1003 file, err = io.open(path, "rb")
\r
1009 worldedit.player_notify(name, "could not open file \"" .. param .. "\"")
\r
1012 local value = file:read("*a")
\r
1015 if worldedit.valueversion(value) == 0 then --unknown version
\r
1016 worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
\r
1020 local count = worldedit.deserialize(pos1, value)
\r
1022 worldedit.player_notify(name, count .. " nodes loaded")
\r
1026 minetest.register_chatcommand("/lua", {
\r
1027 params = "<code>",
\r
1028 description = "Executes <code> as a Lua chunk in the global namespace",
\r
1029 privs = {worldedit=true, server=true},
\r
1030 func = function(name, param)
\r
1031 local err = worldedit.lua(param)
\r
1033 worldedit.player_notify(name, "code error: " .. err)
\r
1035 worldedit.player_notify(name, "code successfully executed", false)
\r
1040 minetest.register_chatcommand("/luatransform", {
\r
1041 params = "<code>",
\r
1042 description = "Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region",
\r
1043 privs = {worldedit=true, server=true},
\r
1044 func = function(name, param)
\r
1045 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
1046 if pos1 == nil or pos2 == nil then
\r
1047 worldedit.player_notify(name, "no region selected")
\r
1051 local err = worldedit.luatransform(pos1, pos2, param)
\r
1053 worldedit.player_notify(name, "code error: " .. err, false)
\r
1055 worldedit.player_notify(name, "code successfully executed", false)
\r
1060 if minetest.place_schematic then
\r
1061 minetest.register_chatcommand("/mtschemcreate", {
\r
1062 params = "<file>",
\r
1063 description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/<filename>.mts\"",
\r
1064 privs = {worldedit=true},
\r
1065 func = function(name, param)
\r
1066 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
1067 if pos1 == nil or pos2 == nil then
\r
1068 worldedit.player_notify(name, "No region selected")
\r
1071 if param == nil then
\r
1072 worldedit.player_notify(name, "No filename specified")
\r
1076 local path = minetest.get_worldpath() .. "/schems"
\r
1077 local filename = path .. "/" .. param .. ".mts"
\r
1078 os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
\r
1080 local ret = minetest.create_schematic(pos1, pos2, worldedit.prob_list[name], filename)
\r
1081 if ret == nil then
\r
1082 worldedit.player_notify(name, "Failed to create Minetest schematic", false)
\r
1084 worldedit.player_notify(name, "Saved Minetest schematic to " .. param, false)
\r
1086 worldedit.prob_list[name] = {}
\r
1090 minetest.register_chatcommand("/mtschemplace", {
\r
1091 params = "<file>",
\r
1092 description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",
\r
1093 privs = {worldedit=true},
\r
1094 func = function(name, param)
\r
1095 local pos = worldedit.pos1[name]
\r
1096 if pos == nil then
\r
1097 worldedit.player_notify(name, "No position selected")
\r
1100 if param == nil then
\r
1101 worldedit.player_notify(name, "No filename specified")
\r
1105 local path = minetest.get_worldpath() .. "/schems/" .. param .. ".mts"
\r
1106 if minetest.place_schematic(pos, path) == nil then
\r
1107 worldedit.player_notify(name, "Failed to place Minetest schematic", false)
\r
1109 worldedit.player_notify(name, "Placed Minetest schematic " .. param ..
\r
1110 " at " .. minetest.pos_to_string(pos), false)
\r
1115 minetest.register_chatcommand("/mtschemprob", {
\r
1116 params = "start/finish/get",
\r
1117 description = "Begins node probability entry for Minetest schematics, gets the nodes that have probabilities set, or ends node probability entry",
\r
1118 privs = {worldedit=true},
\r
1119 func = function(name, param)
\r
1120 if param == "start" then --start probability setting
\r
1121 worldedit.set_pos[name] = "prob"
\r
1122 worldedit.prob_list[name] = {}
\r
1123 worldedit.player_notify(name, "select Minetest schematic probability values by punching nodes")
\r
1124 elseif param == "finish" then --finish probability setting
\r
1125 worldedit.set_pos[name] = nil
\r
1126 worldedit.player_notify(name, "finished Minetest schematic probability selection")
\r
1127 elseif param == "get" then --get all nodes that had probabilities set on them
\r
1129 local problist = worldedit.prob_list[name]
\r
1130 if problist == nil then
\r
1133 for k,v in pairs(problist) do
\r
1134 local prob = math.floor(((v["prob"] / 256) * 100) * 100 + 0.5) / 100
\r
1135 text = text .. minetest.pos_to_string(v["pos"]) .. ": " .. prob .. "% | "
\r
1137 worldedit.player_notify(name, "Currently set node probabilities:")
\r
1138 worldedit.player_notify(name, text)
\r
1140 worldedit.player_notify(name, "unknown subcommand: " .. param)
\r
1145 minetest.register_on_player_receive_fields(
\r
1146 function(player, formname, fields)
\r
1147 if (formname == "prob_val_enter") and (fields.text ~= "") then
\r
1148 local name = player:get_player_name()
\r
1149 local prob_entry = {pos=worldedit.prob_pos[name], prob=tonumber(fields.text)}
\r
1150 local index = table.getn(worldedit.prob_list[name]) + 1
\r
1151 worldedit.prob_list[name][index] = prob_entry
\r
1157 minetest.register_chatcommand("/clearobjects", {
\r
1159 description = "Clears all objects within the WorldEdit region",
\r
1160 privs = {worldedit=true},
\r
1161 func = function(name, param)
\r
1162 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
1163 if pos1 == nil or pos2 == nil then
\r
1164 worldedit.player_notify(name, "no region selected")
\r
1168 local count = worldedit.clearobjects(pos1, pos2)
\r
1169 worldedit.player_notify(name, count .. " objects cleared")
\r