Skip to content

Commit e0a2661

Browse files
committed
Fix //stack2 not working (closes #94)
1 parent 7a19c53 commit e0a2661

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

WorldEdit API.md

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Copies the region defined by positions `pos1` and `pos2` along the `axis` axis (
4545

4646
Returns the number of nodes copied.
4747

48+
### count = worldedit.copy2(pos1, pos2, off)
49+
50+
Copies the region defined by positions `pos1` and `pos2` by the offset vector `off`.
51+
52+
Returns the number of nodes copied.
53+
4854
### count = worldedit.move(pos1, pos2, axis, amount)
4955

5056
Moves the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.

worldedit/manipulations.lua

+33-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function worldedit.stack2(pos1, pos2, direction, amount, finished)
9090
translated.x = translated.x + direction.x
9191
translated.y = translated.y + direction.y
9292
translated.z = translated.z + direction.z
93-
worldedit.copy2(pos1, pos2, translated, volume)
93+
worldedit.copy2(pos1, pos2, translated)
9494
minetest.after(0, next_one)
9595
else
9696
if finished then
@@ -164,6 +164,38 @@ function worldedit.copy(pos1, pos2, axis, amount)
164164
return worldedit.volume(pos1, pos2)
165165
end
166166

167+
--- Copies a region by offset vector `off`.
168+
-- @param pos1
169+
-- @param pos2
170+
-- @param off
171+
-- @return The number of nodes copied.
172+
function worldedit.copy2(pos1, pos2, off)
173+
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
174+
175+
worldedit.keep_loaded(pos1, pos2)
176+
177+
local get_node, get_meta, set_node = minetest.get_node,
178+
minetest.get_meta, minetest.set_node
179+
local pos = {}
180+
pos.x = pos2.x
181+
while pos.x >= pos1.x do
182+
pos.y = pos2.y
183+
while pos.y >= pos1.y do
184+
pos.z = pos2.z
185+
while pos.z >= pos1.z do
186+
local node = get_node(pos) -- Obtain current node
187+
local meta = get_meta(pos):to_table() -- Get meta of current node
188+
local newpos = vector.add(pos, off) -- Calculate new position
189+
set_node(newpos, node) -- Copy node to new position
190+
get_meta(newpos):from_table(meta) -- Set metadata of new node
191+
pos.z = pos.z - 1
192+
end
193+
pos.y = pos.y - 1
194+
end
195+
pos.x = pos.x - 1
196+
end
197+
return worldedit.volume(pos1, pos2)
198+
end
167199

168200
--- Moves a region along `axis` by `amount` nodes.
169201
-- @return The number of nodes moved.

0 commit comments

Comments
 (0)