2020-05-11 23:38:42 +00:00
-- ██████ ██████ ██ ██ ███ ██ ████████
-- ██ ██ ██ ██ ██ ████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██████ ██████ ██████ ██ ████ ██
2022-05-19 21:10:09 +00:00
worldeditadditions_core.register_command ( " count " , {
2020-05-11 23:38:42 +00:00
params = " " ,
description = " Counts all the nodes in the defined region. " ,
privs = { worldedit = true } ,
require_pos = 2 ,
parse = function ( params_text )
return true
end ,
nodes_needed = function ( name )
-- We don't actually modify anything, but without returning a
-- number here safe_region doesn't work
return worldedit.volume ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
end ,
func = function ( name )
2020-06-26 19:46:35 +00:00
local start_time = worldeditadditions.get_ms_time ( )
2020-05-11 23:38:42 +00:00
2021-01-31 17:43:08 +00:00
local success , counts , total = worldeditadditions.count (
worldedit.pos1 [ name ] , worldedit.pos2 [ name ] ,
true
)
2021-03-20 01:48:56 +00:00
local result = worldeditadditions.format . make_ascii_table ( counts ) .. " \n " ..
2020-05-11 23:38:42 +00:00
string.rep ( " = " , 6 + # tostring ( total ) + 6 ) .. " \n " ..
" Total " .. total .. " nodes \n "
2020-06-26 19:46:35 +00:00
local time_taken = worldeditadditions.get_ms_time ( ) - start_time
2020-05-11 23:38:42 +00:00
2021-03-20 01:48:56 +00:00
minetest.log ( " action " , name .. " used //count at " .. worldeditadditions.vector . tostring ( worldedit.pos1 [ name ] ) .. " - " .. worldeditadditions.vector . tostring ( worldedit.pos2 [ name ] ) .. " , counting " .. total .. " nodes in " .. worldeditadditions.format . human_time ( time_taken ) )
2020-05-11 23:38:42 +00:00
return true , result
end
} )