1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2024-11-13 06:00:19 +01:00

Fix //stack2 not working (closes #94)

This commit is contained in:
sfan5 2016-01-05 13:57:48 +01:00
parent 7a19c5303b
commit e0a2661700
2 changed files with 39 additions and 1 deletions

View File

@ -45,6 +45,12 @@ Copies the region defined by positions `pos1` and `pos2` along the `axis` axis (
Returns the number of nodes copied.
### count = worldedit.copy2(pos1, pos2, off)
Copies the region defined by positions `pos1` and `pos2` by the offset vector `off`.
Returns the number of nodes copied.
### count = worldedit.move(pos1, pos2, axis, amount)
Moves the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.

View File

@ -90,7 +90,7 @@ function worldedit.stack2(pos1, pos2, direction, amount, finished)
translated.x = translated.x + direction.x
translated.y = translated.y + direction.y
translated.z = translated.z + direction.z
worldedit.copy2(pos1, pos2, translated, volume)
worldedit.copy2(pos1, pos2, translated)
minetest.after(0, next_one)
else
if finished then
@ -164,6 +164,38 @@ function worldedit.copy(pos1, pos2, axis, amount)
return worldedit.volume(pos1, pos2)
end
--- Copies a region by offset vector `off`.
-- @param pos1
-- @param pos2
-- @param off
-- @return The number of nodes copied.
function worldedit.copy2(pos1, pos2, off)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
worldedit.keep_loaded(pos1, pos2)
local get_node, get_meta, set_node = minetest.get_node,
minetest.get_meta, minetest.set_node
local pos = {}
pos.x = pos2.x
while pos.x >= pos1.x do
pos.y = pos2.y
while pos.y >= pos1.y do
pos.z = pos2.z
while pos.z >= pos1.z do
local node = get_node(pos) -- Obtain current node
local meta = get_meta(pos):to_table() -- Get meta of current node
local newpos = vector.add(pos, off) -- Calculate new position
set_node(newpos, node) -- Copy node to new position
get_meta(newpos):from_table(meta) -- Set metadata of new node
pos.z = pos.z - 1
end
pos.y = pos.y - 1
end
pos.x = pos.x - 1
end
return worldedit.volume(pos1, pos2)
end
--- Moves a region along `axis` by `amount` nodes.
-- @return The number of nodes moved.