Skip to content
Permalink
Browse files
Fix //stack2 not working (closes #94)
  • Loading branch information
sfan5 committed Jan 5, 2016
1 parent 7a19c53 commit e0a26617002564db0c3d06f4f9e6d509b55b106c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
@@ -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.
@@ -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.

0 comments on commit e0a2661

Please sign in to comment.