minetest.register_privilege("worldedit", "Can use WorldEdit commands")\r
\r
worldedit.set_pos = {}\r
+worldedit.inspect = {}\r
\r
worldedit.pos1 = {}\r
worldedit.pos2 = {}\r
+if minetest.place_schematic then\r
+ worldedit.prob_pos = {}\r
+ worldedit.prob_list = {}\r
+end\r
\r
dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")\r
\r
end\r
\r
--determines whether `nodename` is a valid node name, returning a boolean\r
-worldedit.node_is_valid = function(nodename)\r
- return minetest.registered_nodes[nodename] ~= nil\r
- or minetest.registered_nodes["default:" .. nodename] ~= nil\r
+worldedit.normalize_nodename = function(nodename)\r
+ local fullname = ItemStack({name=nodename}):get_name() --resolve aliases of node names to full names\r
+ if minetest.registered_nodes[fullname] then --directly found node name or alias of nodename\r
+ return fullname\r
+ end\r
+ for key, value in pairs(minetest.registered_nodes) do\r
+ if key:find(":" .. nodename, 1, true) then --found in mod\r
+ return key\r
+ end\r
+ end\r
+ nodename = nodename:lower() --lowercase both for case insensitive comparison\r
+ for key, value in pairs(minetest.registered_nodes) do\r
+ if value.description:lower() == nodename then --found in description\r
+ return key\r
+ end\r
+ end\r
+ return nil\r
end\r
\r
--determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)\r
worldedit.player_axis = function(name)\r
- local dir = minetest.env:get_player_by_name(name):get_look_dir()\r
+ local dir = minetest.get_player_by_name(name):get_look_dir()\r
local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)\r
if x > y then\r
if x > z then\r
return "z", dir.z > 0 and 1 or -1\r
end\r
\r
+minetest.register_chatcommand("/about", {\r
+ params = "",\r
+ description = "Get information about the mod",\r
+ func = function(name, param)\r
+ 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
+ end,\r
+})\r
+\r
+minetest.register_chatcommand("/inspect", {\r
+ params = "on/off/1/0/true/false/yes/no/enable/disable",\r
+ description = "Enable or disable node inspection",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" then\r
+ worldedit.inspect[name] = true\r
+ worldedit.player_notify(name, "node inspection enabled")\r
+ elseif param == "off" or param == "0" or param == "false" or param == "no" or param == "disable" then\r
+ worldedit.inspect[name] = nil\r
+ worldedit.player_notify(name, "node inspection disabled")\r
+ else\r
+ worldedit.player_notify(name, "invalid usage: " .. param)\r
+ end\r
+ end,\r
+})\r
+\r
+minetest.register_on_punchnode(function(pos, node, puncher)\r
+ local name = puncher:get_player_name()\r
+ if worldedit.inspect[name] then\r
+ if minetest.check_player_privs(name, {worldedit=true}) then\r
+ message = "inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"\r
+ else\r
+ message = "inspector: worldedit privileges required"\r
+ end\r
+ worldedit.player_notify(name, message)\r
+ end\r
+end)\r
+\r
minetest.register_chatcommand("/reset", {\r
params = "",\r
description = "Reset the region so that it is empty",\r
description = "Set WorldEdit region position 1 to the player's location",\r
privs = {worldedit=true},\r
func = function(name, param)\r
- local pos = minetest.env:get_player_by_name(name):getpos()\r
+ local pos = minetest.get_player_by_name(name):getpos()\r
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
worldedit.pos1[name] = pos\r
worldedit.mark_pos1(name)\r
description = "Set WorldEdit region position 2 to the player's location",\r
privs = {worldedit=true},\r
func = function(name, param)\r
- local pos = minetest.env:get_player_by_name(name):getpos()\r
+ local pos = minetest.get_player_by_name(name):getpos()\r
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
worldedit.pos2[name] = pos\r
worldedit.mark_pos2(name)\r
end,\r
})\r
\r
+minetest.register_chatcommand("/fixedpos", {\r
+ params = "set1/set2 x y z",\r
+ description = "Set a WorldEdit region position to the position at (<x>, <y>, <z>)",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ local found, _, flag, x, y, z = param:find("^(set[12])%s+([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)$")\r
+ if found == nil then\r
+ worldedit.player_notify(name, "invalid usage: " .. param)\r
+ return\r
+ end\r
+ local pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}\r
+ if flag == "set1" then\r
+ worldedit.pos1[name] = pos\r
+ worldedit.mark_pos1(name)\r
+ worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))\r
+ else --flag == "set2"\r
+ worldedit.pos2[name] = pos\r
+ worldedit.mark_pos2(name)\r
+ worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))\r
+ end\r
+ end,\r
+})\r
+\r
minetest.register_on_punchnode(function(pos, node, puncher)\r
local name = puncher:get_player_name()\r
if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position\r
worldedit.mark_pos2(name)\r
worldedit.set_pos[name] = nil --finished setting positions\r
worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))\r
+ elseif worldedit.set_pos[name] == "prob" then --setting Minetest schematic node probabilities\r
+ worldedit.prob_pos[name] = pos\r
+ minetest.show_formspec(puncher:get_player_name(), "prob_val_enter", "field[text;;]")\r
end\r
end\r
end)\r
end\r
\r
local volume = worldedit.volume(pos1, pos2)\r
- worldedit.player_notify(name, "current region has a volume of " .. volume .. " nodes (" .. pos2.x - pos1.x .. "*" .. pos2.y - pos1.y .. "*" .. pos2.z - pos1.z .. ")")\r
+ local abs = math.abs\r
+ worldedit.player_notify(name, "current region has a volume of " .. volume .. " nodes ("\r
+ .. abs(pos2.x - pos1.x) .. "*"\r
+ .. abs(pos2.y - pos1.y) .. "*"\r
+ .. abs(pos2.z - pos1.z) .. ")")\r
end,\r
})\r
\r
return\r
end\r
\r
- if param == "" or not worldedit.node_is_valid(param) then\r
+ local node = worldedit.normalize_nodename(param)\r
+ if param == "" or not node then\r
worldedit.player_notify(name, "invalid node name: " .. param)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
-\r
- local count = worldedit.set(pos1, pos2, param, tenv)\r
+ local count = worldedit.set(pos1, pos2, node)\r
worldedit.player_notify(name, count .. " nodes set")\r
end,\r
})\r
return\r
end\r
\r
- local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")\r
+ local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
- if not worldedit.node_is_valid(searchnode) then\r
+ local newsearchnode = worldedit.normalize_nodename(searchnode)\r
+ if not newsearchnode then\r
worldedit.player_notify(name, "invalid search node name: " .. searchnode)\r
return\r
end\r
- if not worldedit.node_is_valid(replacenode) then\r
+ local newreplacenode = worldedit.normalize_nodename(replacenode)\r
+ if not newreplacenode then\r
worldedit.player_notify(name, "invalid replace node name: " .. replacenode)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.replace(pos1, pos2, searchnode, replacenode, tenv)\r
+ local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode)\r
worldedit.player_notify(name, count .. " nodes replaced")\r
end,\r
})\r
return\r
end\r
\r
- local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")\r
+ local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
- if not worldedit.node_is_valid(searchnode) then\r
+ local newsearchnode = worldedit.normalize_nodename(searchnode)\r
+ if not newsearchnode then\r
worldedit.player_notify(name, "invalid search node name: " .. searchnode)\r
return\r
end\r
- if not worldedit.node_is_valid(replacenode) then\r
+ local newreplacenode = worldedit.normalize_nodename(replacenode)\r
+ if not newreplacenode then\r
worldedit.player_notify(name, "invalid replace node name: " .. replacenode)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode, tenv)\r
+ local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)\r
worldedit.player_notify(name, count .. " nodes replaced")\r
end,\r
})\r
\r
minetest.register_chatcommand("/hollowsphere", {\r
params = "<radius> <node>",\r
- description = "Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>",\r
+ description = "Add hollow sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos = worldedit.pos1[name]\r
return\r
end\r
\r
- local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")\r
+ local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
- if not worldedit.node_is_valid(nodename) then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\r
+ local node = worldedit.normalize_nodename(nodename)\r
+ if not node then\r
+ worldedit.player_notify(name, "invalid node name: " .. nodename)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename, tenv)\r
+ local count = worldedit.hollow_sphere(pos, tonumber(radius), node)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
\r
minetest.register_chatcommand("/sphere", {\r
params = "<radius> <node>",\r
- description = "Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>",\r
+ description = "Add sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos = worldedit.pos1[name]\r
return\r
end\r
\r
- local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")\r
+ local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
- if not worldedit.node_is_valid(nodename) then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\r
+ local node = worldedit.normalize_nodename(nodename)\r
+ if not node then\r
+ worldedit.player_notify(name, "invalid node name: " .. nodename)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.sphere(pos, tonumber(radius), nodename, tenv)\r
+ local count = worldedit.sphere(pos, tonumber(radius), node)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
\r
minetest.register_chatcommand("/hollowdome", {\r
params = "<radius> <node>",\r
- description = "Add hollow dome at WorldEdit position 1 with radius <radius>, composed of <node>",\r
+ description = "Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos = worldedit.pos1[name]\r
return\r
end\r
\r
- local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")\r
+ local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
- if not worldedit.node_is_valid(nodename) then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\r
+ local node = worldedit.normalize_nodename(nodename)\r
+ if not node then\r
+ worldedit.player_notify(name, "invalid node name: " .. nodename)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.hollow_dome(pos, tonumber(radius), nodename, tenv)\r
+ local count = worldedit.hollow_dome(pos, tonumber(radius), node)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
\r
minetest.register_chatcommand("/dome", {\r
params = "<radius> <node>",\r
- description = "Add dome at WorldEdit position 1 with radius <radius>, composed of <node>",\r
+ description = "Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos = worldedit.pos1[name]\r
return\r
end\r
\r
- local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")\r
+ local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
- if not worldedit.node_is_valid(nodename) then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\r
+ local node = worldedit.normalize_nodename(nodename)\r
+ if not node then\r
+ worldedit.player_notify(name, "invalid node name: " .. nodename)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.dome(pos, tonumber(radius), nodename, tenv)\r
+ local count = worldedit.dome(pos, tonumber(radius), node)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
return\r
end\r
\r
- local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")\r
+ local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ length, radius = tonumber(length), tonumber(radius)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
length = length * sign\r
end\r
- if not worldedit.node_is_valid(nodename) then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\r
+ local node = worldedit.normalize_nodename(nodename)\r
+ if not node then\r
+ worldedit.player_notify(name, "invalid node name: " .. nodename)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), nodename, tenv)\r
+ local count = worldedit.hollow_cylinder(pos, axis, length, radius, node)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
return\r
end\r
\r
- local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")\r
+ local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ length, radius = tonumber(length), tonumber(radius)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
length = length * sign\r
end\r
- if not worldedit.node_is_valid(nodename) then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\r
+ local node = worldedit.normalize_nodename(nodename)\r
+ if not node then\r
+ worldedit.player_notify(name, "invalid node name: " .. nodename)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), nodename, tenv)\r
+ local count = worldedit.cylinder(pos, axis, length, radius, node)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
\r
minetest.register_chatcommand("/pyramid", {\r
- params = "<height> <node>",\r
- description = "Add pyramid at WorldEdit position 1 with height <height>, composed of <node>",\r
+ params = "x/y/z/? <height> <node>",\r
+ description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos = worldedit.pos1[name]\r
return\r
end\r
\r
- local found, _, size, nodename = param:find("(%d+)%s+([^%s]+)$")\r
+ local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
- if not worldedit.node_is_valid(nodename) then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\r
+ height = tonumber(height)\r
+ if axis == "?" then\r
+ axis, sign = worldedit.player_axis(name)\r
+ height = height * sign\r
+ end\r
+ local node = worldedit.normalize_nodename(nodename)\r
+ if not node then\r
+ worldedit.player_notify(name, "invalid node name: " .. nodename)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.pyramid(pos, tonumber(size), nodename, tenv)\r
+ local count = worldedit.pyramid(pos, axis, height, node)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
\r
minetest.register_chatcommand("/spiral", {\r
- params = "<width> <height> <space> <node>",\r
- description = "Add spiral at WorldEdit position 1 with width <width>, height <height>, space between walls <space>, composed of <node>",\r
+ params = "<length> <height> <space> <node>",\r
+ description = "Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <space>, composed of <node>",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos = worldedit.pos1[name]\r
return\r
end\r
\r
- local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+([^%s]+)$")\r
+ local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
- if not worldedit.node_is_valid(nodename) then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\r
+ local node = worldedit.normalize_nodename(nodename)\r
+ if not node then\r
+ worldedit.player_notify(name, "invalid node name: " .. nodename)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), nodename, tenv)\r
+ local count = worldedit.spiral(pos, tonumber(length), tonumber(height), tonumber(space), node)\r
worldedit.player_notify(name, count .. " nodes added")\r
end,\r
})\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ amount = tonumber(amount)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
amount = amount * sign\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)\r
+ local count = worldedit.copy(pos1, pos2, axis, amount)\r
worldedit.player_notify(name, count .. " nodes copied")\r
end,\r
})\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ amount = tonumber(amount)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
amount = amount * sign\r
end\r
\r
- --Do NOT use the queue here, it'll mess it up\r
- local count = worldedit.move(pos1, pos2, axis, tonumber(amount))\r
+ local count = worldedit.move(pos1, pos2, axis, amount)\r
\r
pos1[axis] = pos1[axis] + amount\r
pos2[axis] = pos2[axis] + amount\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
return\r
end\r
+ count = tonumber(count)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
count = count * sign\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.stack(pos1, pos2, axis, tonumber(count), tenv)\r
+ local count = worldedit.stack(pos1, pos2, axis, count)\r
worldedit.player_notify(name, count .. " nodes stacked")\r
end,\r
})\r
\r
+minetest.register_chatcommand("/scale", {\r
+ params = "<factor>",\r
+ description = "Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+ if pos1 == nil or pos2 == nil then\r
+ worldedit.player_notify(name, "no region selected")\r
+ return\r
+ end\r
+\r
+ local factor = tonumber(param)\r
+ if not factor or factor ~= math.floor(factor) or factor <= 0 then\r
+ worldedit.player_notify(name, "invalid scaling factor: " .. param)\r
+ end\r
+\r
+ local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor)\r
+\r
+ --reset markers to scaled positions\r
+ worldedit.pos1[name] = pos1\r
+ worldedit.pos2[name] = pos2\r
+ worldedit.mark_pos1(name)\r
+ worldedit.mark_pos2(name)\r
+\r
+ worldedit.player_notify(name, count .. " nodes scaled")\r
+ end,\r
+})\r
+\r
minetest.register_chatcommand("/transpose", {\r
params = "x/y/z/? x/y/z/?",\r
description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, tenv)\r
+ local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)\r
\r
--reset markers to transposed positions\r
worldedit.pos1[name] = pos1\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.flip(pos1, pos2, param, tenv)\r
+ local count = worldedit.flip(pos1, pos2, param)\r
worldedit.player_notify(name, count .. " nodes flipped")\r
end,\r
})\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle, tenv)\r
+ local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)\r
\r
--reset markers to rotated positions\r
worldedit.pos1[name] = pos1\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.orient(pos1, pos2, angle, tenv)\r
+ local count = worldedit.orient(pos1, pos2, angle)\r
\r
worldedit.player_notify(name, count .. " nodes oriented")\r
end,\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.fixlight(pos1, pos2, tenv)\r
+ local count = worldedit.fixlight(pos1, pos2)\r
worldedit.player_notify(name, count .. " nodes updated")\r
end,\r
})\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.hide(pos1, pos2, tenv)\r
+ local count = worldedit.hide(pos1, pos2)\r
worldedit.player_notify(name, count .. " nodes hidden")\r
end,\r
})\r
return\r
end\r
\r
- if param == "" or not worldedit.node_is_valid(param) then\r
+ local node = worldedit.normalize_nodename(param)\r
+ if param == "" or not node then\r
worldedit.player_notify(name, "invalid node name: " .. param)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.suppress(pos1, pos2, param, tenv)\r
+ local count = worldedit.suppress(pos1, pos2, node)\r
worldedit.player_notify(name, count .. " nodes suppressed")\r
end,\r
})\r
return\r
end\r
\r
- if param == "" or not worldedit.node_is_valid(param) then\r
+ local node = worldedit.normalize_nodename(param)\r
+ if param == "" or not node then\r
worldedit.player_notify(name, "invalid node name: " .. param)\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.highlight(pos1, pos2, param, tenv)\r
+ local count = worldedit.highlight(pos1, pos2, node)\r
worldedit.player_notify(name, count .. " nodes highlighted")\r
end,\r
})\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.restore(pos1, pos2, tenv)\r
+ local count = worldedit.restore(pos1, pos2)\r
worldedit.player_notify(name, count .. " nodes restored")\r
end,\r
})\r
return\r
end\r
\r
- local tenv = minetest.env\r
- if worldedit.ENABLE_QUEUE then\r
- tenv = worldedit.quene_aliasenv\r
- end\r
- local count = worldedit.deserialize(pos1, value, tenv)\r
+ local count = worldedit.deserialize(pos1, value)\r
\r
worldedit.player_notify(name, count .. " nodes loaded")\r
end,\r
end\r
end,\r
})\r
+\r
+if minetest.place_schematic then\r
+minetest.register_chatcommand("/mtschemcreate", {\r
+ params = "<file>",\r
+ description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/<filename>.mts\"",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+ if pos1 == nil or pos2 == nil then\r
+ worldedit.player_notify(name, "No region selected")\r
+ return\r
+ end\r
+ if param == nil then\r
+ worldedit.player_notify(name, "No filename specified")\r
+ return\r
+ end\r
+\r
+ local path = minetest.get_worldpath() .. "/schems"\r
+ local filename = path .. "/" .. param .. ".mts"\r
+ os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist\r
+\r
+ local ret = minetest.create_schematic(pos1, pos2, worldedit.prob_list[name], filename)\r
+ if ret == nil then\r
+ worldedit.player_notify(name, "Failed to create Minetest schematic", false)\r
+ else\r
+ worldedit.player_notify(name, "Saved Minetest schematic to " .. param, false)\r
+ end\r
+ worldedit.prob_list[name] = {}\r
+ end,\r
+})\r
+\r
+minetest.register_chatcommand("/mtschemplace", {\r
+ params = "<file>",\r
+ description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ local pos = worldedit.pos1[name]\r
+ if pos == nil then\r
+ worldedit.player_notify(name, "No position selected")\r
+ return\r
+ end\r
+ if param == nil then\r
+ worldedit.player_notify(name, "No filename specified")\r
+ return\r
+ end\r
+\r
+ local path = minetest.get_worldpath() .. "/schems/" .. param .. ".mts"\r
+ if minetest.place_schematic(pos, path) == nil then\r
+ worldedit.player_notify(name, "Failed to place Minetest schematic", false)\r
+ else\r
+ worldedit.player_notify(name, "Placed Minetest schematic " .. param ..\r
+ " at " .. minetest.pos_to_string(pos), false)\r
+ end\r
+ end,\r
+})\r
+\r
+minetest.register_chatcommand("/mtschemprob", {\r
+ params = "start/finish/get",\r
+ description = "Begins node probability entry for Minetest schematics, gets the nodes that have probabilities set, or ends node probability entry",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ if param == "start" then --start probability setting\r
+ worldedit.set_pos[name] = "prob"\r
+ worldedit.prob_list[name] = {}\r
+ worldedit.player_notify(name, "select Minetest schematic probability values by punching nodes")\r
+ elseif param == "finish" then --finish probability setting\r
+ worldedit.set_pos[name] = nil\r
+ worldedit.player_notify(name, "finished Minetest schematic probability selection")\r
+ elseif param == "get" then --get all nodes that had probabilities set on them\r
+ local text = ""\r
+ local problist = worldedit.prob_list[name]\r
+ if problist == nil then\r
+ return\r
+ end\r
+ for k,v in pairs(problist) do\r
+ local prob = math.floor(((v["prob"] / 256) * 100) * 100 + 0.5) / 100\r
+ text = text .. minetest.pos_to_string(v["pos"]) .. ": " .. prob .. "% | "\r
+ end\r
+ worldedit.player_notify(name, "Currently set node probabilities:")\r
+ worldedit.player_notify(name, text)\r
+ else\r
+ worldedit.player_notify(name, "unknown subcommand: " .. param)\r
+ end\r
+ end,\r
+})\r
+\r
+minetest.register_on_player_receive_fields(\r
+ function(player, formname, fields)\r
+ if (formname == "prob_val_enter") and (fields.text ~= "") then\r
+ local name = player:get_player_name()\r
+ local prob_entry = {pos=worldedit.prob_pos[name], prob=tonumber(fields.text)}\r
+ local index = table.getn(worldedit.prob_list[name]) + 1\r
+ worldedit.prob_list[name][index] = prob_entry\r
+ end\r
+ end\r
+)\r
+end\r
+\r
+minetest.register_chatcommand("/clearobjects", {\r
+ params = "",\r
+ description = "Clears all objects within the WorldEdit region",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+ if pos1 == nil or pos2 == nil then\r
+ worldedit.player_notify(name, "no region selected")\r
+ return\r
+ end\r
+\r
+ local count = worldedit.clearobjects(pos1, pos2)\r
+ worldedit.player_notify(name, count .. " objects cleared")\r
+ end,\r
+})\r