2020-09-20 20:19:29 +00:00
-- ███████ ██ ██ ██ ██████ ███████ ███████ █████ ██████ ██████ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- █████ ██ ██ ██ ██████ ███████ █████ ███████ ██████ ██████ ██ ████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ███████ ██ ██ ███████ ███████ ██ ██ ██ ██ ███████ ██
2022-05-19 01:31:01 +00:00
local wea_c = worldeditadditions_core
2020-09-20 20:19:29 +00:00
2022-05-19 21:10:09 +00:00
worldeditadditions_core.register_command ( " ellipsoidapply " , {
2020-09-20 20:19:29 +00:00
params = " <command_name> <args> " ,
description = " Executes the given command (automatically prepending '//'), clipping the result with an ellipse given by the defined region. " ,
privs = { worldedit = true } ,
require_pos = 2 ,
parse = function ( params_text )
if params_text == " " then return false , " Error: No command specified. " end
local cmd_name , args_text = params_text : match ( " ([^%s]+)%s+(.+) " )
if not cmd_name then
2020-09-20 21:07:47 +00:00
cmd_name = params_text
args_text = " "
2020-09-20 20:19:29 +00:00
end
2020-09-20 21:07:47 +00:00
-- print("cmd_name", cmd_name, "args_text", args_text)
2020-09-20 20:19:29 +00:00
-- Note that we search the worldedit commands here, not the minetest ones
2022-05-19 01:31:01 +00:00
local cmd_we = wea_c.fetch_command_def ( cmd_name )
2020-09-20 20:19:29 +00:00
if cmd_we == nil then
return false , " Error: " .. cmd_name .. " isn't a valid command. "
end
2020-09-20 21:07:47 +00:00
-- print("cmd require_pos", cmd_we.require_pos, "END")
2021-07-16 22:00:31 +00:00
if cmd_we.require_pos ~= 2 and cmd_name ~= " multi " then
2020-09-20 20:19:29 +00:00
return false , " Error: The command " .. cmd_name .. " exists, but doesn't take 2 positions and so can't be used with //ellipsoidapply. "
end
-- Run parsing of target command
-- Lifted from cubeapply in WorldEdit
local args_parsed = { cmd_we.parse ( args_text ) }
if not table.remove ( args_parsed , 1 ) then
return false , args_parsed [ 1 ]
end
return true , cmd_we , args_parsed
end ,
nodes_needed = function ( name )
local pos1 , pos2 = worldedit.sort_pos ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
return math.ceil ( 4 / 3 * math.pi * ( pos2.x - pos1.x ) / 2 * ( pos2.y - pos1.y ) / 2 * ( pos2.z - pos1.z ) / 2 )
end ,
func = function ( name , cmd , args_parsed )
if not minetest.check_player_privs ( name , cmd.privs ) then
2021-07-30 19:03:31 +00:00
return false , " Your privileges are insufficient to execute the command ' " .. cmd .. " '. "
2020-09-20 20:19:29 +00:00
end
local success , stats_time = worldeditadditions.ellipsoidapply (
worldedit.pos1 [ name ] , worldedit.pos2 [ name ] ,
function ( )
2021-06-27 23:56:29 +00:00
cmd.func ( name , worldeditadditions.table . unpack ( args_parsed ) )
2022-09-18 15:33:37 +00:00
end --, args_parsed
2020-09-20 20:19:29 +00:00
)
2020-09-20 21:07:47 +00:00
local time_overhead = 100 - worldeditadditions.round ( ( stats_time.fn / stats_time.all ) * 100 , 3 )
2020-09-20 20:19:29 +00:00
2021-03-20 01:48:56 +00:00
minetest.log ( " action " , name .. " used //ellipsoidapply at " .. worldeditadditions.vector . tostring ( worldedit.pos1 [ name ] ) .. " - " .. worldeditadditions.vector . tostring ( worldedit.pos2 [ name ] ) .. " in " .. worldeditadditions.format . human_time ( stats_time.all ) )
return true , " Complete in " .. worldeditadditions.format . human_time ( stats_time.all ) .. " ( " .. worldeditadditions.format . human_time ( stats_time.fn ) .. " fn, " .. time_overhead .. " % ellipsoidapply overhead) "
2020-09-20 20:19:29 +00:00
end
} )