finish upgrading top-level commands

This commit is contained in:
Starbeamrainbowlabs 2022-09-18 21:30:28 +01:00
parent 128dc8f103
commit 459e15b5c2
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
11 changed files with 131 additions and 90 deletions

View file

@ -1,5 +1,6 @@
local we_c = worldeditadditions_commands
local wea = worldeditadditions local wea = worldeditadditions
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ██████ ██████ ███ ██ ███████ ███ ███ ███████ █████ ██ -- ██████ ██████ ███ ██ ███████ ███ ███ ███████ █████ ██
-- ██ ██ ██ ██ ████ ██ ██ ████ ████ ██ ██ ██ ██ -- ██ ██ ██ ██ ████ ██ ██ ████ ████ ██ ██ ██ ██
@ -16,20 +17,20 @@ worldeditadditions_core.register_command("bonemeal", {
params_text = "1" params_text = "1"
end end
local parts = wea.split_shell(params_text) local parts = wea_c.split_shell(params_text)
local strength = 1 local strength = 1
local chance = 1 local chance = 1
local node_names = {} -- An empty table means all nodes local node_names = {} -- An empty table means all nodes
if #parts >= 1 then if #parts >= 1 then
strength = tonumber(wea.trim(table.remove(parts, 1))) strength = tonumber(wea_c.trim(table.remove(parts, 1)))
if not strength then if not strength then
return false, "Invalid strength value (value must be an integer)" return false, "Invalid strength value (value must be an integer)"
end end
end end
if #parts >= 1 then if #parts >= 1 then
chance = worldeditadditions.parse.chance(table.remove(parts, 1)) chance = wea_c.parse.chance(table.remove(parts, 1))
if not chance then if not chance then
return false, "Invalid chance value (must be a positive integer)" return false, "Invalid chance value (must be a positive integer)"
end end
@ -57,21 +58,22 @@ worldeditadditions_core.register_command("bonemeal", {
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) / 2 return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) / 2
end, end,
func = function(name, strength, chance, node_names) func = function(name, strength, chance, node_names)
local start_time = worldeditadditions.get_ms_time() local start_time = wea_c.get_ms_time()
local success, nodes_bonemealed, candidates = worldeditadditions.bonemeal( local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
worldedit.pos1[name], worldedit.pos2[name], local success, nodes_bonemealed, candidates = wea.bonemeal(
pos1, pos2,
strength, chance, strength, chance,
node_names node_names
) )
-- nodes_bonemealed is an error message here if success == false -- nodes_bonemealed is an error message here if success == false
if not success then return success, nodes_bonemealed end if not success then return success, nodes_bonemealed end
local percentage = worldeditadditions.round((nodes_bonemealed / candidates)*100, 2) local percentage = wea_c.round((nodes_bonemealed / candidates)*100, 2)
local time_taken = worldeditadditions.get_ms_time() - start_time local time_taken = wea_c.get_ms_time() - start_time
-- Avoid nan% - since if there aren't any candidates then nodes_bonemealed will be 0 too -- Avoid nan% - since if there aren't any candidates then nodes_bonemealed will be 0 too
if candidates == 0 then percentage = 0 end if candidates == 0 then percentage = 0 end
minetest.log("action", name .. " used //bonemeal at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", bonemealing " .. nodes_bonemealed.." nodes (out of "..candidates.." nodes) at strength "..strength.." in "..time_taken.."s") minetest.log("action", name .. " used //bonemeal at "..pos1.." - "..pos2..", bonemealing " .. nodes_bonemealed.." nodes (out of "..candidates.." nodes) at strength "..strength.." in "..time_taken.."s")
return true, nodes_bonemealed.." out of "..candidates.." (~"..percentage.."%) candidates bonemealed in "..worldeditadditions.format.human_time(time_taken) return true, nodes_bonemealed.." out of "..candidates.." (~"..percentage.."%) candidates bonemealed in "..wea_c.format.human_time(time_taken)
end end
}) })

View file

@ -1,5 +1,6 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ██████ ██████ ███ ██ ██ ██ ██████ ██ ██ ██ ███████ -- ██████ ██████ ███ ██ ██ ██ ██████ ██ ██ ██ ███████
-- ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██
@ -15,7 +16,7 @@ worldeditadditions_core.register_command("convolve", {
if not params_text then params_text = "" end if not params_text then params_text = "" end
-- local parts = wea.split(params_text, "%s+", false) -- local parts = wea.split(params_text, "%s+", false)
local parts = wea.split_shell(params_text) local parts = wea_c.split_shell(params_text)
local kernel_name = "gaussian" local kernel_name = "gaussian"
local width = 5 local width = 5
@ -26,7 +27,7 @@ worldeditadditions_core.register_command("convolve", {
kernel_name = parts[1] kernel_name = parts[1]
end end
if #parts >= 2 then if #parts >= 2 then
local parts_dimension = wea.split(parts[2], ",%s*", false) local parts_dimension = wea_c.split(parts[2], ",%s*", false)
width = tonumber(parts_dimension[1]) width = tonumber(parts_dimension[1])
if not width then if not width then
return false, "Error: Invalid width (it must be a positive odd integer)." return false, "Error: Invalid width (it must be a positive odd integer)."
@ -53,9 +54,13 @@ worldeditadditions_core.register_command("convolve", {
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
end, end,
func = function(name, kernel_name, kernel_width, kernel_height, sigma) func = function(name, kernel_name, kernel_width, kernel_height, sigma)
local start_time = wea.get_ms_time() local start_time = wea_c.get_ms_time()
local success, kernel = wea.get_conv_kernel(kernel_name, kernel_width, kernel_height, sigma) local success, kernel = wea_c.get_conv_kernel(
kernel_name,
kernel_width, kernel_height,
sigma
)
if not success then return success, kernel end if not success then return success, kernel end
local kernel_size = Vector3.new( local kernel_size = Vector3.new(
@ -76,10 +81,10 @@ worldeditadditions_core.register_command("convolve", {
) )
if not success then return success, stats end if not success then return success, stats end
local time_taken = wea.get_ms_time() - start_time local time_taken = wea_c.get_ms_time() - start_time
minetest.log("action", name.." used //convolve at "..pos1.." - "..pos2..", adding "..stats.added.." nodes and removing "..stats.removed.." nodes in "..time_taken.."s") minetest.log("action", name.." used //convolve at "..pos1.." - "..pos2..", adding "..stats.added.." nodes and removing "..stats.removed.." nodes in "..time_taken.."s")
return true, "Added "..stats.added.." and removed "..stats.removed.." nodes in " .. wea.format.human_time(time_taken) return true, "Added "..stats.added.." and removed "..stats.removed.." nodes in " .. wea_c.format.human_time(time_taken)
end end
}) })

View file

@ -1,10 +1,11 @@
local wea_c = worldeditadditions_core
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local Vector3 = wea_c.Vector3
local function parse_stage2(name, parts) local function parse_stage2(name, parts)
local success, vpos1, vpos2 = wea.parse.axes( local success, vpos1, vpos2 = wea_c.parse.axes(
parts, parts,
wea.player_dir(name) wea_c.player_dir(name)
) )
if not success then return success, vpos1 end if not success then return success, vpos1 end
@ -32,7 +33,7 @@ worldeditadditions_core.register_command("copy+", { -- TODO: Make this an overri
parse = function(params_text) parse = function(params_text)
if not params_text then params_text = "" end if not params_text then params_text = "" end
local parts = wea.split_shell(params_text) local parts = wea_c.split_shell(params_text)
return true, parts return true, parts
end, end,
@ -40,7 +41,7 @@ worldeditadditions_core.register_command("copy+", { -- TODO: Make this an overri
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
end, end,
func = function(name, parts) func = function(name, parts)
local start_time = wea.get_ms_time() local start_time = wea_c.get_ms_time()
local success_a, copy_offset = parse_stage2(name, parts) local success_a, copy_offset = parse_stage2(name, parts)
if not success_a then return success_a, copy_offset end if not success_a then return success_a, copy_offset end
@ -57,10 +58,10 @@ worldeditadditions_core.register_command("copy+", { -- TODO: Make this an overri
) )
if not success_b then return success_b, nodes_modified end if not success_b then return success_b, nodes_modified end
local time_taken = wea.get_ms_time() - start_time local time_taken = wea_c.get_ms_time() - start_time
minetest.log("action", name.." used //copy from "..source_pos1.." - "..source_pos2.." to "..target_pos1.." - "..target_pos2..", modifying "..nodes_modified.." nodes in "..wea.format.human_time(time_taken)) minetest.log("action", name.." used //copy from "..source_pos1.." - "..source_pos2.." to "..target_pos1.." - "..target_pos2..", modifying "..nodes_modified.." nodes in "..wea_c.format.human_time(time_taken))
return true, nodes_modified.." nodes copied using offset "..copy_offset.." in "..wea.format.human_time(time_taken) return true, nodes_modified.." nodes copied using offset "..copy_offset.." in "..wea_c.format.human_time(time_taken)
end end
}) })

View file

@ -1,3 +1,7 @@
local wea_c = worldeditadditions_core
local wea = worldeditadditions
local Vector3 = wea_c.Vector3
-- ██████ ██████ ██ ██ ███ ██ ████████ -- ██████ ██████ ██ ██ ███ ██ ████████
-- ██ ██ ██ ██ ██ ████ ██ ██ -- ██ ██ ██ ██ ██ ████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██
@ -17,21 +21,22 @@ worldeditadditions_core.register_command("count", {
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
end, end,
func = function(name) func = function(name)
local start_time = worldeditadditions.get_ms_time() local start_time = wea_c.get_ms_time()
local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
local success, counts, total = worldeditadditions.count( local success, counts, total = wea.count(
worldedit.pos1[name], worldedit.pos2[name], pos1, pos2,
true true
) )
if not success then return success, counts end
local result = worldeditadditions.format.make_ascii_table(counts).."\n".. local result = wea_c.format.make_ascii_table(counts).."\n"..
string.rep("=", 6 + #tostring(total) + 6).."\n".. string.rep("=", 6 + #tostring(total) + 6).."\n"..
"Total "..total.." nodes\n" "Total "..total.." nodes\n"
local time_taken = worldeditadditions.get_ms_time() - start_time local time_taken = wea_c.get_ms_time() - start_time
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)) minetest.log("action", name.." used //count at "..pos1.." - "..pos2..", counting "..total.." nodes in "..wea_c.format.human_time(time_taken))
return true, result return true, result
end end
}) })

View file

@ -1,10 +1,11 @@
local wea_c = worldeditadditions_core
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local Vector3 = wea_c.Vector3
local function parse_stage2(name, parts) local function parse_stage2(name, parts)
local result = Vector3.new() local result = Vector3.new()
for i,axis_name in ipairs(parts) do for i,axis_name in ipairs(parts) do
local success, result_this = wea.parse.axis_name(axis_name, wea.player_dir(name)) local success, result_this = wea_c.parse.axis_name(axis_name, wea_c.player_dir(name))
if not success then return success, result_this end if not success then return success, result_this end
result = result + result_this result = result + result_this
@ -33,7 +34,7 @@ worldeditadditions_core.register_command("dome+", { -- TODO: Make this an overri
parse = function(params_text) parse = function(params_text)
if not params_text then params_text = "" end if not params_text then params_text = "" end
local parts = wea.split_shell(params_text) local parts = wea_c.split_shell(params_text)
if #parts < 2 then if #parts < 2 then
return false, "Error: Not enough arguments (see /help /dome for usage information)." return false, "Error: Not enough arguments (see /help /dome for usage information)."
@ -57,7 +58,7 @@ worldeditadditions_core.register_command("dome+", { -- TODO: Make this an overri
hollow = true hollow = true
table.remove(parts, #parts) table.remove(parts, #parts)
end end
local axes = wea.table.shallowcopy(parts) local axes = wea_c.table.shallowcopy(parts)
table.remove(axes, 1) table.remove(axes, 1)
table.remove(axes, 1) table.remove(axes, 1)
@ -71,7 +72,7 @@ worldeditadditions_core.register_command("dome+", { -- TODO: Make this an overri
return 4/3 * math.pi * radius * radius * radius return 4/3 * math.pi * radius * radius * radius
end, end,
func = function(name, radius, replace_node, axes, hollow) func = function(name, radius, replace_node, axes, hollow)
local start_time = wea.get_ms_time() local start_time = wea_c.get_ms_time()
local success_a, pointing_dir = parse_stage2(name, axes) local success_a, pointing_dir = parse_stage2(name, axes)
if not success_a then return success_a, pointing_dir end if not success_a then return success_a, pointing_dir end
@ -87,10 +88,10 @@ worldeditadditions_core.register_command("dome+", { -- TODO: Make this an overri
) )
if not success_b then return success_b, nodes_replaced end if not success_b then return success_b, nodes_replaced end
local time_taken = wea.get_ms_time() - start_time local time_taken = wea_c.get_ms_time() - start_time
minetest.log("action", name.." used //dome+ at "..pos.." with a radius of "..tostring(radius)..", modifying "..nodes_replaced.." nodes in "..wea.format.human_time(time_taken)) minetest.log("action", name.." used //dome+ at "..pos.." with a radius of "..tostring(radius)..", modifying "..nodes_replaced.." nodes in "..wea_c.format.human_time(time_taken))
return true, nodes_replaced.." nodes replaced "..wea.format.human_time(time_taken) return true, nodes_replaced.." nodes replaced "..wea_c.format.human_time(time_taken)
end end
}) })

View file

@ -3,9 +3,11 @@
-- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██ -- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████ -- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████
local wea = worldeditadditions local wea_c = worldeditadditions
local Vector3 = wea_c.Vector3
local function parse_params_ellipsoid(params_text) local function parse_params_ellipsoid(params_text)
local parts = wea.split_shell(params_text) local parts = wea_c.split_shell(params_text)
if #parts < 4 then if #parts < 4 then
return false, "Error: Not enough arguments. Expected \"<rx> <ry> <rz> <replace_node> [h[ollow]]\"." return false, "Error: Not enough arguments. Expected \"<rx> <ry> <rz> <replace_node> [h[ollow]]\"."
@ -15,7 +17,7 @@ local function parse_params_ellipsoid(params_text)
if not radius then if not radius then
return false, "Error: 3 radii must be specified." return false, "Error: 3 radii must be specified."
end end
wea.vector.abs(radius) wea_c.vector.abs(radius)
local replace_node = worldedit.normalize_nodename(parts[4]) local replace_node = worldedit.normalize_nodename(parts[4])
if not replace_node then if not replace_node then
@ -37,18 +39,19 @@ worldeditadditions_core.register_command("ellipsoid", {
require_pos = 1, require_pos = 1,
parse = function(params_text) parse = function(params_text)
local values = {parse_params_ellipsoid(params_text)} local values = {parse_params_ellipsoid(params_text)}
return wea.table.unpack(values) return wea_c.table.unpack(values)
end, end,
nodes_needed = function(name, target_node, radius) nodes_needed = function(name, target_node, radius)
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z) return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
end, end,
func = function(name, target_node, radius, hollow) func = function(name, target_node, radius, hollow)
local start_time = worldeditadditions.get_ms_time() local start_time = wea_c.get_ms_time()
local replaced = worldeditadditions.ellipsoid(worldedit.pos1[name], radius, target_node, hollow) local pos1 = Vector3.clone(worldedit.pos1[name])
local time_taken = worldeditadditions.get_ms_time() - start_time local replaced = worldeditadditions.ellipsoid(pos1, radius, target_node, hollow)
local time_taken = wea_c.get_ms_time() - start_time
minetest.log("action", name .. " used //ellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s") minetest.log("action", name.." used //ellipsoid at "..pos1..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
return true, replaced .. " nodes replaced in " .. worldeditadditions.format.human_time(time_taken) return true, replaced .. " nodes replaced in " .. wea_c.format.human_time(time_taken)
end end
}) })
@ -60,17 +63,18 @@ worldeditadditions_core.register_command("hollowellipsoid", {
require_pos = 1, require_pos = 1,
parse = function(params_text) parse = function(params_text)
local values = {parse_params_ellipsoid(params_text)} local values = {parse_params_ellipsoid(params_text)}
return wea.table.unpack(values) return wea_c.table.unpack(values)
end, end,
nodes_needed = function(name, target_node, radius) nodes_needed = function(name, target_node, radius)
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z) return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
end, end,
func = function(name, target_node, radius) func = function(name, target_node, radius)
local start_time = worldeditadditions.get_ms_time() local start_time = wea_c.get_ms_time()
local replaced = worldeditadditions.ellipsoid(worldedit.pos1[name], radius, target_node, true) local pos1 = Vector3.clone(worldedit.pos1[name])
local time_taken = worldeditadditions.get_ms_time() - start_time local replaced = worldeditadditions.ellipsoid(pos1, radius, target_node, true)
local time_taken = wea_c.get_ms_time() - start_time
minetest.log("action", name .. " used //hollowellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s") minetest.log("action", name.." used //hollowellipsoid at "..pos1..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
return true, replaced .. " nodes replaced in " .. worldeditadditions.format.human_time(time_taken) return true, replaced .. " nodes replaced in " .. wea_c.format.human_time(time_taken)
end end
}) })

View file

@ -3,7 +3,9 @@
-- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██ -- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████ -- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████
local wea_c = worldeditadditions_core
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea_c.Vector3
worldeditadditions_core.register_command("ellipsoid2", { worldeditadditions_core.register_command("ellipsoid2", {
params = "[<replace_node:dirt> [h[ollow]]]", params = "[<replace_node:dirt> [h[ollow]]]",
@ -15,7 +17,7 @@ worldeditadditions_core.register_command("ellipsoid2", {
params_text = "dirt" params_text = "dirt"
end end
local parts = wea.split_shell(params_text) local parts = wea_c.split_shell(params_text)
local replace_node = worldedit.normalize_nodename(parts[1]) local replace_node = worldedit.normalize_nodename(parts[1])
@ -31,21 +33,21 @@ worldeditadditions_core.register_command("ellipsoid2", {
return true, replace_node, hollow return true, replace_node, hollow
end, end,
nodes_needed = function(name, target_node) nodes_needed = function(name, target_node)
local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name]) local pos1, pos2 = Vector3.sort(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) return math.ceil(4/3 * math.pi * (pos2.x - pos1.x)/2 * (pos2.y - pos1.y)/2 * (pos2.z - pos1.z)/2)
end, end,
func = function(name, target_node, radius, hollow) func = function(name, target_node, radius, hollow)
local start_time = wea.get_ms_time() local start_time = wea_c.get_ms_time()
local pos1, pos2 = wea.Vector3.sort(worldedit.pos1[name], worldedit.pos2[name]) local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
local replaced = wea.ellipsoid2( local replaced = wea.ellipsoid2(
pos1, pos2, pos1, pos2,
target_node, target_node,
hollow hollow
) )
local time_taken = wea.get_ms_time() - start_time local time_taken = wea_c.get_ms_time() - start_time
minetest.log("action", name .. " used //ellipsoid2 at "..pos1.." - "..pos2..", replacing " .. replaced .. " nodes in " .. time_taken .. "s") minetest.log("action", name.." used //ellipsoid2 at "..pos1.." - "..pos2..", replacing "..replaced.." nodes in "..time_taken.."s")
return true, replaced .. " nodes replaced in " .. wea.format.human_time(time_taken) return true, replaced.." nodes replaced in "..wea_c.format.human_time(time_taken)
end end
}) })

View file

@ -1,3 +1,6 @@
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ███████ ██████ ██████ ██████ ███████ -- ███████ ██████ ██████ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██
-- █████ ██████ ██ ██ ██ ██ █████ -- █████ ██████ ██ ██ ██ ██ █████
@ -22,7 +25,7 @@ worldeditadditions_core.register_command("erode", {
return false, "Failed to split params_text into 2 parts (this is probably a bug)" return false, "Failed to split params_text into 2 parts (this is probably a bug)"
end end
local success, map = worldeditadditions.parse.map(params) local success, map = wea_c.parse.map(params)
if not success then return success, map end if not success then return success, map end
return true, algorithm, map return true, algorithm, map
end, end,
@ -30,15 +33,16 @@ worldeditadditions_core.register_command("erode", {
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
end, end,
func = function(name, algorithm, params) func = function(name, algorithm, params)
local start_time = worldeditadditions.get_ms_time() local start_time = wea_c.get_ms_time()
local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
local success, msg, stats = worldeditadditions.erode.run( local success, msg, stats = worldeditadditions.erode.run(
worldedit.pos1[name], worldedit.pos2[name], pos1, pos2,
algorithm, params algorithm, params
) )
if not success then return success, msg end if not success then return success, msg end
local time_taken = worldeditadditions.get_ms_time() - start_time local time_taken = wea_c.get_ms_time() - start_time
minetest.log("action", name .. " used //erode "..algorithm.." at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", adding " .. stats.added .. " nodes and removing " .. stats.removed .. " nodes in " .. time_taken .. "s") minetest.log("action", name.." used //erode "..algorithm.." at "..pos1.." - "..pos2..", adding "..stats.added.." nodes and removing "..stats.removed.." nodes in "..time_taken.."s")
return true, msg.."\n"..stats.added .. " nodes added and " .. stats.removed .. " nodes removed in " .. worldeditadditions.format.human_time(time_taken) return true, msg.."\n"..stats.added.." nodes added and "..stats.removed.." nodes removed in "..wea_c.format.human_time(time_taken)
end end
}) })

View file

@ -1,3 +1,6 @@
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ███████ ██ ██ ██ ██████ █████ ██ ██ ███████ ███████ -- ███████ ██ ██ ██ ██████ █████ ██ ██ ███████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- █████ ██ ██ ██ ██ ███████ ██ ██ █████ ███████ -- █████ ██ ██ ██ ██ ███████ ██ ██ █████ ███████
@ -23,14 +26,18 @@ worldeditadditions_core.register_command("fillcaves", {
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
end, end,
func = function(name, replace_node) func = function(name, replace_node)
local start_time = worldeditadditions.get_ms_time() local start_time = wea_c.get_ms_time()
local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
local success, stats = worldeditadditions.fillcaves(worldedit.pos1[name], worldedit.pos2[name], replace_node) local success, stats = worldeditadditions.fillcaves(
pos1, pos2,
replace_node
)
if not success then return success, stats end if not success then return success, stats end
local time_taken = worldeditadditions.get_ms_time() - start_time local time_taken = wea_c.get_ms_time() - start_time
minetest.log("action", name .. " used //fillcaves at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. stats.replaced .. " nodes in " .. time_taken .. "s") minetest.log("action", name .. " used //fillcaves at "..pos1.." - "..pos2..", replacing "..stats.replaced.." nodes in "..time_taken.."s")
return true, stats.replaced .. " nodes replaced in " .. worldeditadditions.format.human_time(time_taken) return true, stats.replaced.." nodes replaced in "..wea_c.format.human_time(time_taken)
end end
}) })

View file

@ -1,3 +1,6 @@
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ███████ ██ ██████ ██████ ██████ ███████ ██ ██ ██ -- ███████ ██ ██████ ██████ ██████ ███████ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- █████ ██ ██ ██ ██ ██ ██ ██ █████ ██ ██ ██ -- █████ ██ ██ ██ ██ ██ ██ ██ █████ ██ ██ ██
@ -34,15 +37,20 @@ worldeditadditions_core.register_command("floodfill", {
return math.ceil(((4 * math.pi * (tonumber(radius) ^ 3)) / 3) / 2) return math.ceil(((4 * math.pi * (tonumber(radius) ^ 3)) / 3) / 2)
end, end,
func = function(name, replace_node, radius) func = function(name, replace_node, radius)
local start_time = worldeditadditions.get_ms_time() local start_time = wea_c.get_ms_time()
local nodes_replaced = worldeditadditions.floodfill(worldedit.pos1[name], radius, replace_node) local pos1 = Vector3.clone(worldedit.pos1[name])
local time_taken = worldeditadditions.get_ms_time() - start_time local nodes_replaced = worldeditadditions.floodfill(
pos1,
radius,
replace_node
)
local time_taken = wea_c.get_ms_time() - start_time
if nodes_replaced == false then if nodes_replaced == false then
return false, "Error: The search node is the same as the replace node." return false, "Error: The search node is the same as the replace node."
end end
minetest.log("action", name .. " used //floodfill at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. nodes_replaced .. " nodes in " .. time_taken .. "s") minetest.log("action", name.." used //floodfill at "..pos1..", replacing " .. nodes_replaced.." nodes in "..time_taken.."s")
return true, nodes_replaced .. " nodes replaced in " .. worldeditadditions.format.human_time(time_taken) return true, nodes_replaced.." nodes replaced in "..wea_c.format.human_time(time_taken)
end end
}) })

View file

@ -1,4 +1,5 @@
local wea = worldeditadditions local wea_c = worldeditadditions
local Vector3 = wea_c.Vector3
-- ███████ ██████ ██████ ███████ ███████ ████████ -- ███████ ██████ ██████ ███████ ███████ ████████
-- ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██
@ -19,12 +20,12 @@ worldeditadditions_core.register_command("forest", {
params_text = params_text:sub(#match_start + 1) -- everything starts at 1 in Lua :-/ params_text = params_text:sub(#match_start + 1) -- everything starts at 1 in Lua :-/
end end
local success, sapling_list = wea.parse.weighted_nodes( local success, sapling_list = wea_c.parse.weighted_nodes(
wea.split_shell(params_text), wea_c.split_shell(params_text),
false, false,
function(name) function(name)
return worldedit.normalize_nodename( return worldedit.normalize_nodename(
wea.normalise_saplingname(name) wea_c.normalise_saplingname(name)
) )
end end
) )
@ -33,26 +34,27 @@ worldeditadditions_core.register_command("forest", {
end, end,
nodes_needed = function(name) nodes_needed = function(name)
-- //overlay only modifies up to 1 node per column in the selected region -- //overlay only modifies up to 1 node per column in the selected region
local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name]) local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
return (pos2.x - pos1.x) * (pos2.y - pos1.y) return (pos2.x - pos1.x) * (pos2.y - pos1.y)
end, end,
func = function(name, density, sapling_list) func = function(name, density, sapling_list)
local start_time = wea.get_ms_time() local start_time = wea_c.get_ms_time()
local success, stats = wea.forest( local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
worldedit.pos1[name], worldedit.pos2[name], local success, stats = worldeditadditions.forest(
pos1, pos2,
density, density,
sapling_list sapling_list
) )
if not success then return success, stats end if not success then return success, stats end
local time_taken = wea.format.human_time(wea.get_ms_time() - start_time) local time_taken = wea_c.format.human_time(wea_c.get_ms_time() - start_time)
local distribution_display = wea.format.node_distribution( local distribution_display = wea_c.format.node_distribution(
stats.placed, stats.placed,
stats.successes, stats.successes,
false -- no grand total at the bottom false -- no grand total at the bottom
) )
minetest.log("action", name.." used //forest at "..wea.vector.tostring(worldedit.pos1[name]).." - "..wea.vector.tostring(worldedit.pos2[name])..", "..stats.successes.." trees placed, averaging "..stats.attempts_avg.." growth attempts / tree and "..stats.failures.." failed attempts in "..time_taken) minetest.log("action", name.." used //forest at "..pos1.." - "..pos2..", "..stats.successes.." trees placed, averaging "..stats.attempts_avg.." growth attempts / tree and "..stats.failures.." failed attempts in "..time_taken)
return true, distribution_display.."\n=========================\n"..stats.successes.." trees placed, averaging "..stats.attempts_avg.." growth attempts / tree and "..stats.failures.." failed attempts in "..time_taken return true, distribution_display.."\n=========================\n"..stats.successes.." trees placed, averaging "..stats.attempts_avg.." growth attempts / tree and "..stats.failures.." failed attempts in "..time_taken
end end
}) })