function worldedit.move(pos1, pos2, axis, amount)\r
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
\r
+ local dim = vector.add(vector.subtract(pos2, pos1), 1)\r
+ if math.abs(amount) < dim[axis] then\r
+ -- Source and destination region are overlapping\r
+ -- FIXME: I can't be bothered, so just defer to the legacy code for now.\r
+ return worldedit.legacy_move(pos1, pos2, axis, amount)\r
+ end\r
+\r
+ -- Copy stuff to new location\r
+ local off = {x=0, y=0, z=0}\r
+ off[axis] = amount\r
+ worldedit.copy2(pos1, pos2, off)\r
+ -- Nuke old area\r
+ worldedit.set(pos1, pos2, "air")\r
+\r
+ return worldedit.volume(pos1, pos2)\r
+end\r
+\r
+-- This function is not offical part of the API and may be removed at any time.\r
+function worldedit.legacy_move(pos1, pos2, axis, amount)\r
+ local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+\r
worldedit.keep_loaded(pos1, pos2)\r
\r
- --- TODO: Move slice by slice using schematic method in the move axis\r
- -- and transfer metadata in separate loop (and if the amount is\r
- -- greater than the length in the axis, copy whole thing at a time and\r
- -- erase original after, using schematic method).\r
local get_node, get_meta, set_node, remove_node = minetest.get_node,\r
minetest.get_meta, minetest.set_node, minetest.remove_node\r
-- Copy things backwards when negative to avoid corruption.\r
- --- FIXME: Lots of code duplication here.\r
if amount < 0 then\r
local pos = {}\r
pos.x = pos1.x\r