return count\r
end\r
\r
-worldedit.copy = function(pos1, pos2, axis, amount)\r
+worldedit.copy = function(pos1, pos2, axis, amount) --wip: replace the old version below\r
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
\r
if amount == 0 then\r
return worldedit.volume(pos1, pos2) * count\r
end\r
\r
---scales the region defined by positions `pos1` and `pos2` by an factor of positive integer `factor` with `pos1` as the origin, returning the number of nodes scaled, the new scaled position 1, and the new scaled position 2\r
-worldedit.scale = function(pos1, pos2, factor)\r
+--stretches the region defined by positions `pos1` and `pos2` by an factor of positive integers `stretchx`, `stretchy`. and `stretchz` along the X, Y, and Z axes, respectively, with `pos1` as the origin, returning the number of nodes scaled, the new scaled position 1, and the new scaled position 2\r
+worldedit.stretch = function(pos1, pos2, stretchx, stretchy, stretchz) --wip: test this\r
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
\r
--prepare schematic of large node\r
local get_node, get_meta, place_schematic = minetest.get_node, minetest.get_meta, minetest.place_schematic\r
local placeholder_node = {name="", param1=255, param2=0}\r
local nodes = {}\r
- for i = 1, factor ^ 3 do\r
+ for i = 1, stretchx * stretchy * stretchz do\r
nodes[i] = placeholder_node\r
end\r
- local schematic = {size={x=factor, y=factor, z=factor}, data=nodes}\r
+ local schematic = {size={x=stretchx, y=stretchy, z=stretchz}, data=nodes}\r
\r
- local size = factor - 1\r
+ local sizex, sizey, sizez = stretchx - 1, stretchy - 1, stretchz - 1\r
\r
--make area stay loaded\r
local manip = minetest.get_voxel_manip()\r
- local new_pos2 = {x=pos1.x + (pos2.x - pos1.x) * factor + size, y=pos1.y + (pos2.y - pos1.y) * factor + size, z=pos1.z + (pos2.z - pos1.z) * factor + size}\r
+ local new_pos2 = {\r
+ x=pos1.x + (pos2.x - pos1.x) * stretchx + sizex,\r
+ y=pos1.y + (pos2.y - pos1.y) * stretchy + sizey,\r
+ z=pos1.z + (pos2.z - pos1.z) * stretchz + sizez,\r
+ }\r
manip:read_from_map(pos1, new_pos2)\r
\r
local pos = {x=pos2.x, y=0, z=0}\r
local node = get_node(pos) --obtain current node\r
local meta = get_meta(pos):to_table() --get meta of current node\r
\r
- local value = pos[axis] --store current position\r
- local posx, posy, posz = pos1.x + (pos.x - pos1.x) * factor, pos1.y + (pos.y - pos1.y) * factor, pos1.z + (pos.z - pos1.z) * factor\r
+ --calculate far corner of the big node\r
+ local posx = pos1.x + (pos.x - pos1.x) * stretchx\r
+ local posy = pos1.y + (pos.y - pos1.y) * stretchy\r
+ local posz = pos1.z + (pos.z - pos1.z) * stretchz\r
\r
--create large node\r
placeholder_node.name = node.name\r
place_schematic(bigpos, schematic)\r
\r
--fill in large node meta\r
- if next(meta.fields) ~= nil and next(meta.inventory) ~= nil then --node has meta fields\r
- for x = 0, size do\r
- for y = 0, size do\r
- for z = 0, size do\r
+ if next(meta.fields) ~= nil or next(meta.inventory) ~= nil then --node has meta fields\r
+ for x = 0, sizex do\r
+ for y = 0, sizey do\r
+ for z = 0, sizez do\r
bigpos.x, bigpos.y, bigpos.z = posx + x, posy + y, posz + z\r
get_meta(bigpos):from_table(meta) --set metadata of new node\r
end\r
end\r
pos.x = pos.x - 1\r
end\r
- return worldedit.volume(pos1, pos2) * (factor ^ 3), pos1, new_pos2\r
+ return worldedit.volume(pos1, pos2) * stretchx * stretchy * stretchz, pos1, new_pos2\r
end\r
\r
--transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed, the new transposed position 1, and the new transposed position 2\r