]> git.lizzy.rs Git - worldedit.git/commitdiff
Add `//scale <factor>` command (suggested by Jordach), fix transposition description...
authorAnthony Zhang <azhang9@gmail.com>
Tue, 18 Jun 2013 19:05:49 +0000 (15:05 -0400)
committerAnthony Zhang <azhang9@gmail.com>
Tue, 18 Jun 2013 19:05:49 +0000 (15:05 -0400)
Chat Commands.md
WorldEdit API.md
worldedit/manipulations.lua
worldedit_commands/init.lua

index 4b395269a40ca89e57dc6ce82377fcee2f84e406..bba8762b34fef3a40f7970dd6252b3cce21e3d5e 100644 (file)
@@ -166,6 +166,14 @@ Stack the current WorldEdit region along the x/y/z/? axis <count> times.
     //stack z +5\r
     //stack ? 12\r
 \r
+### //scale <factor>\r
+\r
+Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin.\r
+\r
+    //scale 2\r
+    //scale 1\r
+    //scale 10\r
+\r
 ### //transpose x/y/z/? x/y/z/?\r
 \r
 Transpose the current WorldEdit positions and region along the x/y/z/? and x/y/z/? axes.\r
index 6008a9fb54431629b88709c99ca3af921accdfd2..c994bf7bc965f6562998526b142d8b92a309640c 100644 (file)
@@ -46,11 +46,17 @@ Duplicates the region defined by positions `pos1` and `pos2` along the `axis` ax
 \r
 Returns the number of nodes stacked.\r
 \r
+### count, newpos1, newpos2 = worldedit.scale(pos1, pos2, factor)\r
+\r
+Scales the region defined by positions `pos1` and `pos2` by an factor of positive integer `factor` with `pos1` as the origin.\r
+\r
+Returns the number of nodes scaled, the new scaled position 1, and the new scaled position 2.\r
+\r
 ### count, newpos1, newpos2 = worldedit.transpose(pos1, pos2, axis1, axis2)\r
 \r
 Transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes ("x" or "y" or "z").\r
 \r
-Returns the number of nodes transposed, the new position 1, and the new position 2.\r
+Returns the number of nodes transposed, the new transposed position 1, and the new transposed position 2.\r
 \r
 ### count = worldedit.flip(pos1, pos2, axis)\r
 \r
index b5bcd3c42af4dcadf3e4a8458432983f51d93cf6..4b78e2ace1b4db76ebb68f3e64590481d1e984c4 100644 (file)
@@ -222,7 +222,43 @@ worldedit.stack = function(pos1, pos2, axis, count, env)
        return worldedit.volume(pos1, 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 position 1, and the new position 2\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, env)\r
+       local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+       if env == nil then env = minetest.env end\r
+\r
+       local pos = {x=pos2.x, y=0, z=0}\r
+       local bigpos = {x=0, y=0, z=0}\r
+       size = factor - 1\r
+       while pos.x >= pos1.x do\r
+               pos.y = pos2.y\r
+               while pos.y >= pos1.y do\r
+                       pos.z = pos2.z\r
+                       while pos.z >= pos1.z do\r
+                               local node = env:get_node(pos) --obtain current node\r
+                               local meta = env:get_meta(pos):to_table() --get meta of current node\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
+                               for x = 0, size do --fill in large node\r
+                                       for y = 0, size do\r
+                                               for z = 0, size do\r
+                                                       bigpos.x, bigpos.y, bigpos.z = posx + x, posy + y, posz + z\r
+                                                       env:add_node(bigpos, node) --copy node to new position\r
+                                                       env:get_meta(bigpos):from_table(meta) --set metadata of new node\r
+                                               end\r
+                                       end\r
+                               end\r
+                               pos.z = pos.z - 1\r
+                       end\r
+                       pos.y = pos.y - 1\r
+               end\r
+               pos.x = pos.x - 1\r
+       end\r
+       local newpos2 = {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
+       return worldedit.volume(pos1, pos2), pos1, newpos2\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
 worldedit.transpose = function(pos1, pos2, axis1, axis2, env)\r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
 \r
index 69e9804a36ddb6c60144b2aaaddd5f2f22689d65..f610ccbce325cd5f472737a741b530de58231f04 100644 (file)
@@ -631,6 +631,38 @@ minetest.register_chatcommand("/stack", {
        end,\r
 })\r
 \r
+minetest.register_chatcommand("/scale", {\r
+       params = "<factor>",\r
+       description = "Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+               if pos1 == nil or pos2 == nil then\r
+                       worldedit.player_notify(name, "no region selected")\r
+                       return\r
+               end\r
+\r
+               local factor = tonumber(param)\r
+               if not factor or factor ~= math.floor(factor) or factor <= 0 then\r
+                       worldedit.player_notify(name, "invalid scaling factor: " .. param)\r
+               end\r
+\r
+               local tenv = minetest.env\r
+               if worldedit.ENABLE_QUEUE then\r
+                       tenv = worldedit.queue_aliasenv\r
+               end\r
+               local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor, tenv)\r
+\r
+               --reset markers to scaled positions\r
+               worldedit.pos1[name] = pos1\r
+               worldedit.pos2[name] = pos2\r
+               worldedit.mark_pos1(name)\r
+               worldedit.mark_pos2(name)\r
+\r
+               worldedit.player_notify(name, count .. " nodes scaled")\r
+       end,\r
+})\r
+\r
 minetest.register_chatcommand("/transpose", {\r
        params = "x/y/z/? x/y/z/?",\r
        description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",\r