2020-05-03 01:37:18 +02:00
-- ███████ ██ ██ ██ ██████ ███████ ██████ ██ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████
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:_ \\ -]+) " )
if found == nil then
2020-05-10 23:01:31 +02:00
return false , " Invalid syntax "
2020-05-03 01:37:18 +02:00
end
local radius = {
x = tonumber ( radius_x ) ,
y = tonumber ( radius_y ) ,
z = tonumber ( radius_z )
}
replace_node = worldedit.normalize_nodename ( replace_node )
2020-05-10 23:01:31 +02:00
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
2020-05-03 01:37:18 +02:00
2020-05-10 23:01:31 +02:00
return true , replace_node , radius
2020-05-03 01:37:18 +02:00
end
2020-05-10 23:01:31 +02:00
worldedit.register_command ( " ellipsoid " , {
2020-05-03 01:37:18 +02:00
params = " <rx> <ry> <rz> <replace_node> " ,
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 ) }
return 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 )
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 , false )
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 " )
2020-05-10 23:01:31 +02:00
return true , replaced .. " nodes replaced in " .. time_taken .. " s "
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 ) }
return 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 )
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 " )
2020-05-10 23:01:31 +02:00
return true , replaced .. " nodes replaced in " .. time_taken .. " s "
end
2020-05-03 01:37:18 +02:00
} )