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") .. "/cuboid.lua")
\r
14 dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")
\r
15 dofile(minetest.get_modpath("worldedit_commands") .. "/wand.lua")
\r
16 local safe_region, check_region, reset_pending = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")
\r
18 local function get_position(name) --position 1 retrieval function for when not using `safe_region`
\r
19 local pos1 = worldedit.pos1[name]
\r
21 worldedit.player_notify(name, "no position 1 selected")
\r
26 local function get_node(name, nodename)
\r
27 local node = worldedit.normalize_nodename(nodename)
\r
29 worldedit.player_notify(name, "invalid node name: " .. nodename)
\r
35 function worldedit.player_notify(name, message)
\r
36 minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)
\r
39 --determines whether `nodename` is a valid node name, returning a boolean
\r
40 worldedit.normalize_nodename = function(nodename)
\r
41 nodename = nodename:gsub("^%s*(.-)%s*$", "%1")
\r
42 if nodename == "" then return nil end
\r
43 local fullname = ItemStack({name=nodename}):get_name() --resolve aliases of node names to full names
\r
44 if minetest.registered_nodes[fullname] or fullname == "air" then --directly found node name or alias of nodename
\r
47 for key, value in pairs(minetest.registered_nodes) do
\r
48 if key:find(":" .. nodename, 1, true) then --found in mod
\r
52 nodename = nodename:lower() --lowercase both for case insensitive comparison
\r
53 for key, value in pairs(minetest.registered_nodes) do
\r
54 if value.description:lower() == nodename then --found in description
\r
61 -- Determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
\r
62 function worldedit.player_axis(name)
\r
63 local dir = minetest.get_player_by_name(name):get_look_dir()
\r
64 local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
\r
67 return "x", dir.x > 0 and 1 or -1
\r
70 return "y", dir.y > 0 and 1 or -1
\r
72 return "z", dir.z > 0 and 1 or -1
\r
75 local function mkdir(path)
\r
76 if minetest.mkdir then
\r
77 minetest.mkdir(path)
\r
79 os.execute('mkdir "' .. path .. '"')
\r
83 local function check_filename(name)
\r
84 return name:find("^[%w%s%^&'@{}%[%],%$=!%-#%(%)%%%.%+~_]+$") ~= nil
\r
88 minetest.register_chatcommand("/about", {
\r
90 description = "Get information about the mod",
\r
91 func = function(name, param)
\r
92 worldedit.player_notify(name, "WorldEdit " .. worldedit.version_string .. " 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
96 -- mostly copied from builtin/chatcommands.lua with minor modifications
\r
97 minetest.register_chatcommand("/help", {
\r
99 params = "[all/<cmd>]",
\r
100 description = "Get help for WorldEdit commands",
\r
101 func = function(name, param)
\r
102 local function is_we_command(cmd)
\r
103 return cmd:sub(0, 1) == "/"
\r
105 local function format_help_line(cmd, def)
\r
106 local msg = minetest.colorize("#00ffff", "/"..cmd)
\r
107 if def.params and def.params ~= "" then
\r
108 msg = msg .. " " .. def.params
\r
110 if def.description and def.description ~= "" then
\r
111 msg = msg .. ": " .. def.description
\r
116 if not minetest.check_player_privs(name, "worldedit") then
\r
117 return false, "You are not allowed to use any WorldEdit commands."
\r
119 if param == "" then
\r
122 for cmd, def in pairs(minetest.chatcommands) do
\r
123 if is_we_command(cmd) and minetest.check_player_privs(name, def.privs) then
\r
124 cmds[#cmds + 1] = cmd:sub(2) -- strip the /
\r
128 return true, "Available commands: " .. table.concat(cmds, " ") .. "\n"
\r
129 .. "Use '//help <cmd>' to get more information,"
\r
130 .. " or '//help all' to list everything."
\r
131 elseif param == "all" then
\r
133 for cmd, def in pairs(minetest.chatcommands) do
\r
134 if is_we_command(cmd) and minetest.check_player_privs(name, def.privs) then
\r
135 cmds[#cmds + 1] = format_help_line(cmd, def)
\r
139 return true, "Available commands:\n"..table.concat(cmds, "\n")
\r
141 return minetest.chatcommands["help"].func(name, "/" .. param)
\r
146 minetest.register_chatcommand("/inspect", {
\r
147 params = "on/off/1/0/true/false/yes/no/enable/disable/<blank>",
\r
148 description = "Enable or disable node inspection",
\r
149 privs = {worldedit=true},
\r
150 func = function(name, param)
\r
151 if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" or param == "" then
\r
152 worldedit.inspect[name] = true
\r
153 local axis, sign = worldedit.player_axis(name)
\r
154 worldedit.player_notify(name, string.format("inspector: inspection enabled for %s, currently facing the %s axis",
\r
155 name, axis .. (sign > 0 and "+" or "-")))
\r
156 elseif param == "off" or param == "0" or param == "false" or param == "no" or param == "disable" then
\r
157 worldedit.inspect[name] = nil
\r
158 worldedit.player_notify(name, "inspector: inspection disabled")
\r
160 worldedit.player_notify(name, "invalid usage: " .. param)
\r
165 local function get_node_rlight(pos)
\r
166 local vecs = { -- neighboring nodes
\r
167 {x= 1, y= 0, z= 0},
\r
168 {x=-1, y= 0, z= 0},
\r
169 {x= 0, y= 1, z= 0},
\r
170 {x= 0, y=-1, z= 0},
\r
171 {x= 0, y= 0, z= 1},
\r
172 {x= 0, y= 0, z=-1},
\r
175 for _, v in ipairs(vecs) do
\r
176 ret = math.max(ret, minetest.get_node_light(vector.add(pos, v)))
\r
181 minetest.register_on_punchnode(function(pos, node, puncher)
\r
182 local name = puncher:get_player_name()
\r
183 if worldedit.inspect[name] then
\r
184 local axis, sign = worldedit.player_axis(name)
\r
185 message = string.format("inspector: %s at %s (param1=%d, param2=%d, received light=%d) punched facing the %s axis",
\r
186 node.name, minetest.pos_to_string(pos), node.param1, node.param2, get_node_rlight(pos), axis .. (sign > 0 and "+" or "-"))
\r
187 worldedit.player_notify(name, message)
\r
191 minetest.register_chatcommand("/reset", {
\r
193 description = "Reset the region so that it is empty",
\r
194 privs = {worldedit=true},
\r
195 func = function(name, param)
\r
196 worldedit.pos1[name] = nil
\r
197 worldedit.pos2[name] = nil
\r
198 worldedit.mark_pos1(name)
\r
199 worldedit.mark_pos2(name)
\r
200 worldedit.set_pos[name] = nil
\r
201 --make sure the user does not try to confirm an operation after resetting pos:
\r
202 reset_pending(name)
\r
203 worldedit.player_notify(name, "region reset")
\r
207 minetest.register_chatcommand("/mark", {
\r
209 description = "Show markers at the region positions",
\r
210 privs = {worldedit=true},
\r
211 func = function(name, param)
\r
212 worldedit.mark_pos1(name)
\r
213 worldedit.mark_pos2(name)
\r
214 worldedit.player_notify(name, "region marked")
\r
218 minetest.register_chatcommand("/unmark", {
\r
220 description = "Hide markers if currently shown",
\r
221 privs = {worldedit=true},
\r
222 func = function(name, param)
\r
223 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
224 worldedit.pos1[name] = nil
\r
225 worldedit.pos2[name] = nil
\r
226 worldedit.mark_pos1(name)
\r
227 worldedit.mark_pos2(name)
\r
228 worldedit.pos1[name] = pos1
\r
229 worldedit.pos2[name] = pos2
\r
230 worldedit.player_notify(name, "region unmarked")
\r
234 minetest.register_chatcommand("/pos1", {
\r
236 description = "Set WorldEdit region position 1 to the player's location",
\r
237 privs = {worldedit=true},
\r
238 func = function(name, param)
\r
239 local pos = minetest.get_player_by_name(name):getpos()
\r
240 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
241 worldedit.pos1[name] = pos
\r
242 worldedit.mark_pos1(name)
\r
243 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
247 minetest.register_chatcommand("/pos2", {
\r
249 description = "Set WorldEdit region position 2 to the player's location",
\r
250 privs = {worldedit=true},
\r
251 func = function(name, param)
\r
252 local pos = minetest.get_player_by_name(name):getpos()
\r
253 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
254 worldedit.pos2[name] = pos
\r
255 worldedit.mark_pos2(name)
\r
256 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
\r
260 minetest.register_chatcommand("/p", {
\r
261 params = "set/set1/set2/get",
\r
262 description = "Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region",
\r
263 privs = {worldedit=true},
\r
264 func = function(name, param)
\r
265 if param == "set" then --set both WorldEdit positions
\r
266 worldedit.set_pos[name] = "pos1"
\r
267 worldedit.player_notify(name, "select positions by punching two nodes")
\r
268 elseif param == "set1" then --set WorldEdit position 1
\r
269 worldedit.set_pos[name] = "pos1only"
\r
270 worldedit.player_notify(name, "select position 1 by punching a node")
\r
271 elseif param == "set2" then --set WorldEdit position 2
\r
272 worldedit.set_pos[name] = "pos2"
\r
273 worldedit.player_notify(name, "select position 2 by punching a node")
\r
274 elseif param == "get" then --display current WorldEdit positions
\r
275 if worldedit.pos1[name] ~= nil then
\r
276 worldedit.player_notify(name, "position 1: " .. minetest.pos_to_string(worldedit.pos1[name]))
\r
278 worldedit.player_notify(name, "position 1 not set")
\r
280 if worldedit.pos2[name] ~= nil then
\r
281 worldedit.player_notify(name, "position 2: " .. minetest.pos_to_string(worldedit.pos2[name]))
\r
283 worldedit.player_notify(name, "position 2 not set")
\r
286 worldedit.player_notify(name, "unknown subcommand: " .. param)
\r
291 minetest.register_chatcommand("/fixedpos", {
\r
292 params = "set1/set2 x y z",
\r
293 description = "Set a WorldEdit region position to the position at (<x>, <y>, <z>)",
\r
294 privs = {worldedit=true},
\r
295 func = function(name, param)
\r
296 local found, _, flag, x, y, z = param:find("^(set[12])%s+([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)$")
\r
297 if found == nil then
\r
298 worldedit.player_notify(name, "invalid usage: " .. param)
\r
301 local pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}
\r
302 if flag == "set1" then
\r
303 worldedit.pos1[name] = pos
\r
304 worldedit.mark_pos1(name)
\r
305 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
306 else --flag == "set2"
\r
307 worldedit.pos2[name] = pos
\r
308 worldedit.mark_pos2(name)
\r
309 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
\r
314 minetest.register_on_punchnode(function(pos, node, puncher)
\r
315 local name = puncher:get_player_name()
\r
316 if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position
\r
317 if worldedit.set_pos[name] == "pos1" then --setting position 1
\r
318 worldedit.pos1[name] = pos
\r
319 worldedit.mark_pos1(name)
\r
320 worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation
\r
321 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
322 elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only
\r
323 worldedit.pos1[name] = pos
\r
324 worldedit.mark_pos1(name)
\r
325 worldedit.set_pos[name] = nil --finished setting positions
\r
326 worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
\r
327 elseif worldedit.set_pos[name] == "pos2" then --setting position 2
\r
328 worldedit.pos2[name] = pos
\r
329 worldedit.mark_pos2(name)
\r
330 worldedit.set_pos[name] = nil --finished setting positions
\r
331 worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
\r
332 elseif worldedit.set_pos[name] == "prob" then --setting Minetest schematic node probabilities
\r
333 worldedit.prob_pos[name] = pos
\r
334 minetest.show_formspec(puncher:get_player_name(), "prob_val_enter", "field[text;;]")
\r
339 minetest.register_chatcommand("/volume", {
\r
341 description = "Display the volume of the current WorldEdit region",
\r
342 privs = {worldedit=true},
\r
343 func = function(name, param)
\r
344 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
345 if pos1 == nil or pos2 == nil then
\r
346 worldedit.player_notify(name, "no region selected")
\r
350 local volume = worldedit.volume(pos1, pos2)
\r
351 local abs = math.abs
\r
352 worldedit.player_notify(name, "current region has a volume of " .. volume .. " nodes ("
\r
353 .. abs(pos2.x - pos1.x) + 1 .. "*"
\r
354 .. abs(pos2.y - pos1.y) + 1 .. "*"
\r
355 .. abs(pos2.z - pos1.z) + 1 .. ")")
\r
359 minetest.register_chatcommand("/deleteblocks", {
\r
361 description = "remove all MapBlocks (16x16x16) containing the selected area from the map",
\r
362 privs = {worldedit=true},
\r
363 func = safe_region(function(name, param)
\r
364 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
365 local success = minetest.delete_area(pos1, pos2)
\r
367 worldedit.player_notify(name, "Area deleted.")
\r
369 worldedit.player_notify(name, "There was an error during deletion of the area.")
\r
374 minetest.register_chatcommand("/set", {
\r
376 description = "Set the current WorldEdit region to <node>",
\r
377 privs = {worldedit=true},
\r
378 func = safe_region(function(name, param)
\r
379 local node = get_node(name, param)
\r
381 worldedit.player_notify(name, "Could not identify node \"" .. param .. "\"")
\r
385 local count = worldedit.set(worldedit.pos1[name], worldedit.pos2[name], node)
\r
386 worldedit.player_notify(name, count .. " nodes set")
\r
387 end, check_region),
\r
390 minetest.register_chatcommand("/mix", {
\r
391 params = "<node1> ...",
\r
392 description = "Fill the current WorldEdit region with a random mix of <node1>, ...",
\r
393 privs = {worldedit=true},
\r
394 func = safe_region(function(name, param)
\r
396 for nodename in param:gmatch("[^%s]+") do
\r
397 local node = get_node(name, nodename)
\r
399 worldedit.player_notify(name, "Could not identify node \"" .. name .. "\"")
\r
402 nodes[#nodes + 1] = node
\r
405 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
406 local count = worldedit.set(pos1, pos2, nodes)
\r
407 worldedit.player_notify(name, count .. " nodes set")
\r
408 end, check_region),
\r
411 local check_replace = function(name, param)
\r
412 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
\r
413 if found == nil then
\r
414 worldedit.player_notify(name, "invalid usage: " .. param)
\r
417 local newsearchnode = worldedit.normalize_nodename(searchnode)
\r
418 if not newsearchnode then
\r
419 worldedit.player_notify(name, "invalid search node name: " .. searchnode)
\r
422 local newreplacenode = worldedit.normalize_nodename(replacenode)
\r
423 if not newreplacenode then
\r
424 worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
\r
427 return check_region(name, param)
\r
430 minetest.register_chatcommand("/replace", {
\r
431 params = "<search node> <replace node>",
\r
432 description = "Replace all instances of <search node> with <replace node> in the current WorldEdit region",
\r
433 privs = {worldedit=true},
\r
434 func = safe_region(function(name, param)
\r
435 local found, _, search_node, replace_node = param:find("^([^%s]+)%s+(.+)$")
\r
436 local norm_search_node = worldedit.normalize_nodename(search_node)
\r
437 local norm_replace_node = worldedit.normalize_nodename(replace_node)
\r
438 local count = worldedit.replace(worldedit.pos1[name], worldedit.pos2[name],
\r
439 norm_search_node, norm_replace_node)
\r
440 worldedit.player_notify(name, count .. " nodes replaced")
\r
441 end, check_replace),
\r
444 minetest.register_chatcommand("/replaceinverse", {
\r
445 params = "<search node> <replace node>",
\r
446 description = "Replace all nodes other than <search node> with <replace node> in the current WorldEdit region",
\r
447 privs = {worldedit=true},
\r
448 func = safe_region(function(name, param)
\r
449 local found, _, search_node, replace_node = param:find("^([^%s]+)%s+(.+)$")
\r
450 local norm_search_node = worldedit.normalize_nodename(search_node)
\r
451 local norm_replace_node = worldedit.normalize_nodename(replace_node)
\r
452 local count = worldedit.replace(worldedit.pos1[name], worldedit.pos2[name],
\r
453 norm_search_node, norm_replace_node, true)
\r
454 worldedit.player_notify(name, count .. " nodes replaced")
\r
455 end, check_replace),
\r
458 local check_sphere = function(name, param)
\r
459 if worldedit.pos1[name] == nil then
\r
460 worldedit.player_notify(name, "no position 1 selected")
\r
463 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
464 if found == nil then
\r
465 worldedit.player_notify(name, "invalid usage: " .. param)
\r
468 local node = get_node(name, nodename)
\r
469 if not node then return nil end
\r
470 return math.ceil((4 * math.pi * (tonumber(radius) ^ 3)) / 3) --volume of sphere
\r
473 minetest.register_chatcommand("/hollowsphere", {
\r
474 params = "<radius> <node>",
\r
475 description = "Add hollow sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
476 privs = {worldedit=true},
\r
477 func = safe_region(function(name, param)
\r
478 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
479 local node = get_node(name, nodename)
\r
480 local count = worldedit.sphere(worldedit.pos1[name], tonumber(radius), node, true)
\r
481 worldedit.player_notify(name, count .. " nodes added")
\r
482 end, check_sphere),
\r
485 minetest.register_chatcommand("/sphere", {
\r
486 params = "<radius> <node>",
\r
487 description = "Add sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
488 privs = {worldedit=true},
\r
489 func = safe_region(function(name, param)
\r
490 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
491 local node = get_node(name, nodename)
\r
492 local count = worldedit.sphere(worldedit.pos1[name], tonumber(radius), node)
\r
493 worldedit.player_notify(name, count .. " nodes added")
\r
494 end, check_sphere),
\r
497 local check_dome = function(name, param)
\r
498 if worldedit.pos1[name] == nil then
\r
499 worldedit.player_notify(name, "no position 1 selected")
\r
502 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
503 if found == nil then
\r
504 worldedit.player_notify(name, "invalid usage: " .. param)
\r
507 local node = get_node(name, nodename)
\r
508 if not node then return nil end
\r
509 return math.ceil((2 * math.pi * (tonumber(radius) ^ 3)) / 3) --volume of dome
\r
512 minetest.register_chatcommand("/hollowdome", {
\r
513 params = "<radius> <node>",
\r
514 description = "Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
515 privs = {worldedit=true},
\r
516 func = safe_region(function(name, param)
\r
517 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
518 local node = get_node(name, nodename)
\r
519 local count = worldedit.dome(worldedit.pos1[name], tonumber(radius), node, true)
\r
520 worldedit.player_notify(name, count .. " nodes added")
\r
524 minetest.register_chatcommand("/dome", {
\r
525 params = "<radius> <node>",
\r
526 description = "Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
527 privs = {worldedit=true},
\r
528 func = safe_region(function(name, param)
\r
529 local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
\r
530 local node = get_node(name, nodename)
\r
531 local count = worldedit.dome(worldedit.pos1[name], tonumber(radius), node)
\r
532 worldedit.player_notify(name, count .. " nodes added")
\r
536 local check_cylinder = function(name, param)
\r
537 if worldedit.pos1[name] == nil then
\r
538 worldedit.player_notify(name, "no position 1 selected")
\r
542 local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
\r
543 if found == nil then
\r
545 found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
\r
548 if found == nil then
\r
549 worldedit.player_notify(name, "invalid usage: " .. param)
\r
552 local node = get_node(name, nodename)
\r
553 if not node then return nil end
\r
554 local radius = math.max(tonumber(radius1), tonumber(radius2))
\r
555 return math.ceil(math.pi * (radius ^ 2) * tonumber(length))
\r
558 minetest.register_chatcommand("/hollowcylinder", {
\r
559 params = "x/y/z/? <length> <radius1> [radius2] <node>",
\r
560 description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length>, base radius <radius1> (and top radius [radius2]), composed of <node>",
\r
561 privs = {worldedit=true},
\r
562 func = safe_region(function(name, param)
\r
564 local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
\r
565 if found == nil then
\r
567 found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
\r
570 length = tonumber(length)
\r
571 if axis == "?" then
\r
572 axis, sign = worldedit.player_axis(name)
\r
573 length = length * sign
\r
575 local node = get_node(name, nodename)
\r
576 local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius1), tonumber(radius2), node, true)
\r
577 worldedit.player_notify(name, count .. " nodes added")
\r
578 end, check_cylinder),
\r
581 minetest.register_chatcommand("/cylinder", {
\r
582 params = "x/y/z/? <length> <radius1> [radius2] <node>",
\r
583 description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length>, base radius <radius1> (and top radius [radius2]), composed of <node>",
\r
584 privs = {worldedit=true},
\r
585 func = safe_region(function(name, param)
\r
587 local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
\r
588 if found == nil then
\r
590 found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
\r
593 length = tonumber(length)
\r
594 if axis == "?" then
\r
595 axis, sign = worldedit.player_axis(name)
\r
596 length = length * sign
\r
598 local node = get_node(name, nodename)
\r
599 local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius1), tonumber(radius2), node)
\r
600 worldedit.player_notify(name, count .. " nodes added")
\r
601 end, check_cylinder),
\r
604 local check_pyramid = function(name, param)
\r
605 if worldedit.pos1[name] == nil then
\r
606 worldedit.player_notify(name, "no position 1 selected")
\r
609 local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
\r
610 if found == nil then
\r
611 worldedit.player_notify(name, "invalid usage: " .. param)
\r
614 local node = get_node(name, nodename)
\r
615 if not node then return nil end
\r
616 height = tonumber(height)
\r
617 return math.ceil(((height * 2 + 1) ^ 2) * height / 3)
\r
620 minetest.register_chatcommand("/hollowpyramid", {
\r
621 params = "x/y/z/? <height> <node>",
\r
622 description = "Add hollow pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",
\r
623 privs = {worldedit=true},
\r
624 func = safe_region(function(name, param)
\r
625 local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
\r
626 height = tonumber(height)
\r
627 if axis == "?" then
\r
628 axis, sign = worldedit.player_axis(name)
\r
629 height = height * sign
\r
631 local node = get_node(name, nodename)
\r
632 local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node, true)
\r
633 worldedit.player_notify(name, count .. " nodes added")
\r
634 end, check_pyramid),
\r
637 minetest.register_chatcommand("/pyramid", {
\r
638 params = "x/y/z/? <height> <node>",
\r
639 description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",
\r
640 privs = {worldedit=true},
\r
641 func = safe_region(function(name, param)
\r
642 local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
\r
643 height = tonumber(height)
\r
644 if axis == "?" then
\r
645 axis, sign = worldedit.player_axis(name)
\r
646 height = height * sign
\r
648 local node = get_node(name, nodename)
\r
649 local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node)
\r
650 worldedit.player_notify(name, count .. " nodes added")
\r
651 end, check_pyramid),
\r
654 minetest.register_chatcommand("/spiral", {
\r
655 params = "<length> <height> <space> <node>",
\r
656 description = "Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <space>, composed of <node>",
\r
657 privs = {worldedit=true},
\r
658 func = safe_region(function(name, param)
\r
659 local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
\r
660 local node = get_node(name, nodename)
\r
661 local count = worldedit.spiral(worldedit.pos1[name], tonumber(length), tonumber(height), tonumber(space), node)
\r
662 worldedit.player_notify(name, count .. " nodes added")
\r
664 function(name, param)
\r
665 if worldedit.pos1[name] == nil then
\r
666 worldedit.player_notify(name, "no position 1 selected")
\r
669 local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
\r
670 if found == nil then
\r
671 worldedit.player_notify(name, "invalid usage: " .. param)
\r
674 local node = get_node(name, nodename)
\r
675 if not node then return nil end
\r
676 return 1 -- TODO: return an useful value
\r
680 minetest.register_chatcommand("/copy", {
\r
681 params = "x/y/z/? <amount>",
\r
682 description = "Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
683 privs = {worldedit=true},
\r
684 func = safe_region(function(name, param)
\r
685 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
686 if found == nil then
\r
687 worldedit.player_notify(name, "invalid usage: " .. param)
\r
690 amount = tonumber(amount)
\r
691 if axis == "?" then
\r
692 axis, sign = worldedit.player_axis(name)
\r
693 amount = amount * sign
\r
696 local count = worldedit.copy(worldedit.pos1[name], worldedit.pos2[name], axis, amount)
\r
697 worldedit.player_notify(name, count .. " nodes copied")
\r
699 function(name, param)
\r
700 local volume = check_region(name, param)
\r
701 return volume and volume * 2 or volume
\r
705 minetest.register_chatcommand("/move", {
\r
706 params = "x/y/z/? <amount>",
\r
707 description = "Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
708 privs = {worldedit=true},
\r
709 func = safe_region(function(name, param)
\r
710 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
711 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
712 if found == nil then
\r
713 worldedit.player_notify(name, "invalid usage: " .. param)
\r
716 amount = tonumber(amount)
\r
717 if axis == "?" then
\r
718 axis, sign = worldedit.player_axis(name)
\r
719 amount = amount * sign
\r
722 local count = worldedit.move(pos1, pos2, axis, amount)
\r
724 pos1[axis] = pos1[axis] + amount
\r
725 pos2[axis] = pos2[axis] + amount
\r
726 worldedit.mark_pos1(name)
\r
727 worldedit.mark_pos2(name)
\r
728 worldedit.player_notify(name, count .. " nodes moved")
\r
729 end, check_region),
\r
732 minetest.register_chatcommand("/stack", {
\r
733 params = "x/y/z/? <count>",
\r
734 description = "Stack the current WorldEdit region along the x/y/z/? axis <count> times",
\r
735 privs = {worldedit=true},
\r
736 func = safe_region(function(name, param)
\r
737 local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
738 repetitions = tonumber(repetitions)
\r
739 if axis == "?" then
\r
740 axis, sign = worldedit.player_axis(name)
\r
741 repetitions = repetitions * sign
\r
743 local count = worldedit.stack(worldedit.pos1[name], worldedit.pos2[name], axis, repetitions)
\r
744 worldedit.player_notify(name, count .. " nodes stacked")
\r
746 function(name, param)
\r
747 local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
748 if found == nil then
\r
749 worldedit.player_notify(name, "invalid usage: " .. param)
\r
752 local count = check_region(name, param)
\r
753 if count then return (tonumber(repetitions) + 1) * count end
\r
758 minetest.register_chatcommand("/stack2", {
\r
759 params = "<count> <x> <y> <z>",
\r
760 description = "Stack the current WorldEdit region <count> times by offset <x>, <y>, <z>",
\r
761 privs = {worldedit=true},
\r
762 func = function(name, param)
\r
763 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
764 if pos1 == nil or pos2 == nil then
\r
765 worldedit.player_notify(name, "Select a position first!")
\r
768 local repetitions, incs = param:match("(%d+)%s*(.+)")
\r
769 if repetitions == nil then
\r
770 worldedit.player_notify(name, "invalid count: " .. param)
\r
773 repetitions = tonumber(repetitions)
\r
775 local x, y, z = incs:match("([+-]?%d+) ([+-]?%d+) ([+-]?%d+)")
\r
777 worldedit.player_notify(name, "invalid increments: " .. param)
\r
780 x, y, z = tonumber(x), tonumber(y), tonumber(z)
\r
782 local count = worldedit.volume(pos1, pos2) * repetitions
\r
784 return safe_region(function()
\r
785 worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions,
\r
786 function() worldedit.player_notify(name, count .. " nodes stacked") end)
\r
789 end)(name,param) -- more hax --wip: clean this up a little bit
\r
794 minetest.register_chatcommand("/stretch", {
\r
795 params = "<stretchx> <stretchy> <stretchz>",
\r
796 description = "Scale the current WorldEdit positions and region by a factor of <stretchx>, <stretchy>, <stretchz> along the X, Y, and Z axes, repectively, with position 1 as the origin",
\r
797 privs = {worldedit=true},
\r
798 func = safe_region(function(name, param)
\r
799 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
800 local found, _, stretchx, stretchy, stretchz = param:find("^(%d+)%s+(%d+)%s+(%d+)$")
\r
801 stretchx, stretchy, stretchz = tonumber(stretchx), tonumber(stretchy), tonumber(stretchz)
\r
802 local count, pos1, pos2 = worldedit.stretch(pos1, pos2, stretchx, stretchy, stretchz)
\r
804 --reset markers to scaled positions
\r
805 worldedit.pos1[name] = pos1
\r
806 worldedit.pos2[name] = pos2
\r
807 worldedit.mark_pos1(name)
\r
808 worldedit.mark_pos2(name)
\r
810 worldedit.player_notify(name, count .. " nodes stretched")
\r
812 function(name, param)
\r
813 local found, _, stretchx, stretchy, stretchz = param:find("^(%d+)%s+(%d+)%s+(%d+)$")
\r
814 if found == nil then
\r
815 worldedit.player_notify(name, "invalid usage: " .. param)
\r
818 stretchx, stretchy, stretchz = tonumber(stretchx), tonumber(stretchy), tonumber(stretchz)
\r
819 if stretchx == 0 or stretchy == 0 or stretchz == 0 then
\r
820 worldedit.player_notify(name, "invalid scaling factors: " .. param)
\r
822 local count = check_region(name, param)
\r
823 if count then return tonumber(stretchx) * tonumber(stretchy) * tonumber(stretchz) * count end
\r
828 minetest.register_chatcommand("/transpose", {
\r
829 params = "x/y/z/? x/y/z/?",
\r
830 description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",
\r
831 privs = {worldedit=true},
\r
832 func = safe_region(function(name, param)
\r
833 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
834 local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")
\r
835 if axis1 == "?" then axis1 = worldedit.player_axis(name) end
\r
836 if axis2 == "?" then axis2 = worldedit.player_axis(name) end
\r
837 local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
\r
839 --reset markers to transposed positions
\r
840 worldedit.pos1[name] = pos1
\r
841 worldedit.pos2[name] = pos2
\r
842 worldedit.mark_pos1(name)
\r
843 worldedit.mark_pos2(name)
\r
845 worldedit.player_notify(name, count .. " nodes transposed")
\r
847 function(name, param)
\r
848 local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")
\r
849 if found == nil then
\r
850 worldedit.player_notify(name, "invalid usage: " .. param)
\r
853 if axis1 == axis2 then
\r
854 worldedit.player_notify(name, "invalid usage: axes must be different")
\r
857 return check_region(name, param)
\r
861 minetest.register_chatcommand("/flip", {
\r
862 params = "x/y/z/?",
\r
863 description = "Flip the current WorldEdit region along the x/y/z/? axis",
\r
864 privs = {worldedit=true},
\r
865 func = safe_region(function(name, param)
\r
866 if param == "?" then param = worldedit.player_axis(name) end
\r
867 local count = worldedit.flip(worldedit.pos1[name], worldedit.pos2[name], param)
\r
868 worldedit.player_notify(name, count .. " nodes flipped")
\r
870 function(name, param)
\r
871 if param ~= "x" and param ~= "y" and param ~= "z" and param ~= "?" then
\r
872 worldedit.player_notify(name, "invalid usage: " .. param)
\r
875 return check_region(name, param)
\r
879 minetest.register_chatcommand("/rotate", {
\r
880 params = "<axis> <angle>",
\r
881 description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",
\r
882 privs = {worldedit=true},
\r
883 func = safe_region(function(name, param)
\r
884 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
885 local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
886 if axis == "?" then axis = worldedit.player_axis(name) end
\r
887 local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)
\r
889 --reset markers to rotated positions
\r
890 worldedit.pos1[name] = pos1
\r
891 worldedit.pos2[name] = pos2
\r
892 worldedit.mark_pos1(name)
\r
893 worldedit.mark_pos2(name)
\r
895 worldedit.player_notify(name, count .. " nodes rotated")
\r
897 function(name, param)
\r
898 local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
899 if found == nil then
\r
900 worldedit.player_notify(name, "invalid usage: " .. param)
\r
903 if angle % 90 ~= 0 then
\r
904 worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")
\r
907 return check_region(name, param)
\r
911 minetest.register_chatcommand("/orient", {
\r
912 params = "<angle>",
\r
913 description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)",
\r
914 privs = {worldedit=true},
\r
915 func = safe_region(function(name, param)
\r
916 local found, _, angle = param:find("^([+-]?%d+)$")
\r
917 local count = worldedit.orient(worldedit.pos1[name], worldedit.pos2[name], angle)
\r
918 worldedit.player_notify(name, count .. " nodes oriented")
\r
920 function(name, param)
\r
921 local found, _, angle = param:find("^([+-]?%d+)$")
\r
922 if found == nil then
\r
923 worldedit.player_notify(name, "invalid usage: " .. param)
\r
926 if angle % 90 ~= 0 then
\r
927 worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")
\r
930 return check_region(name, param)
\r
934 minetest.register_chatcommand("/fixlight", {
\r
936 description = "Fix the lighting in the current WorldEdit region",
\r
937 privs = {worldedit=true},
\r
938 func = safe_region(function(name, param)
\r
939 local count = worldedit.fixlight(worldedit.pos1[name], worldedit.pos2[name])
\r
940 worldedit.player_notify(name, count .. " nodes updated")
\r
944 minetest.register_chatcommand("/drain", {
\r
946 description = "Remove any fluid node within the current WorldEdit region",
\r
947 privs = {worldedit=true},
\r
948 func = safe_region(function(name, param)
\r
949 -- TODO: make an API function for this
\r
951 local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name])
\r
952 for x = pos1.x, pos2.x do
\r
953 for y = pos1.y, pos2.y do
\r
954 for z = pos1.z, pos2.z do
\r
955 local n = minetest.get_node({x=x, y=y, z=z}).name
\r
956 local d = minetest.registered_nodes[n]
\r
957 if d ~= nil and (d["drawtype"] == "liquid" or d["drawtype"] == "flowingliquid") then
\r
958 minetest.remove_node({x=x, y=y, z=z})
\r
964 worldedit.player_notify(name, count .. " nodes updated")
\r
968 minetest.register_chatcommand("/hide", {
\r
970 description = "Hide all nodes in the current WorldEdit region non-destructively",
\r
971 privs = {worldedit=true},
\r
972 func = safe_region(function(name, param)
\r
973 local count = worldedit.hide(worldedit.pos1[name], worldedit.pos2[name])
\r
974 worldedit.player_notify(name, count .. " nodes hidden")
\r
978 minetest.register_chatcommand("/suppress", {
\r
980 description = "Suppress all <node> in the current WorldEdit region non-destructively",
\r
981 privs = {worldedit=true},
\r
982 func = safe_region(function(name, param)
\r
983 local node = get_node(name, param)
\r
984 local count = worldedit.suppress(worldedit.pos1[name], worldedit.pos2[name], node)
\r
985 worldedit.player_notify(name, count .. " nodes suppressed")
\r
986 end, check_region),
\r
989 minetest.register_chatcommand("/highlight", {
\r
991 description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",
\r
992 privs = {worldedit=true},
\r
993 func = safe_region(function(name, param)
\r
994 local node = get_node(name, param)
\r
995 local count = worldedit.highlight(worldedit.pos1[name], worldedit.pos2[name], node)
\r
996 worldedit.player_notify(name, count .. " nodes highlighted")
\r
997 end, check_region),
\r
1000 minetest.register_chatcommand("/restore", {
\r
1002 description = "Restores nodes hidden with WorldEdit in the current WorldEdit region",
\r
1003 privs = {worldedit=true},
\r
1004 func = safe_region(function(name, param)
\r
1005 local count = worldedit.restore(worldedit.pos1[name], worldedit.pos2[name])
\r
1006 worldedit.player_notify(name, count .. " nodes restored")
\r
1010 minetest.register_chatcommand("/save", {
\r
1011 params = "<file>",
\r
1012 description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",
\r
1013 privs = {worldedit=true},
\r
1014 func = safe_region(function(name, param)
\r
1015 if param == "" then
\r
1016 worldedit.player_notify(name, "invalid usage: " .. param)
\r
1019 if not check_filename(param) then
\r
1020 worldedit.player_notify(name, "Disallowed file name: " .. param)
\r
1023 local result, count = worldedit.serialize(worldedit.pos1[name],
\r
1024 worldedit.pos2[name])
\r
1026 local path = minetest.get_worldpath() .. "/schems"
\r
1027 -- Create directory if it does not already exist
\r
1030 local filename = path .. "/" .. param .. ".we"
\r
1031 local file, err = io.open(filename, "wb")
\r
1032 if err ~= nil then
\r
1033 worldedit.player_notify(name, "Could not save file to \"" .. filename .. "\"")
\r
1036 file:write(result)
\r
1040 worldedit.player_notify(name, count .. " nodes saved")
\r
1044 minetest.register_chatcommand("/allocate", {
\r
1045 params = "<file>",
\r
1046 description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",
\r
1047 privs = {worldedit=true},
\r
1048 func = function(name, param)
\r
1049 local pos = get_position(name)
\r
1050 if pos == nil then return end
\r
1052 if param == "" then
\r
1053 worldedit.player_notify(name, "invalid usage: " .. param)
\r
1056 if not check_filename(param) then
\r
1057 worldedit.player_notify(name, "Disallowed file name: " .. param)
\r
1061 local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"
\r
1062 local file, err = io.open(filename, "rb")
\r
1063 if err ~= nil then
\r
1064 worldedit.player_notify(name, "could not open file \"" .. filename .. "\"")
\r
1067 local value = file:read("*a")
\r
1070 local version = worldedit.read_header(value)
\r
1071 if version == 0 then
\r
1072 worldedit.player_notify(name, "File is invalid!")
\r
1074 elseif version > worldedit.LATEST_SERIALIZATION_VERSION then
\r
1075 worldedit.player_notify(name, "File was created with newer version of WorldEdit!")
\r
1077 local nodepos1, nodepos2, count = worldedit.allocate(pos, value)
\r
1079 worldedit.pos1[name] = nodepos1
\r
1080 worldedit.mark_pos1(name)
\r
1081 worldedit.pos2[name] = nodepos2
\r
1082 worldedit.mark_pos2(name)
\r
1084 worldedit.player_notify(name, count .. " nodes allocated")
\r
1088 minetest.register_chatcommand("/load", {
\r
1089 params = "<file>",
\r
1090 description = "Load nodes from \"(world folder)/schems/<file>[.we[m]]\" with position 1 of the current WorldEdit region as the origin",
\r
1091 privs = {worldedit=true},
\r
1092 func = function(name, param)
\r
1093 local pos = get_position(name)
\r
1094 if pos == nil then return end
\r
1096 if param == "" then
\r
1097 worldedit.player_notify(name, "invalid usage: " .. param)
\r
1100 if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then
\r
1101 worldedit.player_notify(name, "invalid file name: " .. param)
\r
1105 --find the file in the world path
\r
1106 local testpaths = {
\r
1107 minetest.get_worldpath() .. "/schems/" .. param,
\r
1108 minetest.get_worldpath() .. "/schems/" .. param .. ".we",
\r
1109 minetest.get_worldpath() .. "/schems/" .. param .. ".wem",
\r
1112 for index, path in ipairs(testpaths) do
\r
1113 file, err = io.open(path, "rb")
\r
1119 worldedit.player_notify(name, "could not open file \"" .. param .. "\"")
\r
1122 local value = file:read("*a")
\r
1125 local version = worldedit.read_header(value)
\r
1126 if version == 0 then
\r
1127 worldedit.player_notify(name, "File is invalid!")
\r
1129 elseif version > worldedit.LATEST_SERIALIZATION_VERSION then
\r
1130 worldedit.player_notify(name, "File was created with newer version of WorldEdit!")
\r
1134 local count = worldedit.deserialize(pos, value)
\r
1136 worldedit.player_notify(name, count .. " nodes loaded")
\r
1140 minetest.register_chatcommand("/lua", {
\r
1141 params = "<code>",
\r
1142 description = "Executes <code> as a Lua chunk in the global namespace",
\r
1143 privs = {worldedit=true, server=true},
\r
1144 func = function(name, param)
\r
1145 local err = worldedit.lua(param)
\r
1147 worldedit.player_notify(name, "code error: " .. err)
\r
1148 minetest.log("action", name.." tried to execute "..param)
\r
1150 worldedit.player_notify(name, "code successfully executed", false)
\r
1151 minetest.log("action", name.." executed "..param)
\r
1156 minetest.register_chatcommand("/luatransform", {
\r
1157 params = "<code>",
\r
1158 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
1159 privs = {worldedit=true, server=true},
\r
1160 func = safe_region(function(name, param)
\r
1161 local err = worldedit.luatransform(worldedit.pos1[name], worldedit.pos2[name], param)
\r
1163 worldedit.player_notify(name, "code error: " .. err, false)
\r
1164 minetest.log("action", name.." tried to execute luatransform "..param)
\r
1166 worldedit.player_notify(name, "code successfully executed", false)
\r
1167 minetest.log("action", name.." executed luatransform "..param)
\r
1172 minetest.register_chatcommand("/mtschemcreate", {
\r
1173 params = "<file>",
\r
1174 description = "Save the current WorldEdit region using the Minetest "..
\r
1175 "Schematic format to \"(world folder)/schems/<filename>.mts\"",
\r
1176 privs = {worldedit=true},
\r
1177 func = safe_region(function(name, param)
\r
1178 if param == nil then
\r
1179 worldedit.player_notify(name, "No filename specified")
\r
1182 if not check_filename(param) then
\r
1183 worldedit.player_notify(name, "Disallowed file name: " .. param)
\r
1187 local path = minetest.get_worldpath() .. "/schems"
\r
1188 -- Create directory if it does not already exist
\r
1191 local filename = path .. "/" .. param .. ".mts"
\r
1192 local ret = minetest.create_schematic(worldedit.pos1[name],
\r
1193 worldedit.pos2[name], worldedit.prob_list[name],
\r
1195 if ret == nil then
\r
1196 worldedit.player_notify(name, "Failed to create Minetest schematic", false)
\r
1198 worldedit.player_notify(name, "Saved Minetest schematic to " .. param, false)
\r
1200 worldedit.prob_list[name] = {}
\r
1204 minetest.register_chatcommand("/mtschemplace", {
\r
1205 params = "<file>",
\r
1206 description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",
\r
1207 privs = {worldedit=true},
\r
1208 func = function(name, param)
\r
1209 if param == "" then
\r
1210 worldedit.player_notify(name, "no filename specified")
\r
1213 if not check_filename(param) then
\r
1214 worldedit.player_notify(name, "Disallowed file name: " .. param)
\r
1218 local pos = get_position(name)
\r
1219 if pos == nil then return end
\r
1221 local path = minetest.get_worldpath() .. "/schems/" .. param .. ".mts"
\r
1222 if minetest.place_schematic(pos, path) == nil then
\r
1223 worldedit.player_notify(name, "failed to place Minetest schematic", false)
\r
1225 worldedit.player_notify(name, "placed Minetest schematic " .. param ..
\r
1226 " at " .. minetest.pos_to_string(pos), false)
\r
1231 minetest.register_chatcommand("/mtschemprob", {
\r
1232 params = "start/finish/get",
\r
1233 description = "Begins node probability entry for Minetest schematics, gets the nodes that have probabilities set, or ends node probability entry",
\r
1234 privs = {worldedit=true},
\r
1235 func = function(name, param)
\r
1236 if param == "start" then --start probability setting
\r
1237 worldedit.set_pos[name] = "prob"
\r
1238 worldedit.prob_list[name] = {}
\r
1239 worldedit.player_notify(name, "select Minetest schematic probability values by punching nodes")
\r
1240 elseif param == "finish" then --finish probability setting
\r
1241 worldedit.set_pos[name] = nil
\r
1242 worldedit.player_notify(name, "finished Minetest schematic probability selection")
\r
1243 elseif param == "get" then --get all nodes that had probabilities set on them
\r
1245 local problist = worldedit.prob_list[name]
\r
1246 if problist == nil then
\r
1249 for k,v in pairs(problist) do
\r
1250 local prob = math.floor(((v.prob / 256) * 100) * 100 + 0.5) / 100
\r
1251 text = text .. minetest.pos_to_string(v.pos) .. ": " .. prob .. "% | "
\r
1253 worldedit.player_notify(name, "currently set node probabilities:")
\r
1254 worldedit.player_notify(name, text)
\r
1256 worldedit.player_notify(name, "unknown subcommand: " .. param)
\r
1261 minetest.register_on_player_receive_fields(function(player, formname, fields)
\r
1262 if formname == "prob_val_enter" and not (fields.text == "" or fields.text == nil) then
\r
1263 local name = player:get_player_name()
\r
1264 local prob_entry = {pos=worldedit.prob_pos[name], prob=tonumber(fields.text)}
\r
1265 local index = table.getn(worldedit.prob_list[name]) + 1
\r
1266 worldedit.prob_list[name][index] = prob_entry
\r
1270 minetest.register_chatcommand("/clearobjects", {
\r
1272 description = "Clears all objects within the WorldEdit region",
\r
1273 privs = {worldedit=true},
\r
1274 func = safe_region(function(name, param)
\r
1275 local count = worldedit.clear_objects(worldedit.pos1[name], worldedit.pos2[name])
\r
1276 worldedit.player_notify(name, count .. " objects cleared")
\r