2012-10-14 03:45:50 +02:00
|
|
|
minetest.register_privilege("worldedit", "Can use WorldEdit commands")
|
|
|
|
|
|
|
|
worldedit.set_pos = {}
|
|
|
|
|
|
|
|
worldedit.pos1 = {}
|
|
|
|
worldedit.pos2 = {}
|
|
|
|
|
|
|
|
dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")
|
|
|
|
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify = function(name, message)
|
|
|
|
minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)
|
|
|
|
end
|
|
|
|
|
2012-10-14 03:45:50 +02:00
|
|
|
--determines whether `nodename` is a valid node name, returning a boolean
|
2013-06-13 01:59:13 +02:00
|
|
|
worldedit.normalize_nodename = function(nodename)
|
|
|
|
if minetest.registered_nodes[nodename] then --directly found node name
|
|
|
|
return nodename
|
|
|
|
elseif minetest.registered_nodes["default:" .. nodename] then --found node name in default
|
|
|
|
return "default:" .. nodename
|
|
|
|
end
|
|
|
|
for key, value in pairs(minetest.registered_nodes) do
|
|
|
|
if key:find(":" .. nodename, 1, true) then --found in mod
|
|
|
|
return key
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for key, value in pairs(minetest.registered_nodes) do
|
|
|
|
if value.description:lower() == nodename:lower() then --found in description
|
|
|
|
return key
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
2012-10-14 03:45:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
|
|
|
|
worldedit.player_axis = function(name)
|
|
|
|
local dir = minetest.env:get_player_by_name(name):get_look_dir()
|
|
|
|
local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
|
|
|
|
if x > y then
|
|
|
|
if x > z then
|
|
|
|
return "x", dir.x > 0 and 1 or -1
|
|
|
|
end
|
|
|
|
elseif y > z then
|
|
|
|
return "y", dir.y > 0 and 1 or -1
|
|
|
|
end
|
|
|
|
return "z", dir.z > 0 and 1 or -1
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/reset", {
|
|
|
|
params = "",
|
|
|
|
description = "Reset the region so that it is empty",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
worldedit.pos1[name] = nil
|
|
|
|
worldedit.pos2[name] = nil
|
|
|
|
worldedit.mark_pos1(name)
|
|
|
|
worldedit.mark_pos2(name)
|
2013-05-15 23:03:26 +02:00
|
|
|
worldedit.set_pos[name] = nil
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "region reset")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/mark", {
|
|
|
|
params = "",
|
|
|
|
description = "Show markers at the region positions",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
worldedit.mark_pos1(name)
|
|
|
|
worldedit.mark_pos2(name)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "region marked")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2013-05-15 23:03:26 +02:00
|
|
|
minetest.register_chatcommand("/unmark", {
|
|
|
|
params = "",
|
|
|
|
description = "Hide markers if currently shown",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
worldedit.pos1[name] = nil
|
|
|
|
worldedit.pos2[name] = nil
|
|
|
|
worldedit.mark_pos1(name)
|
|
|
|
worldedit.mark_pos2(name)
|
|
|
|
worldedit.pos1[name] = pos1
|
|
|
|
worldedit.pos2[name] = pos2
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "region unmarked")
|
2013-05-15 23:03:26 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2012-10-14 03:45:50 +02:00
|
|
|
minetest.register_chatcommand("/pos1", {
|
|
|
|
params = "",
|
|
|
|
description = "Set WorldEdit region position 1 to the player's location",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos = minetest.env:get_player_by_name(name):getpos()
|
2013-02-17 03:14:44 +01:00
|
|
|
pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)
|
2012-10-14 03:45:50 +02:00
|
|
|
worldedit.pos1[name] = pos
|
|
|
|
worldedit.mark_pos1(name)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/pos2", {
|
|
|
|
params = "",
|
|
|
|
description = "Set WorldEdit region position 2 to the player's location",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos = minetest.env:get_player_by_name(name):getpos()
|
2013-02-17 03:14:44 +01:00
|
|
|
pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)
|
2012-10-14 03:45:50 +02:00
|
|
|
worldedit.pos2[name] = pos
|
|
|
|
worldedit.mark_pos2(name)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/p", {
|
2012-10-19 03:28:58 +02:00
|
|
|
params = "set/set1/set2/get",
|
|
|
|
description = "Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region",
|
2012-10-14 03:45:50 +02:00
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
if param == "set" then --set both WorldEdit positions
|
2012-10-19 03:28:58 +02:00
|
|
|
worldedit.set_pos[name] = "pos1"
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "select positions by punching two nodes")
|
2012-10-19 03:28:58 +02:00
|
|
|
elseif param == "set1" then --set WorldEdit position 1
|
|
|
|
worldedit.set_pos[name] = "pos1only"
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "select position 1 by punching a node")
|
2012-10-19 03:28:58 +02:00
|
|
|
elseif param == "set2" then --set WorldEdit position 2
|
|
|
|
worldedit.set_pos[name] = "pos2"
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "select position 2 by punching a node")
|
2012-10-14 03:45:50 +02:00
|
|
|
elseif param == "get" then --display current WorldEdit positions
|
|
|
|
if worldedit.pos1[name] ~= nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "position 1: " .. minetest.pos_to_string(worldedit.pos1[name]))
|
2012-10-14 03:45:50 +02:00
|
|
|
else
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "position 1 not set")
|
2012-10-14 03:45:50 +02:00
|
|
|
end
|
|
|
|
if worldedit.pos2[name] ~= nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "position 2: " .. minetest.pos_to_string(worldedit.pos2[name]))
|
2012-10-14 03:45:50 +02:00
|
|
|
else
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "position 2 not set")
|
2012-10-14 03:45:50 +02:00
|
|
|
end
|
|
|
|
else
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "unknown subcommand: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_on_punchnode(function(pos, node, puncher)
|
|
|
|
local name = puncher:get_player_name()
|
|
|
|
if name ~= "" and worldedit.set_pos[name] ~= nil then --currently setting position
|
2012-10-19 03:28:58 +02:00
|
|
|
if worldedit.set_pos[name] == "pos1" then --setting position 1
|
2012-10-14 03:45:50 +02:00
|
|
|
worldedit.pos1[name] = pos
|
|
|
|
worldedit.mark_pos1(name)
|
2012-10-19 03:28:58 +02:00
|
|
|
worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
|
2012-10-19 03:28:58 +02:00
|
|
|
elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only
|
|
|
|
worldedit.pos1[name] = pos
|
|
|
|
worldedit.mark_pos1(name)
|
2012-10-14 03:45:50 +02:00
|
|
|
worldedit.set_pos[name] = nil --finished setting positions
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))
|
2012-10-19 03:28:58 +02:00
|
|
|
elseif worldedit.set_pos[name] == "pos2" then --setting position 2
|
2012-10-14 03:45:50 +02:00
|
|
|
worldedit.pos2[name] = pos
|
|
|
|
worldedit.mark_pos2(name)
|
2012-10-19 03:28:58 +02:00
|
|
|
worldedit.set_pos[name] = nil --finished setting positions
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))
|
2012-10-14 03:45:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/volume", {
|
|
|
|
params = "",
|
|
|
|
description = "Display the volume of the current WorldEdit region",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local volume = worldedit.volume(pos1, pos2)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "current region has a volume of " .. volume .. " nodes (" .. pos2.x - pos1.x .. "*" .. pos2.y - pos1.y .. "*" .. pos2.z - pos1.z .. ")")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/set", {
|
|
|
|
params = "<node>",
|
|
|
|
description = "Set the current WorldEdit region to <node>",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.normalize_nodename(param)
|
|
|
|
if param == "" or not node then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid node name: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-05-15 23:52:12 +02:00
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.set(pos1, pos2, node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes set")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/replace", {
|
|
|
|
params = "<search node> <replace node>",
|
2013-01-13 00:20:41 +01:00
|
|
|
description = "Replace all instances of <search node> with <replace node> in the current WorldEdit region",
|
2012-10-14 03:45:50 +02:00
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
|
2012-10-14 03:45:50 +02:00
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local newsearchnode = worldedit.normalize_nodename(searchnode)
|
|
|
|
if not newsearchnode then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid search node name: " .. searchnode)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local newreplacenode = worldedit.normalize_nodename(replacenode)
|
|
|
|
if not newreplacenode then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes replaced")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2013-01-13 00:29:57 +01:00
|
|
|
minetest.register_chatcommand("/replaceinverse", {
|
|
|
|
params = "<search node> <replace node>",
|
|
|
|
description = "Replace all nodes other than <search node> with <replace node> in the current WorldEdit region",
|
2013-01-13 00:20:41 +01:00
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2013-01-13 00:20:41 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
|
2013-01-13 00:29:57 +01:00
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2013-01-13 00:29:57 +01:00
|
|
|
return
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local newsearchnode = worldedit.normalize_nodename(searchnode)
|
|
|
|
if not newsearchnode then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid search node name: " .. searchnode)
|
2013-01-13 00:29:57 +01:00
|
|
|
return
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local newreplacenode = worldedit.normalize_nodename(replacenode)
|
|
|
|
if not newreplacenode then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid replace node name: " .. replacenode)
|
2013-01-13 00:20:41 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
|
|
|
local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes replaced")
|
2013-01-13 00:20:41 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2012-10-14 03:45:50 +02:00
|
|
|
minetest.register_chatcommand("/hollowsphere", {
|
|
|
|
params = "<radius> <node>",
|
|
|
|
description = "Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos = worldedit.pos1[name]
|
|
|
|
if pos == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
|
2012-10-14 03:45:50 +02:00
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.normalize_nodename(nodename)
|
|
|
|
if not node then
|
|
|
|
worldedit.player_notify(name, "invalid node name: " .. nodename)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.hollow_sphere(pos, tonumber(radius), node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes added")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/sphere", {
|
|
|
|
params = "<radius> <node>",
|
|
|
|
description = "Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos = worldedit.pos1[name]
|
|
|
|
if pos == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
|
2012-10-14 03:45:50 +02:00
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.normalize_nodename(nodename)
|
|
|
|
if not node then
|
|
|
|
worldedit.player_notify(name, "invalid node name: " .. nodename)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.sphere(pos, tonumber(radius), node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes added")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2013-04-28 00:28:20 +02:00
|
|
|
minetest.register_chatcommand("/hollowdome", {
|
|
|
|
params = "<radius> <node>",
|
|
|
|
description = "Add hollow dome at WorldEdit position 1 with radius <radius>, composed of <node>",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos = worldedit.pos1[name]
|
|
|
|
if pos == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2013-04-28 00:28:20 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
|
2013-04-28 00:28:20 +02:00
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2013-04-28 00:28:20 +02:00
|
|
|
return
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.normalize_nodename(nodename)
|
|
|
|
if not node then
|
|
|
|
worldedit.player_notify(name, "invalid node name: " .. nodename)
|
2013-04-28 00:28:20 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.hollow_dome(pos, tonumber(radius), node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes added")
|
2013-04-28 00:28:20 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/dome", {
|
|
|
|
params = "<radius> <node>",
|
|
|
|
description = "Add dome at WorldEdit position 1 with radius <radius>, composed of <node>",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos = worldedit.pos1[name]
|
|
|
|
if pos == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2013-04-28 00:28:20 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
|
2013-04-28 00:28:20 +02:00
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2013-04-28 00:28:20 +02:00
|
|
|
return
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.normalize_nodename(nodename)
|
|
|
|
if not node then
|
|
|
|
worldedit.player_notify(name, "invalid node name: " .. nodename)
|
2013-04-28 00:28:20 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.dome(pos, tonumber(radius), node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes added")
|
2013-04-28 00:28:20 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2012-10-14 03:45:50 +02:00
|
|
|
minetest.register_chatcommand("/hollowcylinder", {
|
|
|
|
params = "x/y/z/? <length> <radius> <node>",
|
|
|
|
description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos = worldedit.pos1[name]
|
|
|
|
if pos == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
|
2012-10-14 03:45:50 +02:00
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if axis == "?" then
|
|
|
|
axis, sign = worldedit.player_axis(name)
|
|
|
|
length = length * sign
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.normalize_nodename(nodename)
|
|
|
|
if not node then
|
|
|
|
worldedit.player_notify(name, "invalid node name: " .. nodename)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes added")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/cylinder", {
|
|
|
|
params = "x/y/z/? <length> <radius> <node>",
|
|
|
|
description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos = worldedit.pos1[name]
|
|
|
|
if pos == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
|
2012-10-14 03:45:50 +02:00
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if axis == "?" then
|
|
|
|
axis, sign = worldedit.player_axis(name)
|
|
|
|
length = length * sign
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.normalize_nodename(nodename)
|
|
|
|
if not node then
|
|
|
|
worldedit.player_notify(name, "invalid node name: " .. nodename)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes added")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/pyramid", {
|
|
|
|
params = "<height> <node>",
|
|
|
|
description = "Add pyramid at WorldEdit position 1 with height <height>, composed of <node>",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos = worldedit.pos1[name]
|
|
|
|
if pos == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local found, _, size, nodename = param:find("(%d+)%s+(.+)$")
|
2012-10-14 03:45:50 +02:00
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.normalize_nodename(nodename)
|
|
|
|
if not node then
|
|
|
|
worldedit.player_notify(name, "invalid node name: " .. nodename)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.pyramid(pos, tonumber(size), node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes added")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/spiral", {
|
|
|
|
params = "<width> <height> <space> <node>",
|
|
|
|
description = "Add spiral at WorldEdit position 1 with width <width>, height <height>, space between walls <space>, composed of <node>",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos = worldedit.pos1[name]
|
|
|
|
if pos == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
|
2012-10-14 03:45:50 +02:00
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.normalize_nodename(nodename)
|
|
|
|
if not node then
|
|
|
|
worldedit.player_notify(name, "invalid node name: " .. nodename)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes added")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/copy", {
|
|
|
|
params = "x/y/z/? <amount>",
|
|
|
|
description = "Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
|
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if axis == "?" then
|
|
|
|
axis, sign = worldedit.player_axis(name)
|
|
|
|
amount = amount * sign
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
|
|
|
local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes copied")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/move", {
|
|
|
|
params = "x/y/z/? <amount>",
|
|
|
|
description = "Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
|
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if axis == "?" then
|
|
|
|
axis, sign = worldedit.player_axis(name)
|
|
|
|
amount = amount * sign
|
|
|
|
end
|
|
|
|
|
2013-05-31 02:38:56 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
|
|
|
tenv = worldedit.queue_aliasenv
|
|
|
|
end
|
|
|
|
local count = worldedit.move(pos1, pos2, axis, tonumber(amount), tenv)
|
2012-10-14 03:45:50 +02:00
|
|
|
|
|
|
|
pos1[axis] = pos1[axis] + amount
|
|
|
|
pos2[axis] = pos2[axis] + amount
|
|
|
|
worldedit.mark_pos1(name)
|
|
|
|
worldedit.mark_pos2(name)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes moved")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/stack", {
|
|
|
|
params = "x/y/z/? <count>",
|
|
|
|
description = "Stack the current WorldEdit region along the x/y/z/? axis <count> times",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local found, _, axis, count = param:find("^([xyz%?])%s+([+-]?%d+)$")
|
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if axis == "?" then
|
|
|
|
axis, sign = worldedit.player_axis(name)
|
|
|
|
count = count * sign
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
|
|
|
local count = worldedit.stack(pos1, pos2, axis, tonumber(count), tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes stacked")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/transpose", {
|
|
|
|
params = "x/y/z/? x/y/z/?",
|
|
|
|
description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")
|
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if axis1 == "?" then
|
|
|
|
axis1 = worldedit.player_axis(name)
|
|
|
|
end
|
|
|
|
if axis2 == "?" then
|
|
|
|
axis2 = worldedit.player_axis(name)
|
|
|
|
end
|
|
|
|
if axis1 == axis2 then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: axes must be different")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
|
|
|
local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, tenv)
|
2012-12-12 23:17:56 +01:00
|
|
|
|
|
|
|
--reset markers to transposed positions
|
|
|
|
worldedit.pos1[name] = pos1
|
|
|
|
worldedit.pos2[name] = pos2
|
|
|
|
worldedit.mark_pos1(name)
|
|
|
|
worldedit.mark_pos2(name)
|
|
|
|
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes transposed")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/flip", {
|
|
|
|
params = "x/y/z/?",
|
|
|
|
description = "Flip the current WorldEdit region along the x/y/z/? axis",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if param == "?" then
|
|
|
|
param = worldedit.player_axis(name)
|
|
|
|
end
|
|
|
|
if param ~= "x" and param ~= "y" and param ~= "z" then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
|
|
|
local count = worldedit.flip(pos1, pos2, param, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes flipped")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/rotate", {
|
|
|
|
params = "<axis> <angle>",
|
|
|
|
description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")
|
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if axis == "?" then
|
|
|
|
axis = worldedit.player_axis(name)
|
|
|
|
end
|
|
|
|
if angle % 90 ~= 0 then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-02 23:50:14 +02:00
|
|
|
local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)
|
2012-12-12 23:17:56 +01:00
|
|
|
|
|
|
|
--reset markers to rotated positions
|
|
|
|
worldedit.pos1[name] = pos1
|
|
|
|
worldedit.pos2[name] = pos2
|
|
|
|
worldedit.mark_pos1(name)
|
|
|
|
worldedit.mark_pos2(name)
|
|
|
|
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes rotated")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2013-01-12 22:46:40 +01:00
|
|
|
minetest.register_chatcommand("/orient", {
|
|
|
|
params = "<angle>",
|
|
|
|
description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2013-01-12 22:46:40 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local found, _, angle = param:find("^([+-]?%d+)$")
|
|
|
|
if found == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2013-01-12 22:46:40 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if angle % 90 ~= 0 then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")
|
2013-01-12 22:46:40 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
|
|
|
local count = worldedit.orient(pos1, pos2, angle, tenv)
|
2013-01-12 22:46:40 +01:00
|
|
|
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes oriented")
|
2013-01-12 22:46:40 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2013-01-12 08:10:19 +01:00
|
|
|
minetest.register_chatcommand("/fixlight", {
|
2012-10-14 03:45:50 +02:00
|
|
|
params = "",
|
2013-01-12 22:02:23 +01:00
|
|
|
description = "Fix the lighting in the current WorldEdit region",
|
2012-10-14 03:45:50 +02:00
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
|
|
|
local count = worldedit.fixlight(pos1, pos2, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes updated")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/hide", {
|
2012-12-12 23:17:56 +01:00
|
|
|
params = "",
|
|
|
|
description = "Hide all nodes in the current WorldEdit region non-destructively",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-12-12 23:17:56 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
|
|
|
local count = worldedit.hide(pos1, pos2, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes hidden")
|
2012-12-12 23:17:56 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/suppress", {
|
2012-10-14 03:45:50 +02:00
|
|
|
params = "<node>",
|
2012-12-12 23:17:56 +01:00
|
|
|
description = "Suppress all <node> in the current WorldEdit region non-destructively",
|
2012-10-14 03:45:50 +02:00
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.node_is_valid(param)
|
|
|
|
if param == "" or not node then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid node name: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.suppress(pos1, pos2, node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes suppressed")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2012-10-21 23:49:43 +02:00
|
|
|
minetest.register_chatcommand("/highlight", {
|
2012-10-14 03:45:50 +02:00
|
|
|
params = "<node>",
|
2012-10-21 23:49:43 +02:00
|
|
|
description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",
|
2012-10-14 03:45:50 +02:00
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-06-13 01:59:13 +02:00
|
|
|
local node = worldedit.node_is_valid(param)
|
|
|
|
if param == "" or not node then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid node name: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2013-06-13 01:59:13 +02:00
|
|
|
local count = worldedit.highlight(pos1, pos2, node, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes highlighted")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/restore", {
|
|
|
|
params = "",
|
|
|
|
description = "Restores nodes hidden with WorldEdit in the current WorldEdit region",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-04-28 19:08:09 +02:00
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
|
|
|
local count = worldedit.restore(pos1, pos2, tenv)
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes restored")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/save", {
|
|
|
|
params = "<file>",
|
|
|
|
description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if param == "" then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local result, count = worldedit.serialize(pos1, pos2)
|
|
|
|
|
|
|
|
local path = minetest.get_worldpath() .. "/schems"
|
|
|
|
local filename = path .. "/" .. param .. ".we"
|
|
|
|
os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
|
|
|
|
local file, err = io.open(filename, "wb")
|
|
|
|
if err ~= nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "could not save file to \"" .. filename .. "\"")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
file:write(result)
|
|
|
|
file:flush()
|
|
|
|
file:close()
|
|
|
|
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes saved")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2012-10-21 23:49:43 +02:00
|
|
|
minetest.register_chatcommand("/allocate", {
|
|
|
|
params = "<file>",
|
|
|
|
description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1 = worldedit.pos1[name]
|
|
|
|
if pos1 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-21 23:49:43 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if param == "" then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-21 23:49:43 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"
|
|
|
|
local file, err = io.open(filename, "rb")
|
|
|
|
if err ~= nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "could not open file \"" .. filename .. "\"")
|
2012-10-21 23:49:43 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local value = file:read("*a")
|
|
|
|
file:close()
|
|
|
|
|
2013-03-20 22:12:48 +01:00
|
|
|
if worldedit.valueversion(value) == 0 then --unknown version
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
|
2013-03-20 22:12:48 +01:00
|
|
|
return
|
2012-10-23 05:17:37 +02:00
|
|
|
end
|
2013-03-20 22:12:48 +01:00
|
|
|
local nodepos1, nodepos2, count = worldedit.allocate(pos1, value)
|
2012-10-21 23:49:43 +02:00
|
|
|
|
|
|
|
worldedit.pos1[name] = nodepos1
|
|
|
|
worldedit.mark_pos1(name)
|
|
|
|
worldedit.pos2[name] = nodepos2
|
|
|
|
worldedit.mark_pos2(name)
|
|
|
|
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes allocated")
|
2012-10-21 23:49:43 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2012-10-14 03:45:50 +02:00
|
|
|
minetest.register_chatcommand("/load", {
|
|
|
|
params = "<file>",
|
2013-03-20 22:12:48 +01:00
|
|
|
description = "Load nodes from \"(world folder)/schems/<file>[.we[m]]\" with position 1 of the current WorldEdit region as the origin",
|
2012-10-14 03:45:50 +02:00
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1 = worldedit.pos1[name]
|
|
|
|
if pos1 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if param == "" then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-03-20 22:12:48 +01:00
|
|
|
--find the file in the world path
|
|
|
|
local testpaths = {
|
|
|
|
minetest.get_worldpath() .. "/schems/" .. param,
|
|
|
|
minetest.get_worldpath() .. "/schems/" .. param .. ".we",
|
|
|
|
minetest.get_worldpath() .. "/schems/" .. param .. ".wem",
|
|
|
|
}
|
|
|
|
local file, err
|
|
|
|
for index, path in ipairs(testpaths) do
|
|
|
|
file, err = io.open(path, "rb")
|
|
|
|
if not err then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if err then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "could not open file \"" .. param .. "\"")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local value = file:read("*a")
|
|
|
|
file:close()
|
|
|
|
|
2013-03-20 22:12:48 +01:00
|
|
|
if worldedit.valueversion(value) == 0 then --unknown version
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
|
2012-10-14 03:45:50 +02:00
|
|
|
return
|
|
|
|
end
|
2013-04-28 19:08:09 +02:00
|
|
|
|
|
|
|
local tenv = minetest.env
|
|
|
|
if worldedit.ENABLE_QUEUE then
|
2013-05-31 02:38:56 +02:00
|
|
|
tenv = worldedit.queue_aliasenv
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
|
|
|
local count = worldedit.deserialize(pos1, value, tenv)
|
2012-10-14 03:45:50 +02:00
|
|
|
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, count .. " nodes loaded")
|
2012-10-14 03:45:50 +02:00
|
|
|
end,
|
|
|
|
})
|
2013-01-13 00:20:41 +01:00
|
|
|
|
|
|
|
minetest.register_chatcommand("/lua", {
|
|
|
|
params = "<code>",
|
|
|
|
description = "Executes <code> as a Lua chunk in the global namespace",
|
2013-01-14 22:14:54 +01:00
|
|
|
privs = {worldedit=true, server=true},
|
2013-01-13 00:20:41 +01:00
|
|
|
func = function(name, param)
|
|
|
|
local err = worldedit.lua(param)
|
|
|
|
if err then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "code error: " .. err)
|
2013-01-13 00:20:41 +01:00
|
|
|
else
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "code successfully executed", false)
|
2013-01-13 00:20:41 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("/luatransform", {
|
|
|
|
params = "<code>",
|
|
|
|
description = "Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region",
|
2013-01-14 22:14:54 +01:00
|
|
|
privs = {worldedit=true, server=true},
|
2013-01-13 00:20:41 +01:00
|
|
|
func = function(name, param)
|
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
|
|
if pos1 == nil or pos2 == nil then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "no region selected")
|
2013-01-13 00:20:41 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local err = worldedit.luatransform(pos1, pos2, param)
|
|
|
|
if err then
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "code error: " .. err, false)
|
2013-01-13 00:20:41 +01:00
|
|
|
else
|
2013-05-15 23:52:12 +02:00
|
|
|
worldedit.player_notify(name, "code successfully executed", false)
|
2013-01-13 00:20:41 +01:00
|
|
|
end
|
|
|
|
end,
|
2013-04-28 19:08:09 +02:00
|
|
|
})
|