From 8d6db6d3f59d49a7e46cf686ac7a5a413f9a28f4 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Sun, 18 Sep 2022 20:58:28 +0100
Subject: [PATCH] upgrade 7 more commands

---
 worldeditadditions/lib/line.lua               |  2 ++
 .../commands/layers.lua                       |  2 ++
 worldeditadditions_commands/commands/line.lua | 21 +++++++++---
 worldeditadditions_commands/commands/maze.lua | 32 +++++++++++--------
 .../commands/metaball.lua                     | 11 ++++---
 worldeditadditions_commands/commands/move.lua | 17 +++++-----
 .../commands/noise2d.lua                      | 25 ++++++++-------
 7 files changed, 68 insertions(+), 42 deletions(-)

diff --git a/worldeditadditions/lib/line.lua b/worldeditadditions/lib/line.lua
index 4fc7a89..140bb58 100644
--- a/worldeditadditions/lib/line.lua
+++ b/worldeditadditions/lib/line.lua
@@ -6,6 +6,8 @@
 -- ██      ██ ██ ██  ██ █████
 -- ██      ██ ██  ██ ██ ██
 -- ███████ ██ ██   ████ ███████
+
+
 function worldeditadditions.line(pos1, pos2, thickness, node_name)
 	local pos1_sorted, pos2_sorted = worldedit.sort_pos(pos1, pos2)
 	-- pos2 will always have the highest co-ordinates now
diff --git a/worldeditadditions_commands/commands/layers.lua b/worldeditadditions_commands/commands/layers.lua
index dfcfa54..ba20a83 100644
--- a/worldeditadditions_commands/commands/layers.lua
+++ b/worldeditadditions_commands/commands/layers.lua
@@ -1,3 +1,5 @@
+local wea_c = worldeditadditions_core
+
 local function parse_slope_range(text)
 	if string.match(text, "%.%.") then
 		-- It's in the form a..b
diff --git a/worldeditadditions_commands/commands/line.lua b/worldeditadditions_commands/commands/line.lua
index 0c75cf0..e38e356 100644
--- a/worldeditadditions_commands/commands/line.lua
+++ b/worldeditadditions_commands/commands/line.lua
@@ -1,3 +1,6 @@
+local wea_c = worldeditadditions_core
+local Vector3 = wea_c.Vector3
+
 -- ██      ██ ███    ██ ███████
 -- ██      ██ ████   ██ ██
 -- ██      ██ ██ ██  ██ █████
@@ -39,13 +42,21 @@ worldeditadditions_core.register_command("line", {
 			)) -- Volume of a cylinder
 	end,
 	func = function(name, replace_node, radius)
-		local start_time = worldeditadditions.get_ms_time()
-		local success, stats = worldeditadditions.line(worldedit.pos1[name], worldedit.pos2[name], radius, replace_node)
-		local time_taken = worldeditadditions.get_ms_time() - start_time
+		local start_time = wea_c.get_ms_time()
+		-- Can't  sort here because the start & ending points matter
+		local pos1 = Vector3.clone(worldedit.pos1[name])
+		local pos2 = Vector3.clone(worldedit.pos2[name])
+		
+		local success, stats = worldeditadditions.line(
+			pos1, pos2,
+			radius,
+			replace_node
+		)
+		local time_taken = wea_c.get_ms_time() - start_time
 		
 		if success == false then return false, stats end
 		
-		minetest.log("action", name .. " used //line at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. stats.replaced .. " nodes in " .. time_taken .. "s")
-		return true, stats.replaced .. " nodes replaced in " .. worldeditadditions.format.human_time(time_taken)
+		minetest.log("action", name.." used //line from "..pos1.." to "..pos2..", replacing "..stats.replaced.." nodes in "..time_taken.."s")
+		return true, stats.replaced.." nodes replaced in "..wea_c.format.human_time(time_taken)
 	end
 })
diff --git a/worldeditadditions_commands/commands/maze.lua b/worldeditadditions_commands/commands/maze.lua
index c543474..08ffad4 100644
--- a/worldeditadditions_commands/commands/maze.lua
+++ b/worldeditadditions_commands/commands/maze.lua
@@ -1,15 +1,15 @@
 local wea = worldeditadditions
 local wea_c = worldeditadditions_core
-local Vector3 = worldeditadditions.Vector3
+local Vector3 = wea.Vector3
 
 local function parse_params_maze(params_text, is_3d)
 	if not params_text then params_text = "" end
-	params_text = wea.trim(params_text)
+	params_text = wea_c.trim(params_text)
 	if #params_text == 0 then
 		return false, "No arguments specified"
 	end
 	
-	local parts = worldeditadditions.split_shell(params_text)
+	local parts = wea_c.split_shell(params_text)
 	
 	local replace_node = parts[1]
 	local seed = os.time() * math.random()
@@ -31,7 +31,7 @@ local function parse_params_maze(params_text, is_3d)
 		path_depth = tonumber(parts[4])
 	end
 	if #parts >= param_index_seed then
-		seed = worldeditadditions.parse.seed(parts[param_index_seed])
+		seed = wea_c.parse.seed(parts[param_index_seed])
 	end
 	
 	replace_node = worldedit.normalize_nodename(replace_node)
@@ -75,7 +75,7 @@ wea_c.register_command("maze", {
 		return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
 	end,
 	func = function(name, replace_node, seed, path_length, path_width)
-		local start_time = wea.get_ms_time()
+		local start_time = wea_c.get_ms_time()
 		
 		local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
 		local replaced = wea.maze2d(
@@ -85,10 +85,10 @@ wea_c.register_command("maze", {
 			path_length, path_width
 		)
 		
-		local time_taken = wea.get_ms_time() - start_time
+		local time_taken = wea_c.get_ms_time() - start_time
 		
 		minetest.log("action", name.." used //maze 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
 })
 
@@ -107,18 +107,24 @@ wea_c.register_command("maze3d", {
 	require_pos = 2,
 	parse = function(params_text)
 		local values = {parse_params_maze(params_text, true)}
-		return worldeditadditions.table.unpack(values)
+		return wea_c.table.unpack(values)
 	end,
 	nodes_needed = function(name)
 		return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
 	end,
 	func = function(name, replace_node, seed, path_length, path_width, path_depth)
-		local start_time = worldeditadditions.get_ms_time()
-		local replaced = worldeditadditions.maze3d(worldedit.pos1[name], worldedit.pos2[name], replace_node, seed, path_length, path_width, path_depth)
-		local time_taken = worldeditadditions.get_ms_time() - start_time
+		local start_time = wea_c.get_ms_time()
+		local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
+		local replaced = wea_c.maze3d(
+			pos1, pos2,
+			replace_node,
+			seed,
+			path_length, path_width, path_depth
+		)
+		local time_taken = wea_c.get_ms_time() - start_time
 		
 		
-		minetest.log("action", name.." used //maze3d at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", replacing "..replaced.." nodes in "..time_taken.."s")
-		return true, replaced.." nodes replaced in "..worldeditadditions.format.human_time(time_taken)
+		minetest.log("action", name.." used //maze3d at "..pos1.." - "..pos2..", replacing "..replaced.." nodes in "..time_taken.."s")
+		return true, replaced.." nodes replaced in "..wea_c.format.human_time(time_taken)
 	end
 })
diff --git a/worldeditadditions_commands/commands/metaball.lua b/worldeditadditions_commands/commands/metaball.lua
index 312617e..46fb15b 100644
--- a/worldeditadditions_commands/commands/metaball.lua
+++ b/worldeditadditions_commands/commands/metaball.lua
@@ -1,4 +1,5 @@
 local wea = worldeditadditions
+local wea_c = worldeditadditions_core
 local Vector3 = wea.Vector3
 
 -- ██████   ██████  ███    ███ ███████
@@ -14,7 +15,7 @@ worldeditadditions_core.register_command("metaball", {
 	parse = function(params_text)
 		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 < 1 then
 			return false, "Error: Not enough arguments (see /help /dome for usage information)."
@@ -88,7 +89,7 @@ worldeditadditions_core.register_command("metaball", {
 		end
 	end,
 	func = function(name, subcommand, subargs)
-		local start_time = wea.get_ms_time()
+		local start_time = wea_c.get_ms_time()
 		local message = ""
 		local append_time = false
 		if subcommand == "list" then
@@ -142,14 +143,14 @@ worldeditadditions_core.register_command("metaball", {
 			append_time = true
 		end
 		
-		local time_taken = wea.get_ms_time() - start_time
+		local time_taken = wea_c.get_ms_time() - start_time
 		
 		
 		if append_time then
-			message = message.." in "..wea.format.human_time(time_taken)
+			message = message.." in "..wea_c.format.human_time(time_taken)
 		end
 		
-		minetest.log("action", name.." used //metaballs "..subcommand.." in "..wea.format.human_time(time_taken))
+		minetest.log("action", name.." used //metaballs "..subcommand.." in "..wea_c.format.human_time(time_taken))
 		return true, message
 	end
 })
diff --git a/worldeditadditions_commands/commands/move.lua b/worldeditadditions_commands/commands/move.lua
index 6e7f5cc..54320f0 100644
--- a/worldeditadditions_commands/commands/move.lua
+++ b/worldeditadditions_commands/commands/move.lua
@@ -1,10 +1,11 @@
 local wea = worldeditadditions
-local Vector3 = wea.Vector3
+local wea_c = worldeditadditions_core
+local Vector3 = wea_c.Vector3
 
 local function parse_stage2(name, parts)
-	local success, vpos1, vpos2 = wea.parse.axes(
+	local success, vpos1, vpos2 = wea_c.parse.axes(
 		parts,
-		wea.player_dir(name)
+		wea_c.player_dir(name)
 	)
 	
 	if not success then return success, vpos1 end
@@ -32,7 +33,7 @@ worldeditadditions_core.register_command("move+", { -- TODO: Make this an overri
 	parse = function(params_text)
 		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
 	end,
@@ -40,7 +41,7 @@ worldeditadditions_core.register_command("move+", { -- TODO: Make this an overri
 		return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
 	end,
 	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)
 		if not success_a then return success_a, copy_offset end
@@ -67,10 +68,10 @@ worldeditadditions_core.register_command("move+", { -- TODO: Make this an overri
 		worldedit.pos2[name] = target_pos2
 		worldedit.marker_update(name)
 		
-		local time_taken = wea.get_ms_time() - start_time
+		local time_taken = wea_c.get_ms_time() - start_time
 		
 		
-		minetest.log("action", name.." used //move+ from "..source_pos1.." - "..source_pos2.." to "..target_pos1.." - "..target_pos2..", modifying "..nodes_modified.." nodes in "..wea.format.human_time(time_taken))
-		return true, nodes_modified.." nodes moved using offset "..copy_offset.." in "..wea.format.human_time(time_taken)
+		minetest.log("action", name.." used //move+ 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 moved using offset "..copy_offset.." in "..wea_c.format.human_time(time_taken)
 	end
 })
diff --git a/worldeditadditions_commands/commands/noise2d.lua b/worldeditadditions_commands/commands/noise2d.lua
index 19f18a4..9ff598e 100644
--- a/worldeditadditions_commands/commands/noise2d.lua
+++ b/worldeditadditions_commands/commands/noise2d.lua
@@ -1,5 +1,7 @@
 
 local wea = worldeditadditions
+local wea_c = worldeditadditions_core
+local Vector3 = wea_c.Vector3
 
 worldeditadditions_core.register_command("noise2d", {
 	params = "[<key_1> [<value_1>]] [<key_2> [<value_2>]] ...]",
@@ -8,28 +10,28 @@ worldeditadditions_core.register_command("noise2d", {
 	require_pos = 2,
 	parse = function(params_text)
 		if not params_text then return true, {} end
-		params_text = wea.trim(params_text)
+		params_text = wea_c.trim(params_text)
 		if params_text == "" then return true, {} end
 		
 		
-		local success, map = worldeditadditions.parse.map(params_text,
+		local success, map = wea_c.parse.map(params_text,
 			wea.noise.engines.available) -- Keywords
 		if not success then return success, map end
 		
 		if map.scale then
 			map.scale = tonumber(map.scale)
-			map.scale = wea.Vector3.new(map.scale, map.scale, map.scale)
+			map.scale = Vector3.new(map.scale, map.scale, map.scale)
 		elseif map.scalex or map.scaley or map.scalez then
 			map.scalex = tonumber(map.scalex) or 1
 			map.scaley = tonumber(map.scaley) or 1
 			map.scalez = tonumber(map.scalez) or 1
-			map.scale = wea.Vector3.new(map.scalex, map.scaley, map.scalez)
+			map.scale = Vector3.new(map.scalex, map.scaley, map.scalez)
 		end
 		if map.offsetx or map.offsety or map.offsetz then
 			map.offsetx = tonumber(map.offsetx) or 0
 			map.offsety = tonumber(map.offsety) or 0
 			map.offsetz = tonumber(map.offsetz) or 0
-			map.offset = wea.Vector3.new(map.offsetx, map.offsety, map.offsetz)
+			map.offset = Vector3.new(map.offsetx, map.offsety, map.offsetz)
 		end
 		
 		return true, map
@@ -38,15 +40,16 @@ worldeditadditions_core.register_command("noise2d", {
 		return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
 	end,
 	func = function(name, params)
-		local start_time = worldeditadditions.get_ms_time()
-		local success, stats = worldeditadditions.noise.run2d(
-			worldedit.pos1[name], worldedit.pos2[name],
+		local start_time = wea_c.get_ms_time()
+		local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
+		local success, stats = wea.noise.run2d(
+			pos1, pos2,
 			params
 		)
 		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 //noise2d at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", adding " .. stats.added .. " nodes and removing " .. stats.removed .. " nodes in " .. time_taken .. "s")
-		return true, stats.added .. " nodes added and " .. stats.removed .. " nodes removed in " .. worldeditadditions.format.human_time(time_taken)
+		minetest.log("action", name .. " used //noise2d at " .. pos1 .. " - "..pos2..", adding " .. stats.added .. " nodes and removing " .. stats.removed .. " nodes in " .. wea_c.format.human_time(time_taken))
+		return true, stats.added .. " nodes added and " .. stats.removed .. " nodes removed in " .. wea_c.format.human_time(time_taken)
 	end
 })
