2020-05-03 01:37:18 +02:00
-- ███████ ██ ██ ██ ██████ ███████ ██████ ██ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████
2021-05-31 00:29:14 +02:00
local wea = worldeditadditions
2020-05-03 01:37:18 +02:00
local function parse_params_ellipsoid ( params_text )
2021-07-31 17:03:04 +02:00
local parts = wea.split_shell ( params_text )
2020-05-03 01:37:18 +02:00
2021-05-31 00:29:14 +02:00
if # parts < 4 then
return false , " Error: Not enough arguments. Expected \" <rx> <ry> <rz> <replace_node> [h[ollow]] \" . "
2020-05-03 01:37:18 +02:00
end
2021-05-31 00:29:14 +02:00
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
wea.vector . abs ( radius )
2020-05-03 01:37:18 +02:00
2021-05-31 00:29:14 +02:00
local replace_node = worldedit.normalize_nodename ( parts [ 4 ] )
2020-05-10 23:01:31 +02:00
if not replace_node then
2021-05-31 00:29:14 +02:00
return false , " Error: Invalid replace_node specified. "
2020-05-10 23:01:31 +02:00
end
2021-05-31 00:29:14 +02:00
local hollow = false
if parts [ 5 ] == " hollow " or parts [ 5 ] == " h " then
hollow = true
2020-05-10 23:01:31 +02:00
end
2020-05-03 01:37:18 +02:00
2021-05-31 00:29:14 +02:00
return true , replace_node , radius , hollow
2020-05-03 01:37:18 +02:00
end
2020-05-10 23:01:31 +02:00
worldedit.register_command ( " ellipsoid " , {
2021-05-31 00:29:14 +02:00
params = " <rx> <ry> <rz> <replace_node> [h[ollow]] " ,
2020-05-03 01:37:18 +02:00
description = " Creates a 3D ellipsoid with a radius of (rx, ry, rz) at pos1, filled with <replace_node>. " ,
privs = { worldedit = true } ,
2020-05-10 23:01:31 +02:00
require_pos = 1 ,
parse = function ( params_text )
local values = { parse_params_ellipsoid ( params_text ) }
2021-06-28 01:56:29 +02:00
return wea.table . unpack ( values )
2020-05-10 23:01:31 +02:00
end ,
nodes_needed = function ( name , target_node , radius )
return math.ceil ( 4 / 3 * math.pi * radius.x * radius.y * radius.z )
end ,
2021-05-31 00:29:14 +02:00
func = function ( name , target_node , radius , hollow )
2020-06-26 21:46:35 +02:00
local start_time = worldeditadditions.get_ms_time ( )
2021-05-31 00:29:14 +02:00
local replaced = worldeditadditions.ellipsoid ( worldedit.pos1 [ name ] , radius , target_node , hollow )
2020-06-26 21:46:35 +02:00
local time_taken = worldeditadditions.get_ms_time ( ) - start_time
2020-05-03 01:37:18 +02:00
minetest.log ( " action " , name .. " used //ellipsoid at " .. worldeditadditions.vector . tostring ( worldedit.pos1 [ name ] ) .. " , replacing " .. replaced .. " nodes in " .. time_taken .. " s " )
2021-03-20 02:48:56 +01:00
return true , replaced .. " nodes replaced in " .. worldeditadditions.format . human_time ( time_taken )
2020-05-10 23:01:31 +02:00
end
2020-05-03 01:37:18 +02:00
} )
-- TODO: This duplicates a lot of code. Perhaps we can trim it down a bit?
2020-05-10 23:01:31 +02:00
worldedit.register_command ( " hollowellipsoid " , {
2020-05-03 01:37:18 +02: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 } ,
2020-05-10 23:01:31 +02:00
require_pos = 1 ,
parse = function ( params_text )
local values = { parse_params_ellipsoid ( params_text ) }
2021-06-28 01:56:29 +02:00
return wea.table . unpack ( values )
2020-05-10 23:01:31 +02:00
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 )
2020-06-26 21:46:35 +02:00
local start_time = worldeditadditions.get_ms_time ( )
2020-05-11 00:29:49 +02:00
local replaced = worldeditadditions.ellipsoid ( worldedit.pos1 [ name ] , radius , target_node , true )
2020-06-26 21:46:35 +02:00
local time_taken = worldeditadditions.get_ms_time ( ) - start_time
2020-05-03 01:37:18 +02:00
minetest.log ( " action " , name .. " used //hollowellipsoid at " .. worldeditadditions.vector . tostring ( worldedit.pos1 [ name ] ) .. " , replacing " .. replaced .. " nodes in " .. time_taken .. " s " )
2021-03-20 02:48:56 +01:00
return true , replaced .. " nodes replaced in " .. worldeditadditions.format . human_time ( time_taken )
2020-05-10 23:01:31 +02:00
end
2020-05-03 01:37:18 +02:00
} )