From d560583121dcdce45fd432aa9aa287575bcc3a5f Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 11 Nov 2021 02:20:37 +0000 Subject: [PATCH] Make //copy+ a thing using the new wea.parse.axes --- worldeditadditions/init.lua | 1 + worldeditadditions/lib/copy.lua | 4 +- worldeditadditions/utils/parse/axes.lua | 2 +- worldeditadditions_commands/commands/copy.lua | 52 ++++++++++++------- worldeditadditions_commands/init.lua | 1 + 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index 7403736..babed60 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -54,6 +54,7 @@ dofile(wea.modpath.."/lib/scale_down.lua") dofile(wea.modpath.."/lib/scale.lua") dofile(wea.modpath.."/lib/spiral_square.lua") dofile(wea.modpath.."/lib/spiral_circle.lua") +dofile(wea.modpath.."/lib/copy.lua") dofile(wea.modpath.."/lib/conv/conv.lua") dofile(wea.modpath.."/lib/erode/erode.lua") dofile(wea.modpath.."/lib/noise/init.lua") diff --git a/worldeditadditions/lib/copy.lua b/worldeditadditions/lib/copy.lua index 5bac439..b0c19bf 100644 --- a/worldeditadditions/lib/copy.lua +++ b/worldeditadditions/lib/copy.lua @@ -10,7 +10,7 @@ local Vector3 = wea.Vector3 -- ██ ██ ██ ██ ██ -- ██████ ██████ ██ ██ -function worldeditadditions.count(source_pos1, source_pos2, target_pos1, target_pos2) +function worldeditadditions.copy(source_pos1, source_pos2, target_pos1, target_pos2) source_pos1, source_pos2 = Vector3.sort(source_pos1, source_pos2) target_pos1, target_pos2 = Vector3.sort(target_pos1, target_pos2) @@ -25,7 +25,7 @@ function worldeditadditions.count(source_pos1, source_pos2, target_pos1, target_ local manip_target, area_target = worldedit.manip_helpers.init(target_pos1, target_pos2) local data_target = manip_target:get_data() - -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) + -- z y x is the preferred loop order (because CPU cache, since then we're iterating linearly through the data array backwards. This only holds true for little-endian machines however) for z = source_pos2.z, source_pos1.z, -1 do for y = source_pos2.y, source_pos1.y, -1 do diff --git a/worldeditadditions/utils/parse/axes.lua b/worldeditadditions/utils/parse/axes.lua index e7144cc..a297462 100644 --- a/worldeditadditions/utils/parse/axes.lua +++ b/worldeditadditions/utils/parse/axes.lua @@ -112,7 +112,7 @@ local function parse_axes(token_list, facing_dir) return false, "Error: Expected list of tokens as a table, but found value of type '"..type(token_list).."' instead." end if type(facing_dir) ~= "table" then - return false, "Error: Expected facing_dir to be a table, but found value of type '"..type(token_list).."' instead." + return false, "Error: Expected facing_dir to be a table, but found value of type '"..type(facing_dir).."' instead." end local vpos1, vpos2 = Vector3.new(), Vector3.new() diff --git a/worldeditadditions_commands/commands/copy.lua b/worldeditadditions_commands/commands/copy.lua index 4a0e1e3..5a832f2 100644 --- a/worldeditadditions_commands/commands/copy.lua +++ b/worldeditadditions_commands/commands/copy.lua @@ -1,12 +1,32 @@ local wea = worldeditadditions +local Vector3 = wea.Vector3 + +local function parse_stage2(name, parts) + local success, vpos1, vpos2 = wea.parse.axes( + parts, + wea.player_dir(name) + ) + + if not success then return success, vpos1 end + + -- In this case, we aren't interested in keeping the multidirectional shape changing information insomuch as an offset to which we should shift the region's contents to. + local offset = vpos1 + vpos2 + + if offset == Vector3.new() then + return false, "Refusing to copy region a distance of 0 nodes" + end + + return true, offset:floor() +end + -- ██████ ██████ ██████ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██████ ████ -- ██ ██ ██ ██ ██ -- ██████ ██████ ██ ██ -worldedit.register_command("copy", { -- TODO: Make this an override - params = " [ [...]]", - description = "Copies the defined region to another location - potentially on multiple axes at once.", +worldedit.register_command("copy+", { -- TODO: Make this an override + params = " [mirror|mir] [ [mirror|mir] [...]]", + description = "Copies the defined region to another location - potentially across multiple axes at once.", privs = { worldedit = true }, require_pos = 2, parse = function(params_text) @@ -14,32 +34,28 @@ worldedit.register_command("copy", { -- TODO: Make this an override local parts = wea.split_shell(params_text) - local copy_offset = wea.parse.axes(parts) - - if copy_offset == wea.Vector3.new() then - return false, "Refusing to copy region a distance of 0 nodes" - end - - return true, copy_offset:floor() + return true, parts 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, copy_offset) + func = function(name, parts) local start_time = wea.get_ms_time() - local source_pos1 = wea.Vector3.clone(worldedit.pos1[name]) - local source_pos2 = wea.Vector3.clone(worldedit.pos2[name]) + local success_a, copy_offset = parse_stage2(name, parts) + if not success_a then return success_a, copy_offset end - local target_pos1 = source_pos1:add(copy_offset) - local target_pos2 = source_pos2:add(copy_offset) + local source_pos1 = Vector3.clone(worldedit.pos1[name]) + local source_pos2 = Vector3.clone(worldedit.pos2[name]) - local success, nodes_modified = wea.copy( + local target_pos1 = source_pos1 + copy_offset + local target_pos2 = source_pos2 + copy_offset + + local success_b, nodes_modified = wea.copy( source_pos1, source_pos2, target_pos1, target_pos2 ) + if not success_b then return success_b, nodes_modified end local time_taken = wea.get_ms_time() - start_time diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index c639dd2..25e3c72 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -36,6 +36,7 @@ dofile(we_c.modpath.."/commands/scale.lua") dofile(we_c.modpath.."/commands/torus.lua") dofile(we_c.modpath.."/commands/walls.lua") dofile(we_c.modpath.."/commands/spiral2.lua") +dofile(we_c.modpath.."/commands/copy.lua") dofile(we_c.modpath.."/commands/count.lua")