mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2025-01-11 18:40:28 +01:00
Use faster vmanip copying for //move too
This commit is contained in:
parent
a0181ea897
commit
b4826aa821
@ -271,81 +271,44 @@ function worldedit.move(pos1, pos2, axis, amount)
|
|||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
local dim = vector.add(vector.subtract(pos2, pos1), 1)
|
local dim = vector.add(vector.subtract(pos2, pos1), 1)
|
||||||
if math.abs(amount) < dim[axis] then
|
local overlap = math.abs(amount) < dim[axis]
|
||||||
-- Source and destination region are overlapping
|
-- Decide if we need to copy metadata backwards
|
||||||
-- FIXME: I can't be bothered, so just defer to the legacy code for now.
|
local backwards = overlap and amount > 0
|
||||||
return worldedit.legacy_move(pos1, pos2, axis, amount)
|
|
||||||
|
local function nuke_area(my_off, my_dim)
|
||||||
|
if my_dim.x == 0 or my_dim.y == 0 or my_dim.z == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local my_pos1 = vector.add(pos1, my_off)
|
||||||
|
local my_pos2 = vector.subtract(vector.add(my_pos1, my_dim), 1)
|
||||||
|
worldedit.set(my_pos1, my_pos2, "air")
|
||||||
|
worldedit.delete_meta(my_pos1, my_pos2)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Copy stuff to new location
|
-- Copy stuff to new location
|
||||||
local off = {x=0, y=0, z=0}
|
local off = {x=0, y=0, z=0}
|
||||||
off[axis] = amount
|
off[axis] = amount
|
||||||
worldedit.copy2(pos1, pos2, off)
|
worldedit.copy2(pos1, pos2, off, backwards)
|
||||||
-- Nuke old area
|
-- Nuke old area
|
||||||
worldedit.set(pos1, pos2, "air")
|
if not overlap then
|
||||||
worldedit.delete_meta(pos1, pos2)
|
nuke_area({x=0, y=0, z=0}, dim)
|
||||||
|
|
||||||
return worldedit.volume(pos1, pos2)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- This function is not offical part of the API and may be removed at any time.
|
|
||||||
function worldedit.legacy_move(pos1, pos2, axis, amount)
|
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
|
||||||
|
|
||||||
worldedit.keep_loaded(pos1, pos2)
|
|
||||||
|
|
||||||
local get_node, get_meta, set_node, remove_node = minetest.get_node,
|
|
||||||
minetest.get_meta, minetest.set_node, minetest.remove_node
|
|
||||||
-- Copy things backwards when negative to avoid corruption.
|
|
||||||
if amount < 0 then
|
|
||||||
local pos = {}
|
|
||||||
pos.x = pos1.x
|
|
||||||
while pos.x <= pos2.x do
|
|
||||||
pos.y = pos1.y
|
|
||||||
while pos.y <= pos2.y do
|
|
||||||
pos.z = pos1.z
|
|
||||||
while pos.z <= pos2.z do
|
|
||||||
local node = get_node(pos) -- Obtain current node
|
|
||||||
local meta = get_meta(pos):to_table() -- Get metadata of current node
|
|
||||||
remove_node(pos) -- Remove current node
|
|
||||||
local value = pos[axis] -- Store current position
|
|
||||||
pos[axis] = value + amount -- Move along axis
|
|
||||||
set_node(pos, node) -- Move node to new position
|
|
||||||
get_meta(pos):from_table(meta) -- Set metadata of new node
|
|
||||||
pos[axis] = value -- Restore old position
|
|
||||||
pos.z = pos.z + 1
|
|
||||||
end
|
|
||||||
pos.y = pos.y + 1
|
|
||||||
end
|
|
||||||
pos.x = pos.x + 1
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
local pos = {}
|
-- Source and destination region are overlapping, which means we can't
|
||||||
pos.x = pos2.x
|
-- blindly delete the [pos1, pos2] area
|
||||||
while pos.x >= pos1.x do
|
local leftover = vector.new(dim) -- size of the leftover slice
|
||||||
pos.y = pos2.y
|
leftover[axis] = math.abs(amount)
|
||||||
while pos.y >= pos1.y do
|
if amount > 0 then
|
||||||
pos.z = pos2.z
|
nuke_area({x=0, y=0, z=0}, leftover)
|
||||||
while pos.z >= pos1.z do
|
else
|
||||||
local node = get_node(pos) -- Obtain current node
|
local top = {x=0, y=0, z=0} -- offset of the leftover slice from pos1
|
||||||
local meta = get_meta(pos):to_table() -- Get metadata of current node
|
top[axis] = dim[axis] - 1
|
||||||
remove_node(pos) -- Remove current node
|
nuke_area(top, leftover)
|
||||||
local value = pos[axis] -- Store current position
|
|
||||||
pos[axis] = value + amount -- Move along axis
|
|
||||||
set_node(pos, node) -- Move node to new position
|
|
||||||
get_meta(pos):from_table(meta) -- Set metadata of new node
|
|
||||||
pos[axis] = value -- Restore old position
|
|
||||||
pos.z = pos.z - 1
|
|
||||||
end
|
|
||||||
pos.y = pos.y - 1
|
|
||||||
end
|
|
||||||
pos.x = pos.x - 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return worldedit.volume(pos1, pos2)
|
return worldedit.volume(pos1, pos2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Duplicates a region along `axis` `amount` times.
|
--- Duplicates a region along `axis` `amount` times.
|
||||||
-- Stacking is spread across server steps.
|
-- Stacking is spread across server steps.
|
||||||
-- @param pos1
|
-- @param pos1
|
||||||
|
Loading…
Reference in New Issue
Block a user