2022-09-18 22:30:28 +02:00
|
|
|
local wea_c = worldeditadditions_core
|
|
|
|
local wea = worldeditadditions
|
|
|
|
local Vector3 = wea_c.Vector3
|
|
|
|
|
2020-05-12 01:38:42 +02:00
|
|
|
-- ██████ ██████ ██ ██ ███ ██ ████████
|
|
|
|
-- ██ ██ ██ ██ ██ ████ ██ ██
|
|
|
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
|
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
|
|
-- ██████ ██████ ██████ ██ ████ ██
|
2022-05-19 23:10:09 +02:00
|
|
|
worldeditadditions_core.register_command("count", {
|
2020-05-12 01:38:42 +02: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)
|
2022-09-18 22:30:28 +02:00
|
|
|
local start_time = wea_c.get_ms_time()
|
|
|
|
local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
|
|
|
|
local success, counts, total = wea.count(
|
|
|
|
pos1, pos2,
|
2021-01-31 18:43:08 +01:00
|
|
|
true
|
|
|
|
)
|
2022-09-18 22:30:28 +02:00
|
|
|
if not success then return success, counts end
|
2021-01-31 18:43:08 +01:00
|
|
|
|
2023-05-24 23:20:52 +02:00
|
|
|
local result = "\n"..wea_c.format.make_ascii_table(counts).."\n"..
|
2020-05-12 01:38:42 +02:00
|
|
|
string.rep("=", 6 + #tostring(total) + 6).."\n"..
|
|
|
|
"Total "..total.." nodes\n"
|
|
|
|
|
2022-09-18 22:30:28 +02:00
|
|
|
local time_taken = wea_c.get_ms_time() - start_time
|
2020-05-12 01:38:42 +02:00
|
|
|
|
|
|
|
|
2022-09-18 22:30:28 +02:00
|
|
|
minetest.log("action", name.." used //count at "..pos1.." - "..pos2..", counting "..total.." nodes in "..wea_c.format.human_time(time_taken))
|
2020-05-12 01:38:42 +02:00
|
|
|
return true, result
|
|
|
|
end
|
|
|
|
})
|