Rename the randomized //set to //mix, style update, document changes.

This commit is contained in:
Uberi 2014-07-18 15:51:09 -04:00
parent d8aa7e72a7
commit 4b178bf709
2 changed files with 81 additions and 79 deletions

View File

@ -98,14 +98,23 @@ Display the volume of the current WorldEdit region.
//volume
### `//set <node1> ...`
### `//set <node>`
Set the current WorldEdit region to a random mix of `<node1>`, `...`.
Set the current WorldEdit region to `<node>`.
//set air
//set cactus stone glass
//set Bronze
//set mesecons:wire_00000000_off
//set cactus
//set Blue Lightstone
//set dirt with grass
### `//mix <node1> ...`
Fill the current WorldEdit region with a random mix of `<node1>`, `...`.
//mix air
//mix cactus stone glass sandstone
//mix Bronze
//mix default:cobble air
### `//replace <search node> <replace node>`

View File

@ -15,7 +15,7 @@ end
dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")
dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")
local get_position = function(name)
local get_position = function(name) --position 1 retrieval function for when not using `safe_region`
local pos1 = worldedit.pos1[name]
if pos1 == nil then
worldedit.player_notify(name, "no position 1 selected")
@ -279,19 +279,35 @@ minetest.register_chatcommand("/volume", {
})
minetest.register_chatcommand("/set", {
params = "<node1> ...",
description = "Set the current WorldEdit region to a random mix of <node1>, ...",
params = "<node>",
description = "Set the current WorldEdit region to <node>",
privs = {worldedit=true},
func = safe_region(function(name, param)
local nodes = {}
for nodename in param:gmatch("[^%s]+") do
local node = get_node(name, nodename)
if not node then
worldedit.player_notify(name, "Could not identify node \"" .. name .. "\"")
return
end
nodes[#nodes + 1] = node
end
local node = get_node(name, param)
if not node then
worldedit.player_notify(name, "Could not identify node \"" .. param .. "\"")
return
end
local count = worldedit.set(worldedit.pos1[name], worldedit.pos2[name], node)
worldedit.player_notify(name, count .. " nodes set")
end, check_region),
})
minetest.register_chatcommand("/mix", {
params = "<node1> ...",
description = "Fill the current WorldEdit region with a random mix of <node1>, ...",
privs = {worldedit=true},
func = safe_region(function(name, param)
local nodes = {}
for nodename in param:gmatch("[^,]+") do
local node = get_node(name, nodename)
if not node then
worldedit.player_notify(name, "Could not identify node \"" .. name .. "\"")
return
end
nodes[#nodes + 1] = node
end
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local count = worldedit.set(pos1, pos2, nodes)
@ -323,11 +339,10 @@ minetest.register_chatcommand("/replace", {
description = "Replace all instances of <search node> with <replace node> in the current WorldEdit region",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
local newsearchnode = worldedit.normalize_nodename(searchnode)
local newreplacenode = worldedit.normalize_nodename(replacenode)
local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode)
local count = worldedit.replace(worldedit.pos1[name], worldedit.pos2[name], newsearchnode, newreplacenode)
worldedit.player_notify(name, count .. " nodes replaced")
end, check_replace),
})
@ -337,11 +352,10 @@ minetest.register_chatcommand("/replaceinverse", {
description = "Replace all nodes other than <search node> with <replace node> in the current WorldEdit region",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")
local newsearchnode = worldedit.normalize_nodename(searchnode)
local newreplacenode = worldedit.normalize_nodename(replacenode)
local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)
local count = worldedit.replaceinverse(worldedit.pos1[name], worldedit.pos2[name], searchnode, replacenode)
worldedit.player_notify(name, count .. " nodes replaced")
end, check_replace),
})
@ -366,10 +380,9 @@ minetest.register_chatcommand("/hollowsphere", {
description = "Add hollow sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos = worldedit.pos1[name]
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
local node = get_node(name, nodename)
local count = worldedit.hollow_sphere(pos, tonumber(radius), node)
local count = worldedit.hollow_sphere(worldedit.pos1[name], tonumber(radius), node)
worldedit.player_notify(name, count .. " nodes added")
end, check_sphere),
})
@ -379,10 +392,9 @@ minetest.register_chatcommand("/sphere", {
description = "Add sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos = worldedit.pos1[name]
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
local node = get_node(name, nodename)
local count = worldedit.sphere(pos, tonumber(radius), node)
local count = worldedit.sphere(worldedit.pos1[name], tonumber(radius), node)
worldedit.player_notify(name, count .. " nodes added")
end, check_sphere),
})
@ -407,10 +419,9 @@ minetest.register_chatcommand("/hollowdome", {
description = "Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos = worldedit.pos1[name]
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
local node = get_node(name, nodename)
local count = worldedit.hollow_dome(pos, tonumber(radius), node)
local count = worldedit.hollow_dome(worldedit.pos1[name], tonumber(radius), node)
worldedit.player_notify(name, count .. " nodes added")
end, check_dome),
})
@ -420,10 +431,9 @@ minetest.register_chatcommand("/dome", {
description = "Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos = worldedit.pos1[name]
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")
local node = get_node(name, nodename)
local count = worldedit.dome(pos, tonumber(radius), node)
local count = worldedit.dome(worldedit.pos1[name], tonumber(radius), node)
worldedit.player_notify(name, count .. " nodes added")
end, check_dome),
})
@ -448,7 +458,6 @@ minetest.register_chatcommand("/hollowcylinder", {
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 = safe_region(function(name, param)
local pos = worldedit.pos1[name]
local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
length = tonumber(length)
if axis == "?" then
@ -456,7 +465,7 @@ minetest.register_chatcommand("/hollowcylinder", {
length = length * sign
end
local node = get_node(name, nodename)
local count = worldedit.hollow_cylinder(pos, axis, length, tonumber(radius), node)
local count = worldedit.hollow_cylinder(worldedit.pos1[name], axis, length, tonumber(radius), node)
worldedit.player_notify(name, count .. " nodes added")
end, check_cylinder),
})
@ -466,7 +475,6 @@ minetest.register_chatcommand("/cylinder", {
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 = safe_region(function(name, param)
local pos = worldedit.pos1[name]
local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
length = tonumber(length)
if axis == "?" then
@ -474,7 +482,7 @@ minetest.register_chatcommand("/cylinder", {
length = length * sign
end
local node = get_node(name, nodename)
local count = worldedit.cylinder(pos, axis, length, tonumber(radius), node)
local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius), node)
worldedit.player_notify(name, count .. " nodes added")
end, check_cylinder),
})
@ -484,7 +492,6 @@ minetest.register_chatcommand("/pyramid", {
description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos = get_position(name)
local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
height = tonumber(height)
if axis == "?" then
@ -492,7 +499,7 @@ minetest.register_chatcommand("/pyramid", {
height = height * sign
end
local node = get_node(name, nodename)
local count = worldedit.pyramid(pos, axis, height, node)
local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node)
worldedit.player_notify(name, count .. " nodes added")
end,
function(name, param)
@ -517,10 +524,9 @@ minetest.register_chatcommand("/spiral", {
description = "Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <space>, composed of <node>",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos = worldedit.pos1[name]
local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
local node = get_node(name, nodename)
local count = worldedit.spiral(pos, tonumber(length), tonumber(height), tonumber(space), node)
local count = worldedit.spiral(worldedit.pos1[name], tonumber(length), tonumber(height), tonumber(space), node)
worldedit.player_notify(name, count .. " nodes added")
end,
function(name, param)
@ -544,7 +550,6 @@ minetest.register_chatcommand("/copy", {
description = "Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")
if found == nil then
worldedit.player_notify(name, "invalid usage: " .. param)
@ -556,7 +561,7 @@ minetest.register_chatcommand("/copy", {
amount = amount * sign
end
local count = worldedit.copy(pos1, pos2, axis, amount)
local count = worldedit.copy(worldedit.pos1[name], worldedit.pos2[name], axis, amount)
worldedit.player_notify(name, count .. " nodes copied")
end,
function(name, param)
@ -597,14 +602,13 @@ minetest.register_chatcommand("/stack", {
description = "Stack the current WorldEdit region along the x/y/z/? axis <count> times",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$")
repetitions = tonumber(repetitions)
if axis == "?" then
axis, sign = worldedit.player_axis(name)
repetitions = repetitions * sign
end
local count = worldedit.stack(pos1, pos2, axis, repetitions)
local count = worldedit.stack(worldedit.pos1[name], worldedit.pos2[name], axis, repetitions)
worldedit.player_notify(name, count .. " nodes stacked")
end,
function(name, param)
@ -624,32 +628,32 @@ minetest.register_chatcommand("/stack2", {
privs = {worldedit=true},
func = function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
if pos1 == nil or pos2 == nil then
if pos1 == nil or pos2 == nil then
worldedit.player_notify(name, "Select a position first!")
return
end
local repetitions, incs = param:match("(%d+)%s*(.+)")
if repetitions == nil then
return
end
local repetitions, incs = param:match("(%d+)%s*(.+)")
if repetitions == nil then
worldedit.player_notify(name, "invalid count: " .. param)
return
end
return
end
repetitions = tonumber(repetitions)
local x, y, z = incs:match("([+-]?%d+) ([+-]%d+) ([+-]%d+)")
if x == nil then
worldedit.player_notify(name, "invalid increments: " .. param)
return
end
x, y, z = tonumber(x), tonumber(y), tonumber(z)
local x, y, z = incs:match("([+-]?%d+) ([+-]%d+) ([+-]%d+)")
if x == nil then
worldedit.player_notify(name, "invalid increments: " .. param)
return
end
x, y, z = tonumber(x), tonumber(y), tonumber(z)
local count = worldedit.volume(pos1, pos2) * repetitions
local count = worldedit.volume(pos1, pos2) * repetitions
return safe_region(function()
return safe_region(function()
worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions,
function() worldedit.player_notify(name, count .. " nodes stacked") end)
end, function()
return count
end)(name,param) -- more hax
end)(name,param) -- more hax --wip: clean this up a little bit
end
})
@ -726,9 +730,8 @@ minetest.register_chatcommand("/flip", {
description = "Flip the current WorldEdit region along the x/y/z/? axis",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
if param == "?" then param = worldedit.player_axis(name) end
local count = worldedit.flip(pos1, pos2, param)
local count = worldedit.flip(worldedit.pos1[name], worldedit.pos2[name], param)
worldedit.player_notify(name, count .. " nodes flipped")
end,
function(name, param)
@ -777,9 +780,8 @@ minetest.register_chatcommand("/orient", {
description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local found, _, angle = param:find("^([+-]?%d+)$")
local count = worldedit.orient(pos1, pos2, angle)
local count = worldedit.orient(worldedit.pos1[name], worldedit.pos2[name], angle)
worldedit.player_notify(name, count .. " nodes oriented")
end,
function(name, param)
@ -801,8 +803,7 @@ minetest.register_chatcommand("/fixlight", {
description = "Fix the lighting in the current WorldEdit region",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local count = worldedit.fixlight(pos1, pos2)
local count = worldedit.fixlight(worldedit.pos1[name], worldedit.pos2[name])
worldedit.player_notify(name, count .. " nodes updated")
end),
})
@ -812,8 +813,7 @@ minetest.register_chatcommand("/hide", {
description = "Hide all nodes in the current WorldEdit region non-destructively",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local count = worldedit.hide(pos1, pos2)
local count = worldedit.hide(worldedit.pos1[name], worldedit.pos2[name])
worldedit.player_notify(name, count .. " nodes hidden")
end),
})
@ -823,9 +823,8 @@ minetest.register_chatcommand("/suppress", {
description = "Suppress all <node> in the current WorldEdit region non-destructively",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local node = get_node(name, param)
local count = worldedit.suppress(pos1, pos2, node)
local count = worldedit.suppress(worldedit.pos1[name], worldedit.pos2[name], node)
worldedit.player_notify(name, count .. " nodes suppressed")
end, check_set),
})
@ -835,9 +834,8 @@ minetest.register_chatcommand("/highlight", {
description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local node = get_node(name, param)
local count = worldedit.highlight(pos1, pos2, node)
local count = worldedit.highlight(worldedit.pos1[name], worldedit.pos2[name], node)
worldedit.player_notify(name, count .. " nodes highlighted")
end, check_set),
})
@ -847,8 +845,7 @@ minetest.register_chatcommand("/restore", {
description = "Restores nodes hidden with WorldEdit in the current WorldEdit region",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local count = worldedit.restore(pos1, pos2)
local count = worldedit.restore(worldedit.pos1[name], worldedit.pos2[name])
worldedit.player_notify(name, count .. " nodes restored")
end),
})
@ -858,7 +855,6 @@ minetest.register_chatcommand("/save", {
description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
if param == "" then
worldedit.player_notify(name, "invalid usage: " .. param)
return
@ -868,7 +864,7 @@ minetest.register_chatcommand("/save", {
return
end
local result, count = worldedit.serialize(pos1, pos2)
local result, count = worldedit.serialize(worldedit.pos1[name], worldedit.pos2[name])
local path = minetest.get_worldpath() .. "/schems"
local filename = path .. "/" .. param .. ".we"
@ -1000,14 +996,13 @@ minetest.register_chatcommand("/luatransform", {
description = "Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region",
privs = {worldedit=true, server=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local admin = minetest.setting_get("name")
if not admin or not name == admin then
worldedit.player_notify(name, "this command can only be run by the server administrator")
return
end
local err = worldedit.luatransform(pos1, pos2, param)
local err = worldedit.luatransform(worldedit.pos1[name], worldedit.pos2[name], param)
if err then
worldedit.player_notify(name, "code error: " .. err, false)
else
@ -1021,7 +1016,6 @@ minetest.register_chatcommand("/mtschemcreate", {
description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/<filename>.mts\"",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
if param == nil then
worldedit.player_notify(name, "No filename specified")
return
@ -1032,7 +1026,7 @@ minetest.register_chatcommand("/mtschemcreate", {
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\") --escape any nasty characters
os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
local ret = minetest.create_schematic(pos1, pos2, worldedit.prob_list[name], filename)
local ret = minetest.create_schematic(worldedit.pos1[name], worldedit.pos2[name], worldedit.prob_list[name], filename)
if ret == nil then
worldedit.player_notify(name, "failed to create Minetest schematic", false)
else
@ -1111,8 +1105,7 @@ minetest.register_chatcommand("/clearobjects", {
description = "Clears all objects within the WorldEdit region",
privs = {worldedit=true},
func = safe_region(function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local count = worldedit.clearobjects(pos1, pos2)
local count = worldedit.clearobjects(worldedit.pos1[name], worldedit.pos2[name])
worldedit.player_notify(name, count .. " objects cleared")
end),
})