Minetest-WorldEditAdditions/worldeditadditions_commands/commands/ellipsoid.lua

81 lines
3.5 KiB
Lua
Raw Normal View History

2020-05-02 23:37:18 +00:00
-- ███████ ██ ██ ██ ██████ ███████ ██████ ██ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████
2022-09-18 20:30:28 +00:00
local wea_c = worldeditadditions
local Vector3 = wea_c.Vector3
2020-05-02 23:37:18 +00:00
local function parse_params_ellipsoid(params_text)
2022-09-18 20:30:28 +00:00
local parts = wea_c.split_shell(params_text)
2020-05-02 23:37:18 +00:00
if #parts < 4 then
return false, "Error: Not enough arguments. Expected \"<rx> <ry> <rz> <replace_node> [h[ollow]]\"."
2020-05-02 23:37:18 +00:00
end
local radius = minetest.string_to_pos(parts[1].." "..parts[2].." "..parts[3])
if not radius then
return false, "Error: 3 radii must be specified."
end
2022-09-18 20:30:28 +00:00
wea_c.vector.abs(radius)
2020-05-02 23:37:18 +00:00
local replace_node = worldedit.normalize_nodename(parts[4])
if not replace_node then
return false, "Error: Invalid replace_node specified."
end
local hollow = false
if parts[5] == "hollow" or parts[5] == "h" then
hollow = true
end
2020-05-02 23:37:18 +00:00
return true, replace_node, radius, hollow
2020-05-02 23:37:18 +00:00
end
worldeditadditions_core.register_command("ellipsoid", {
params = "<rx> <ry> <rz> <replace_node> [h[ollow]]",
2020-05-02 23:37:18 +00:00
description = "Creates a 3D ellipsoid with a radius of (rx, ry, rz) at pos1, filled with <replace_node>.",
privs = { worldedit = true },
require_pos = 1,
parse = function(params_text)
local values = {parse_params_ellipsoid(params_text)}
2022-09-18 20:30:28 +00:00
return wea_c.table.unpack(values)
end,
nodes_needed = function(name, target_node, radius)
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
end,
func = function(name, target_node, radius, hollow)
2022-09-18 20:30:28 +00:00
local start_time = wea_c.get_ms_time()
local pos1 = Vector3.clone(worldedit.pos1[name])
local replaced = worldeditadditions.ellipsoid(pos1, radius, target_node, hollow)
local time_taken = wea_c.get_ms_time() - start_time
2020-05-02 23:37:18 +00:00
2022-09-18 20:30:28 +00:00
minetest.log("action", name.." used //ellipsoid at "..pos1..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
return true, replaced .. " nodes replaced in " .. wea_c.format.human_time(time_taken)
end
2020-05-02 23:37:18 +00:00
})
-- TODO: This duplicates a lot of code. Perhaps we can trim it down a bit?
worldeditadditions_core.register_command("hollowellipsoid", {
2020-05-02 23:37:18 +00:00
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>.",
privs = { worldedit = true },
require_pos = 1,
parse = function(params_text)
local values = {parse_params_ellipsoid(params_text)}
2022-09-18 20:30:28 +00:00
return wea_c.table.unpack(values)
end,
nodes_needed = function(name, target_node, radius)
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
end,
func = function(name, target_node, radius)
2022-09-18 20:30:28 +00:00
local start_time = wea_c.get_ms_time()
local pos1 = Vector3.clone(worldedit.pos1[name])
local replaced = worldeditadditions.ellipsoid(pos1, radius, target_node, true)
local time_taken = wea_c.get_ms_time() - start_time
2020-05-02 23:37:18 +00:00
2022-09-18 20:30:28 +00:00
minetest.log("action", name.." used //hollowellipsoid at "..pos1..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
return true, replaced .. " nodes replaced in " .. wea_c.format.human_time(time_taken)
end
2020-05-02 23:37:18 +00:00
})