mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
Make //copy+ a thing using the new wea.parse.axes
This commit is contained in:
parent
9729e82e35
commit
d560583121
5 changed files with 39 additions and 21 deletions
|
@ -54,6 +54,7 @@ dofile(wea.modpath.."/lib/scale_down.lua")
|
||||||
dofile(wea.modpath.."/lib/scale.lua")
|
dofile(wea.modpath.."/lib/scale.lua")
|
||||||
dofile(wea.modpath.."/lib/spiral_square.lua")
|
dofile(wea.modpath.."/lib/spiral_square.lua")
|
||||||
dofile(wea.modpath.."/lib/spiral_circle.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/conv/conv.lua")
|
||||||
dofile(wea.modpath.."/lib/erode/erode.lua")
|
dofile(wea.modpath.."/lib/erode/erode.lua")
|
||||||
dofile(wea.modpath.."/lib/noise/init.lua")
|
dofile(wea.modpath.."/lib/noise/init.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)
|
source_pos1, source_pos2 = Vector3.sort(source_pos1, source_pos2)
|
||||||
target_pos1, target_pos2 = Vector3.sort(target_pos1, target_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 manip_target, area_target = worldedit.manip_helpers.init(target_pos1, target_pos2)
|
||||||
local data_target = manip_target:get_data()
|
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 z = source_pos2.z, source_pos1.z, -1 do
|
||||||
for y = source_pos2.y, source_pos1.y, -1 do
|
for y = source_pos2.y, source_pos1.y, -1 do
|
||||||
|
|
|
@ -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."
|
return false, "Error: Expected list of tokens as a table, but found value of type '"..type(token_list).."' instead."
|
||||||
end
|
end
|
||||||
if type(facing_dir) ~= "table" then
|
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
|
end
|
||||||
|
|
||||||
local vpos1, vpos2 = Vector3.new(), Vector3.new()
|
local vpos1, vpos2 = Vector3.new(), Vector3.new()
|
||||||
|
|
|
@ -1,12 +1,32 @@
|
||||||
local wea = worldeditadditions
|
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
|
worldedit.register_command("copy+", { -- TODO: Make this an override
|
||||||
params = "<axis:x|y|z|-x|-y|-z|?|front|back|left|right|up|down> <count> [<axis> <count> [...]]",
|
params = "<axis:x|y|z|-x|-y|-z|?|front|back|left|right|up|down> <count> [mirror|mir] [<axis> <count> [mirror|mir] [...]]",
|
||||||
description = "Copies the defined region to another location - potentially on multiple axes at once.",
|
description = "Copies the defined region to another location - potentially across multiple axes at once.",
|
||||||
privs = { worldedit = true },
|
privs = { worldedit = true },
|
||||||
require_pos = 2,
|
require_pos = 2,
|
||||||
parse = function(params_text)
|
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 parts = wea.split_shell(params_text)
|
||||||
|
|
||||||
local copy_offset = wea.parse.axes(parts)
|
return true, 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()
|
|
||||||
end,
|
end,
|
||||||
nodes_needed = function(name)
|
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])
|
return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
|
||||||
end,
|
end,
|
||||||
func = function(name, copy_offset)
|
func = function(name, parts)
|
||||||
local start_time = wea.get_ms_time()
|
local start_time = wea.get_ms_time()
|
||||||
|
|
||||||
local source_pos1 = wea.Vector3.clone(worldedit.pos1[name])
|
local success_a, copy_offset = parse_stage2(name, parts)
|
||||||
local source_pos2 = wea.Vector3.clone(worldedit.pos2[name])
|
if not success_a then return success_a, copy_offset end
|
||||||
|
|
||||||
local target_pos1 = source_pos1:add(copy_offset)
|
local source_pos1 = Vector3.clone(worldedit.pos1[name])
|
||||||
local target_pos2 = source_pos2:add(copy_offset)
|
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,
|
source_pos1, source_pos2,
|
||||||
target_pos1, target_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
|
local time_taken = wea.get_ms_time() - start_time
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ dofile(we_c.modpath.."/commands/scale.lua")
|
||||||
dofile(we_c.modpath.."/commands/torus.lua")
|
dofile(we_c.modpath.."/commands/torus.lua")
|
||||||
dofile(we_c.modpath.."/commands/walls.lua")
|
dofile(we_c.modpath.."/commands/walls.lua")
|
||||||
dofile(we_c.modpath.."/commands/spiral2.lua")
|
dofile(we_c.modpath.."/commands/spiral2.lua")
|
||||||
|
dofile(we_c.modpath.."/commands/copy.lua")
|
||||||
|
|
||||||
dofile(we_c.modpath.."/commands/count.lua")
|
dofile(we_c.modpath.."/commands/count.lua")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue