//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
\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
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
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