1 minetest.register_privilege("worldedit", "Can use WorldEdit commands")
\r
3 worldedit.set_pos = {}
\r
8 dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")
\r
10 --determines whether `nodename` is a valid node name, returning a boolean
\r
11 worldedit.node_is_valid = function(nodename)
\r
12 return minetest.registered_nodes[nodename] ~= nil
\r
13 or minetest.registered_nodes["default:" .. nodename] ~= nil
\r
16 --determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
\r
17 worldedit.player_axis = function(name)
\r
18 local dir = minetest.env:get_player_by_name(name):get_look_dir()
\r
19 local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
\r
22 return "x", dir.x > 0 and 1 or -1
\r
25 return "y", dir.y > 0 and 1 or -1
\r
27 return "z", dir.z > 0 and 1 or -1
\r
30 minetest.register_chatcommand("/reset", {
\r
32 description = "Reset the region so that it is empty",
\r
33 privs = {worldedit=true},
\r
34 func = function(name, param)
\r
35 worldedit.pos1[name] = nil
\r
36 worldedit.pos2[name] = nil
\r
37 worldedit.mark_pos1(name)
\r
38 worldedit.mark_pos2(name)
\r
39 minetest.chat_send_player(name, "WorldEdit region reset")
\r
43 minetest.register_chatcommand("/mark", {
\r
45 description = "Show markers at the region positions",
\r
46 privs = {worldedit=true},
\r
47 func = function(name, param)
\r
48 worldedit.mark_pos1(name)
\r
49 worldedit.mark_pos2(name)
\r
50 minetest.chat_send_player(name, "WorldEdit region marked")
\r
54 minetest.register_chatcommand("/pos1", {
\r
56 description = "Set WorldEdit region position 1 to the player's location",
\r
57 privs = {worldedit=true},
\r
58 func = function(name, param)
\r
59 local pos = minetest.env:get_player_by_name(name):getpos()
\r
60 pos.x, pos.y, pos.z = math.floor(pos.x), math.floor(pos.y), math.floor(pos.z)
\r
61 worldedit.pos1[name] = pos
\r
62 worldedit.mark_pos1(name)
\r
63 minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))
\r
67 minetest.register_chatcommand("/pos2", {
\r
69 description = "Set WorldEdit region position 2 to the player's location",
\r
70 privs = {worldedit=true},
\r
71 func = function(name, param)
\r
72 local pos = minetest.env:get_player_by_name(name):getpos()
\r
73 pos.x, pos.y, pos.z = math.floor(pos.x), math.floor(pos.y), math.floor(pos.z)
\r
74 worldedit.pos2[name] = pos
\r
75 worldedit.mark_pos2(name)
\r
76 minetest.chat_send_player(name, "WorldEdit position 2 set to " .. minetest.pos_to_string(pos))
\r
80 minetest.register_chatcommand("/p", {
\r
81 params = "set/set1/set2/get",
\r
82 description = "Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region",
\r
83 privs = {worldedit=true},
\r
84 func = function(name, param)
\r
85 if param == "set" then --set both WorldEdit positions
\r
86 worldedit.set_pos[name] = "pos1"
\r
87 minetest.chat_send_player(name, "Select positions by punching two nodes")
\r
88 elseif param == "set1" then --set WorldEdit position 1
\r
89 worldedit.set_pos[name] = "pos1only"
\r
90 minetest.chat_send_player(name, "Select position 1 by punching a node")
\r
91 elseif param == "set2" then --set WorldEdit position 2
\r
92 worldedit.set_pos[name] = "pos2"
\r
93 minetest.chat_send_player(name, "Select position 2 by punching a node")
\r
94 elseif param == "get" then --display current WorldEdit positions
\r
95 if worldedit.pos1[name] ~= nil then
\r
96 minetest.chat_send_player(name, "WorldEdit position 1: " .. minetest.pos_to_string(worldedit.pos1[name]))
\r
98 minetest.chat_send_player(name, "WorldEdit position 1 not set")
\r
100 if worldedit.pos2[name] ~= nil then
\r
101 minetest.chat_send_player(name, "WorldEdit position 2: " .. minetest.pos_to_string(worldedit.pos2[name]))
\r
103 minetest.chat_send_player(name, "WorldEdit position 2 not set")
\r
106 minetest.chat_send_player(name, "Unknown subcommand: " .. param)
\r
111 minetest.register_on_punchnode(function(pos, node, puncher)
\r
112 local name = puncher:get_player_name()
\r
113 if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position
\r
114 if worldedit.set_pos[name] == "pos1" then --setting position 1
\r
115 worldedit.pos1[name] = pos
\r
116 worldedit.mark_pos1(name)
\r
117 worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation
\r
118 minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))
\r
119 elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only
\r
120 worldedit.pos1[name] = pos
\r
121 worldedit.mark_pos1(name)
\r
122 worldedit.set_pos[name] = nil --finished setting positions
\r
123 minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))
\r
124 elseif worldedit.set_pos[name] == "pos2" then --setting position 2
\r
125 worldedit.pos2[name] = pos
\r
126 worldedit.mark_pos2(name)
\r
127 worldedit.set_pos[name] = nil --finished setting positions
\r
128 minetest.chat_send_player(name, "WorldEdit position 2 set to " .. minetest.pos_to_string(pos))
\r
133 minetest.register_chatcommand("/volume", {
\r
135 description = "Display the volume of the current WorldEdit region",
\r
136 privs = {worldedit=true},
\r
137 func = function(name, param)
\r
138 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
139 if pos1 == nil or pos2 == nil then
\r
140 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
144 local volume = worldedit.volume(pos1, pos2)
\r
145 minetest.chat_send_player(name, "Current WorldEdit region has a volume of " .. volume .. " nodes (" .. pos2.x - pos1.x .. "*" .. pos2.y - pos1.y .. "*" .. pos2.z - pos1.z .. ")")
\r
149 minetest.register_chatcommand("/set", {
\r
151 description = "Set the current WorldEdit region to <node>",
\r
152 privs = {worldedit=true},
\r
153 func = function(name, param)
\r
154 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
155 if pos1 == nil or pos2 == nil then
\r
156 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
160 if param == "" or not worldedit.node_is_valid(param) then
\r
161 minetest.chat_send_player(name, "Invalid node name: " .. param)
\r
165 local count = worldedit.set(pos1, pos2, param)
\r
166 minetest.chat_send_player(name, count .. " nodes set")
\r
170 minetest.register_chatcommand("/replace", {
\r
171 params = "<search node> <replace node>",
\r
172 description = "Replace all instances of <search node> with <place node> in the current WorldEdit region",
\r
173 privs = {worldedit=true},
\r
174 func = function(name, param)
\r
175 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
176 if pos1 == nil or pos2 == nil then
\r
177 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
181 local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")
\r
182 if found == nil then
\r
183 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
186 if not worldedit.node_is_valid(searchnode) then
\r
187 minetest.chat_send_player(name, "Invalid search node name: " .. searchnode)
\r
190 if not worldedit.node_is_valid(replacenode) then
\r
191 minetest.chat_send_player(name, "Invalid replace node name: " .. replacenode)
\r
195 local count = worldedit.replace(pos1, pos2, searchnode, replacenode)
\r
196 minetest.chat_send_player(name, count .. " nodes replaced")
\r
200 minetest.register_chatcommand("/hollowsphere", {
\r
201 params = "<radius> <node>",
\r
202 description = "Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
203 privs = {worldedit=true},
\r
204 func = function(name, param)
\r
205 local pos = worldedit.pos1[name]
\r
207 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
211 local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
\r
212 if found == nil then
\r
213 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
216 if not worldedit.node_is_valid(nodename) then
\r
217 minetest.chat_send_player(name, "Invalid node name: " .. param)
\r
221 local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename)
\r
222 minetest.chat_send_player(name, count .. " nodes added")
\r
226 minetest.register_chatcommand("/sphere", {
\r
227 params = "<radius> <node>",
\r
228 description = "Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>",
\r
229 privs = {worldedit=true},
\r
230 func = function(name, param)
\r
231 local pos = worldedit.pos1[name]
\r
233 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
237 local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
\r
238 if found == nil then
\r
239 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
242 if not worldedit.node_is_valid(nodename) then
\r
243 minetest.chat_send_player(name, "Invalid node name: " .. param)
\r
247 local count = worldedit.sphere(pos, tonumber(radius), nodename)
\r
248 minetest.chat_send_player(name, count .. " nodes added")
\r
252 minetest.register_chatcommand("/hollowcylinder", {
\r
253 params = "x/y/z/? <length> <radius> <node>",
\r
254 description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
\r
255 privs = {worldedit=true},
\r
256 func = function(name, param)
\r
257 local pos = worldedit.pos1[name]
\r
259 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
263 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")
\r
264 if found == nil then
\r
265 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
268 if axis == "?" then
\r
269 axis, sign = worldedit.player_axis(name)
\r
270 length = length * sign
\r
272 if not worldedit.node_is_valid(nodename) then
\r
273 minetest.chat_send_player(name, "Invalid node name: " .. param)
\r
277 local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), nodename)
\r
278 minetest.chat_send_player(name, count .. " nodes added")
\r
282 minetest.register_chatcommand("/cylinder", {
\r
283 params = "x/y/z/? <length> <radius> <node>",
\r
284 description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
\r
285 privs = {worldedit=true},
\r
286 func = function(name, param)
\r
287 local pos = worldedit.pos1[name]
\r
289 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
293 local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")
\r
294 if found == nil then
\r
295 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
298 if axis == "?" then
\r
299 axis, sign = worldedit.player_axis(name)
\r
300 length = length * sign
\r
302 if not worldedit.node_is_valid(nodename) then
\r
303 minetest.chat_send_player(name, "Invalid node name: " .. param)
\r
307 local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), nodename)
\r
308 minetest.chat_send_player(name, count .. " nodes added")
\r
312 minetest.register_chatcommand("/pyramid", {
\r
313 params = "<height> <node>",
\r
314 description = "Add pyramid at WorldEdit position 1 with height <height>, composed of <node>",
\r
315 privs = {worldedit=true},
\r
316 func = function(name, param)
\r
317 local pos = worldedit.pos1[name]
\r
319 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
323 local found, _, size, nodename = param:find("(%d+)%s+([^%s]+)$")
\r
324 if found == nil then
\r
325 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
328 if not worldedit.node_is_valid(nodename) then
\r
329 minetest.chat_send_player(name, "Invalid node name: " .. param)
\r
333 local count = worldedit.pyramid(pos, tonumber(size), nodename)
\r
334 minetest.chat_send_player(name, count .. " nodes added")
\r
338 minetest.register_chatcommand("/spiral", {
\r
339 params = "<width> <height> <space> <node>",
\r
340 description = "Add spiral at WorldEdit position 1 with width <width>, height <height>, space between walls <space>, composed of <node>",
\r
341 privs = {worldedit=true},
\r
342 func = function(name, param)
\r
343 local pos = worldedit.pos1[name]
\r
345 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
349 local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+([^%s]+)$")
\r
350 if found == nil then
\r
351 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
354 if not worldedit.node_is_valid(nodename) then
\r
355 minetest.chat_send_player(name, "Invalid node name: " .. param)
\r
359 local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), nodename)
\r
360 minetest.chat_send_player(name, count .. " nodes changed")
\r
364 minetest.register_chatcommand("/copy", {
\r
365 params = "x/y/z/? <amount>",
\r
366 description = "Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
367 privs = {worldedit=true},
\r
368 func = function(name, param)
\r
369 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
370 if pos1 == nil or pos2 == nil then
\r
371 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
375 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
376 if found == nil then
\r
377 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
380 if axis == "?" then
\r
381 axis, sign = worldedit.player_axis(name)
\r
382 amount = amount * sign
\r
385 local count = worldedit.copy(pos1, pos2, axis, tonumber(amount))
\r
386 minetest.chat_send_player(name, count .. " nodes copied")
\r
390 minetest.register_chatcommand("/move", {
\r
391 params = "x/y/z/? <amount>",
\r
392 description = "Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
\r
393 privs = {worldedit=true},
\r
394 func = function(name, param)
\r
395 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
396 if pos1 == nil or pos2 == nil then
\r
397 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
401 local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
402 if found == nil then
\r
403 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
406 if axis == "?" then
\r
407 axis, sign = worldedit.player_axis(name)
\r
408 amount = amount * sign
\r
411 local count = worldedit.move(pos1, pos2, axis, tonumber(amount))
\r
413 pos1[axis] = pos1[axis] + amount
\r
414 pos2[axis] = pos2[axis] + amount
\r
415 worldedit.mark_pos1(name)
\r
416 worldedit.mark_pos2(name)
\r
418 minetest.chat_send_player(name, count .. " nodes moved")
\r
422 minetest.register_chatcommand("/stack", {
\r
423 params = "x/y/z/? <count>",
\r
424 description = "Stack the current WorldEdit region along the x/y/z/? axis <count> times",
\r
425 privs = {worldedit=true},
\r
426 func = function(name, param)
\r
427 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
428 if pos1 == nil or pos2 == nil then
\r
429 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
433 local found, _, axis, count = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
434 if found == nil then
\r
435 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
438 if axis == "?" then
\r
439 axis, sign = worldedit.player_axis(name)
\r
440 count = count * sign
\r
443 local count = worldedit.stack(pos1, pos2, axis, tonumber(count))
\r
444 minetest.chat_send_player(name, count .. " nodes stacked")
\r
448 minetest.register_chatcommand("/transpose", {
\r
449 params = "x/y/z/? x/y/z/?",
\r
450 description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",
\r
451 privs = {worldedit=true},
\r
452 func = function(name, param)
\r
453 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
454 if pos1 == nil or pos2 == nil then
\r
455 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
459 local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")
\r
460 if found == nil then
\r
461 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
464 if axis1 == "?" then
\r
465 axis1 = worldedit.player_axis(name)
\r
467 if axis2 == "?" then
\r
468 axis2 = worldedit.player_axis(name)
\r
470 if axis1 == axis2 then
\r
471 minetest.chat_send_player(name, "Invalid usage: axes are the same")
\r
475 local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
\r
477 --reset markers to transposed positions
\r
478 worldedit.pos1[name] = pos1
\r
479 worldedit.pos2[name] = pos2
\r
480 worldedit.mark_pos1(name)
\r
481 worldedit.mark_pos2(name)
\r
483 minetest.chat_send_player(name, count .. " nodes transposed")
\r
487 minetest.register_chatcommand("/flip", {
\r
488 params = "x/y/z/?",
\r
489 description = "Flip the current WorldEdit region along the x/y/z/? axis",
\r
490 privs = {worldedit=true},
\r
491 func = function(name, param)
\r
492 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
493 if pos1 == nil or pos2 == nil then
\r
494 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
498 if param == "?" then
\r
499 param = worldedit.player_axis(name)
\r
501 if param ~= "x" and param ~= "y" and param ~= "z" then
\r
502 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
506 local count = worldedit.flip(pos1, pos2, param)
\r
507 minetest.chat_send_player(name, count .. " nodes flipped")
\r
511 minetest.register_chatcommand("/rotate", {
\r
512 params = "<axis> <angle>",
\r
513 description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",
\r
514 privs = {worldedit=true},
\r
515 func = function(name, param)
\r
516 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
517 if pos1 == nil or pos2 == nil then
\r
518 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
522 local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")
\r
523 if found == nil then
\r
524 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
527 if axis == "?" then
\r
528 axis = worldedit.player_axis(name)
\r
530 if angle % 90 ~= 0 then
\r
531 minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90")
\r
535 local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)
\r
537 --reset markers to rotated positions
\r
538 worldedit.pos1[name] = pos1
\r
539 worldedit.pos2[name] = pos2
\r
540 worldedit.mark_pos1(name)
\r
541 worldedit.mark_pos2(name)
\r
543 minetest.chat_send_player(name, count .. " nodes rotated")
\r
547 minetest.register_chatcommand("/dig", {
\r
549 description = "Dig the current WorldEdit region",
\r
550 privs = {worldedit=true},
\r
551 func = function(name, param)
\r
552 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
553 if pos1 == nil or pos2 == nil then
\r
554 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
558 local count = worldedit.dig(pos1, pos2)
\r
559 minetest.chat_send_player(name, count .. " nodes dug")
\r
563 minetest.register_chatcommand("/hide", {
\r
565 description = "Hide all nodes in the current WorldEdit region non-destructively",
\r
566 privs = {worldedit=true},
\r
567 func = function(name, param)
\r
568 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
569 if pos1 == nil or pos2 == nil then
\r
570 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
574 local count = worldedit.hide(pos1, pos2)
\r
575 minetest.chat_send_player(name, count .. " nodes hidden")
\r
579 minetest.register_chatcommand("/suppress", {
\r
581 description = "Suppress all <node> in the current WorldEdit region non-destructively",
\r
582 privs = {worldedit=true},
\r
583 func = function(name, param)
\r
584 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
585 if pos1 == nil or pos2 == nil then
\r
586 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
590 if param == "" or not worldedit.node_is_valid(param) then
\r
591 minetest.chat_send_player(name, "Invalid node name: " .. param)
\r
595 local count = worldedit.suppress(pos1, pos2, param)
\r
596 minetest.chat_send_player(name, count .. " nodes suppressed")
\r
600 minetest.register_chatcommand("/highlight", {
\r
602 description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",
\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 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
611 if param == "" or not worldedit.node_is_valid(param) then
\r
612 minetest.chat_send_player(name, "Invalid node name: " .. param)
\r
616 local count = worldedit.highlight(pos1, pos2, param)
\r
617 minetest.chat_send_player(name, count .. " nodes highlighted")
\r
621 minetest.register_chatcommand("/restore", {
\r
623 description = "Restores nodes hidden with WorldEdit in the current WorldEdit region",
\r
624 privs = {worldedit=true},
\r
625 func = function(name, param)
\r
626 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
627 if pos1 == nil or pos2 == nil then
\r
628 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
632 local count = worldedit.restore(pos1, pos2)
\r
633 minetest.chat_send_player(name, count .. " nodes restored")
\r
637 minetest.register_chatcommand("/save", {
\r
639 description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",
\r
640 privs = {worldedit=true},
\r
641 func = function(name, param)
\r
642 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
643 if pos1 == nil or pos2 == nil then
\r
644 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
648 if param == "" then
\r
649 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
653 local result, count = worldedit.serialize(pos1, pos2)
\r
655 local path = minetest.get_worldpath() .. "/schems"
\r
656 local filename = path .. "/" .. param .. ".we"
\r
657 os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
\r
658 local file, err = io.open(filename, "wb")
\r
660 minetest.chat_send_player(name, "Could not save file to \"" .. filename .. "\"")
\r
667 minetest.chat_send_player(name, count .. " nodes saved")
\r
671 minetest.register_chatcommand("/allocate", {
\r
673 description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",
\r
674 privs = {worldedit=true},
\r
675 func = function(name, param)
\r
676 local pos1 = worldedit.pos1[name]
\r
677 if pos1 == nil then
\r
678 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
682 if param == "" then
\r
683 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
687 local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"
\r
688 local file, err = io.open(filename, "rb")
\r
690 minetest.chat_send_player(name, "Could not open file \"" .. filename .. "\"")
\r
693 local value = file:read("*a")
\r
696 local nodepos1, nodepos2, count
\r
697 if value:find("{") then --old WorldEdit format
\r
698 nodepos1, nodepos2, count = worldedit.allocate_old(pos1, value)
\r
699 else --new WorldEdit format
\r
700 nodepos1, nodepos2, count = worldedit.allocate(pos1, value)
\r
703 worldedit.pos1[name] = nodepos1
\r
704 worldedit.mark_pos1(name)
\r
705 worldedit.pos2[name] = nodepos2
\r
706 worldedit.mark_pos2(name)
\r
708 minetest.chat_send_player(name, count .. " nodes allocated")
\r
712 minetest.register_chatcommand("/load", {
\r
714 description = "Load nodes from \"(world folder)/schems/<file>.we\" with position 1 of the current WorldEdit region as the origin",
\r
715 privs = {worldedit=true},
\r
716 func = function(name, param)
\r
717 local pos1 = worldedit.pos1[name]
\r
718 if pos1 == nil then
\r
719 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
723 if param == "" then
\r
724 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
728 local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"
\r
729 local file, err = io.open(filename, "rb")
\r
731 minetest.chat_send_player(name, "Could not open file \"" .. filename .. "\"")
\r
734 local value = file:read("*a")
\r
738 if value:find("{") then --old WorldEdit format
\r
739 count = worldedit.deserialize_old(pos1, value)
\r
740 else --new WorldEdit format
\r
741 count = worldedit.deserialize(pos1, value)
\r
744 minetest.chat_send_player(name, count .. " nodes loaded")
\r
748 minetest.register_chatcommand("/metasave", {
\r
750 description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.wem\"",
\r
751 privs = {worldedit=true},
\r
752 func = function(name, param)
\r
753 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
754 if pos1 == nil or pos2 == nil then
\r
755 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
758 if param == "" then
\r
759 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
762 local count, err = worldedit.metasave(pos1, pos2, param)
\r
764 minetest.chat_send_player(name, "error loading file: " .. err)
\r
766 minetest.chat_send_player(name, count .. " nodes saved")
\r
771 minetest.register_chatcommand("/metaload", {
\r
773 description = "Load nodes from \"(world folder)/schems/<file>.wem\" with position 1 of the current WorldEdit region as the origin",
\r
774 privs = {worldedit=true},
\r
775 func = function(name, param)
\r
776 local pos1 = worldedit.pos1[name]
\r
777 if pos1 == nil then
\r
778 minetest.chat_send_player(name, "No WorldEdit region selected")
\r
781 if param == "" then
\r
782 minetest.chat_send_player(name, "Invalid usage: " .. param)
\r
785 local count, err = worldedit.metaload(pos1, param)
\r
787 minetest.chat_send_player(name, "error loading file: " .. err)
\r
789 minetest.chat_send_player(name, count .. " nodes loaded")
\r