mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
Migrate //ellipsoid and it's sibling to worldedit.register_command
This commit is contained in:
parent
b7888a2b3f
commit
6be534d4b7
1 changed files with 34 additions and 50 deletions
|
@ -1,5 +1,3 @@
|
||||||
local we_c = worldeditadditions_commands
|
|
||||||
|
|
||||||
-- ███████ ██ ██ ██ ██████ ███████ ██████ ██ ██████
|
-- ███████ ██ ██ ██ ██████ ███████ ██████ ██ ██████
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
-- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██
|
-- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██
|
||||||
|
@ -10,7 +8,7 @@ local function parse_params_ellipsoid(params_text)
|
||||||
local found, _, radius_x, radius_y, radius_z, replace_node = params_text:find("([0-9]+)%s+([0-9]+)%s+([0-9]+)%s+([a-z:_\\-]+)")
|
local found, _, radius_x, radius_y, radius_z, replace_node = params_text:find("([0-9]+)%s+([0-9]+)%s+([0-9]+)%s+([a-z:_\\-]+)")
|
||||||
|
|
||||||
if found == nil then
|
if found == nil then
|
||||||
return nil, nil
|
return false, "Invalid syntax"
|
||||||
end
|
end
|
||||||
|
|
||||||
local radius = {
|
local radius = {
|
||||||
|
@ -20,73 +18,59 @@ local function parse_params_ellipsoid(params_text)
|
||||||
}
|
}
|
||||||
|
|
||||||
replace_node = worldedit.normalize_nodename(replace_node)
|
replace_node = worldedit.normalize_nodename(replace_node)
|
||||||
|
if not replace_node then
|
||||||
|
worldedit.player_notify(name, "Error: Invalid node name.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if not radius.x or not radius.y or not radius.z then
|
||||||
|
worldedit.player_notify(name, "Error: Invalid radius(es).")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
return replace_node, radius
|
return true, replace_node, radius
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_chatcommand("/ellipsoid", {
|
worldedit.register_command("ellipsoid", {
|
||||||
params = "<rx> <ry> <rz> <replace_node>",
|
params = "<rx> <ry> <rz> <replace_node>",
|
||||||
description = "Creates a 3D ellipsoid with a radius of (rx, ry, rz) at pos1, filled with <replace_node>.",
|
description = "Creates a 3D ellipsoid with a radius of (rx, ry, rz) at pos1, filled with <replace_node>.",
|
||||||
privs = { worldedit = true },
|
privs = { worldedit = true },
|
||||||
func = we_c.safe_region(function(name, params_text)
|
require_pos = 1,
|
||||||
local target_node, radius = parse_params_ellipsoid(params_text)
|
parse = function(params_text)
|
||||||
|
local values = {parse_params_ellipsoid(params_text)}
|
||||||
if not target_node then
|
return unpack(values)
|
||||||
worldedit.player_notify(name, "Error: Invalid node name.")
|
end,
|
||||||
return false
|
nodes_needed = function(name, target_node, radius)
|
||||||
end
|
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
|
||||||
if not radius then
|
end,
|
||||||
worldedit.player_notify(name, "Error: Invalid radius(es).")
|
func = function(name, target_node, radius)
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local start_time = os.clock()
|
local start_time = os.clock()
|
||||||
local replaced = worldedit.ellipsoid(worldedit.pos1[name], radius, target_node, false)
|
local replaced = worldedit.ellipsoid(worldedit.pos1[name], radius, target_node, false)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = os.clock() - start_time
|
||||||
|
|
||||||
worldedit.player_notify(name, replaced .. " nodes replaced in " .. time_taken .. "s")
|
|
||||||
minetest.log("action", name .. " used //ellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //ellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
end, function(name, params_text)
|
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
||||||
local target_node, radius = parse_params_ellipsoid(params_text)
|
end
|
||||||
if not target_node or not radius then
|
|
||||||
worldedit.player_notify(name, "Error: Invalid input '" .. params_text .. "'. Try '/help /ellipsoid' to learn how to use this command.")
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
|
|
||||||
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
|
|
||||||
end)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
-- TODO: This duplicates a lot of code. Perhaps we can trim it down a bit?
|
-- TODO: This duplicates a lot of code. Perhaps we can trim it down a bit?
|
||||||
minetest.register_chatcommand("/hollowellipsoid", {
|
worldedit.register_command("hollowellipsoid", {
|
||||||
params = "<rx> <ry> <rz> <replace_node>",
|
params = "<rx> <ry> <rz> <replace_node>",
|
||||||
description = "Creates a 3D hollow ellipsoid with a radius of (rx, ry, rz) at pos1, made out of <replace_node>.",
|
description = "Creates a 3D hollow ellipsoid with a radius of (rx, ry, rz) at pos1, made out of <replace_node>.",
|
||||||
privs = { worldedit = true },
|
privs = { worldedit = true },
|
||||||
func = we_c.safe_region(function(name, params_text)
|
require_pos = 1,
|
||||||
local target_node, radius = parse_params_ellipsoid(params_text)
|
parse = function(params_text)
|
||||||
|
local values = {parse_params_ellipsoid(params_text)}
|
||||||
if not target_node then
|
return unpack(values)
|
||||||
worldedit.player_notify(name, "Error: Invalid node name.")
|
end,
|
||||||
return false
|
nodes_needed = function(name, target_node, radius)
|
||||||
end
|
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
|
||||||
if not radius then
|
end,
|
||||||
worldedit.player_notify(name, "Error: Invalid radius(es).")
|
func = function(name, target_node, radius)
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local start_time = os.clock()
|
local start_time = os.clock()
|
||||||
local replaced = worldedit.ellipsoid(worldedit.pos1[name], radius, target_node, true)
|
local replaced = worldedit.ellipsoid(worldedit.pos1[name], radius, target_node, true)
|
||||||
local time_taken = os.clock() - start_time
|
local time_taken = os.clock() - start_time
|
||||||
|
|
||||||
worldedit.player_notify(name, replaced .. " nodes replaced in " .. time_taken .. "s")
|
|
||||||
minetest.log("action", name .. " used //hollowellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //hollowellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
end, function(name, params_text)
|
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
|
||||||
local target_node, radius = parse_params_ellipsoid(params_text)
|
end
|
||||||
if not target_node or not radius then
|
|
||||||
worldedit.player_notify(name, "Error: Invalid input '" .. params_text .. "'. Try '/help /hollowellipsoid' to learn how to use this command.")
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
|
|
||||||
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
|
|
||||||
end)
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue