]> git.lizzy.rs Git - worldedit.git/blobdiff - worldedit/manipulations.lua
Improve node inspector to show player axis, replace //scale with //stretch, which...
[worldedit.git] / worldedit / manipulations.lua
index eee0bb8f2583d1d2ac0aff11c98cfb5eb21b27c9..1d4c6dc2096a1c04e3ff387513be56eb7d9eaf3a 100644 (file)
@@ -109,7 +109,7 @@ worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
        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
@@ -291,24 +291,28 @@ worldedit.stack = function(pos1, pos2, axis, count)
        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
@@ -321,8 +325,10 @@ worldedit.scale = function(pos1, pos2, factor)
                                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
@@ -331,10 +337,10 @@ worldedit.scale = function(pos1, pos2, factor)
                                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
@@ -347,7 +353,7 @@ worldedit.scale = function(pos1, pos2, factor)
                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