Minetest-WorldEditAdditions/worldeditadditions_commands/commands/count.lua

44 lines
1.6 KiB
Lua
Raw Normal View History

2022-09-18 20:30:28 +00:00
local wea_c = worldeditadditions_core
local wea = worldeditadditions
local Vector3 = wea_c.Vector3
2020-05-11 23:38:42 +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)
print("div0" * yay)
2020-05-11 23:38:42 +00:00
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 20:30:28 +00: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,
true
)
2022-09-18 20:30:28 +00:00
if not success then return success, counts end
2023-05-24 21:20:52 +00:00
local result = "\n"..wea_c.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"
2022-09-18 20:30:28 +00:00
local time_taken = wea_c.get_ms_time() - start_time
2020-05-11 23:38:42 +00:00
2022-09-18 20:30:28 +00:00
minetest.log("action", name.." used //count at "..pos1.." - "..pos2..", counting "..total.." nodes in "..wea_c.format.human_time(time_taken))
2020-05-11 23:38:42 +00:00
return true, result
end
})