Skip to content

Commit d418786

Browse files
committedJun 18, 2013
Add //scale <factor> command (suggested by Jordach), fix transposition description in docs.
1 parent 74018da commit d418786

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed
 

‎Chat Commands.md

+8
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ Stack the current WorldEdit region along the x/y/z/? axis <count> times.
166166
//stack z +5
167167
//stack ? 12
168168

169+
### //scale <factor>
170+
171+
Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin.
172+
173+
//scale 2
174+
//scale 1
175+
//scale 10
176+
169177
### //transpose x/y/z/? x/y/z/?
170178

171179
Transpose the current WorldEdit positions and region along the x/y/z/? and x/y/z/? axes.

‎WorldEdit API.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ Duplicates the region defined by positions `pos1` and `pos2` along the `axis` ax
4646

4747
Returns the number of nodes stacked.
4848

49+
### count, newpos1, newpos2 = worldedit.scale(pos1, pos2, factor)
50+
51+
Scales the region defined by positions `pos1` and `pos2` by an factor of positive integer `factor` with `pos1` as the origin.
52+
53+
Returns the number of nodes scaled, the new scaled position 1, and the new scaled position 2.
54+
4955
### count, newpos1, newpos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
5056

5157
Transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes ("x" or "y" or "z").
5258

53-
Returns the number of nodes transposed, the new position 1, and the new position 2.
59+
Returns the number of nodes transposed, the new transposed position 1, and the new transposed position 2.
5460

5561
### count = worldedit.flip(pos1, pos2, axis)
5662

‎worldedit/manipulations.lua

+37-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,43 @@ worldedit.stack = function(pos1, pos2, axis, count, env)
222222
return worldedit.volume(pos1, pos2)
223223
end
224224

225-
--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
225+
--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
226+
worldedit.scale = function(pos1, pos2, factor, env)
227+
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
228+
if env == nil then env = minetest.env end
229+
230+
local pos = {x=pos2.x, y=0, z=0}
231+
local bigpos = {x=0, y=0, z=0}
232+
size = factor - 1
233+
while pos.x >= pos1.x do
234+
pos.y = pos2.y
235+
while pos.y >= pos1.y do
236+
pos.z = pos2.z
237+
while pos.z >= pos1.z do
238+
local node = env:get_node(pos) --obtain current node
239+
local meta = env:get_meta(pos):to_table() --get meta of current node
240+
local value = pos[axis] --store current position
241+
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
242+
for x = 0, size do --fill in large node
243+
for y = 0, size do
244+
for z = 0, size do
245+
bigpos.x, bigpos.y, bigpos.z = posx + x, posy + y, posz + z
246+
env:add_node(bigpos, node) --copy node to new position
247+
env:get_meta(bigpos):from_table(meta) --set metadata of new node
248+
end
249+
end
250+
end
251+
pos.z = pos.z - 1
252+
end
253+
pos.y = pos.y - 1
254+
end
255+
pos.x = pos.x - 1
256+
end
257+
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}
258+
return worldedit.volume(pos1, pos2), pos1, newpos2
259+
end
260+
261+
--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
226262
worldedit.transpose = function(pos1, pos2, axis1, axis2, env)
227263
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
228264

‎worldedit_commands/init.lua

+32
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,38 @@ minetest.register_chatcommand("/stack", {
631631
end,
632632
})
633633

634+
minetest.register_chatcommand("/scale", {
635+
params = "<factor>",
636+
description = "Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin",
637+
privs = {worldedit=true},
638+
func = function(name, param)
639+
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
640+
if pos1 == nil or pos2 == nil then
641+
worldedit.player_notify(name, "no region selected")
642+
return
643+
end
644+
645+
local factor = tonumber(param)
646+
if not factor or factor ~= math.floor(factor) or factor <= 0 then
647+
worldedit.player_notify(name, "invalid scaling factor: " .. param)
648+
end
649+
650+
local tenv = minetest.env
651+
if worldedit.ENABLE_QUEUE then
652+
tenv = worldedit.queue_aliasenv
653+
end
654+
local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor, tenv)
655+
656+
--reset markers to scaled positions
657+
worldedit.pos1[name] = pos1
658+
worldedit.pos2[name] = pos2
659+
worldedit.mark_pos1(name)
660+
worldedit.mark_pos2(name)
661+
662+
worldedit.player_notify(name, count .. " nodes scaled")
663+
end,
664+
})
665+
634666
minetest.register_chatcommand("/transpose", {
635667
params = "x/y/z/? x/y/z/?",
636668
description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",

0 commit comments

Comments
 (0)
Please sign in to comment.