2021-11-13 13:36:10 +01:00
local wea = worldeditadditions
2022-09-18 21:58:28 +02:00
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
2021-11-13 13:36:10 +01:00
local function parse_stage2 ( name , parts )
2023-07-02 02:52:25 +02:00
local do_airapply = false
if parts [ # parts ] == " aa " or parts [ # parts ] == " airapply " then
do_airapply = true
table.remove ( parts , # parts )
end
2022-09-18 21:58:28 +02:00
local success , vpos1 , vpos2 = wea_c.parse . axes (
2021-11-13 13:36:10 +01:00
parts ,
2022-09-18 21:58:28 +02:00
wea_c.player_dir ( name )
2021-11-13 13:36:10 +01:00
)
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 move region a distance of 0 nodes "
end
2023-07-02 02:52:25 +02:00
return true , offset : floor ( ) , do_airapply
2021-11-13 13:36:10 +01:00
end
-- ███ ███ ██████ ██ ██ ███████
-- ████ ████ ██ ██ ██ ██ ██
-- ██ ████ ██ ██ ██ ██ ██ █████
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██████ ████ ███████
2022-05-19 23:10:09 +02:00
worldeditadditions_core.register_command ( " move+ " , { -- TODO: Make this an override
2023-07-02 02:52:25 +02:00
params = " <axis:x|y|z|-x|-y|-z|?|front|back|left|right|up|down> <count> [<axis> <count> [...]] [aa|airapply] " ,
2021-11-13 13:36:10 +01:00
description = " Moves the defined region to another location - potentially across multiple axes at once. " ,
privs = { worldedit = true } ,
require_pos = 2 ,
parse = function ( params_text )
if not params_text then params_text = " " end
2022-09-18 21:58:28 +02:00
local parts = wea_c.split_shell ( params_text )
2021-11-13 13:36:10 +01:00
return true , parts
end ,
nodes_needed = function ( name )
return worldedit.volume ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
end ,
func = function ( name , parts )
2022-09-18 21:58:28 +02:00
local start_time = wea_c.get_ms_time ( )
2021-11-13 13:36:10 +01:00
2023-07-02 02:52:25 +02:00
local success_a , copy_offset , do_airapply = parse_stage2 ( name , parts )
2021-11-13 13:36:10 +01:00
if not success_a then return success_a , copy_offset end
2021-11-13 13:41:00 +01:00
--- 1: Calculate the source & target regions
-----------------------------------------------------------------------
2021-11-13 13:36:10 +01:00
local source_pos1 = Vector3.clone ( worldedit.pos1 [ name ] )
local source_pos2 = Vector3.clone ( worldedit.pos2 [ name ] )
local target_pos1 = source_pos1 + copy_offset
local target_pos2 = source_pos2 + copy_offset
2021-11-13 13:41:00 +01:00
-- 2: Move the nodes
-----------------------------------------------------------------------
2021-11-13 13:36:10 +01:00
local success_b , nodes_modified = wea.move (
source_pos1 , source_pos2 ,
2023-07-02 02:52:25 +02:00
target_pos1 , target_pos2 ,
do_airapply
2021-11-13 13:36:10 +01:00
)
if not success_b then return success_b , nodes_modified end
2021-11-13 13:41:00 +01:00
-- 3: Update the defined region
-----------------------------------------------------------------------
2023-07-02 02:52:25 +02:00
wea_c.pos . set1 ( name , target_pos1 )
wea_c.pos . set2 ( name , target_pos2 )
-- worldedit.pos1[name] = target_pos1
-- worldedit.pos2[name] = target_pos2
-- worldedit.marker_update(name)
2021-11-13 13:41:00 +01:00
2022-09-18 21:58:28 +02:00
local time_taken = wea_c.get_ms_time ( ) - start_time
2021-11-13 13:36:10 +01:00
2022-09-18 21:58:28 +02:00
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 )
2021-11-13 13:36:10 +01:00
end
} )