Skip to content
Permalink
Browse files

Add `//scale <factor>` command (suggested by Jordach), fix transposit…

…ion description in docs.
  • Loading branch information
Uberi committed Jun 18, 2013
1 parent 74018da commit d4187866db261192b82930cd561172761dcc83e4
Showing with 84 additions and 2 deletions.
  1. +8 −0 Chat Commands.md
  2. +7 −1 WorldEdit API.md
  3. +37 −1 worldedit/manipulations.lua
  4. +32 −0 worldedit_commands/init.lua
@@ -166,6 +166,14 @@ Stack the current WorldEdit region along the x/y/z/? axis <count> times.
//stack z +5
//stack ? 12

### //scale <factor>

Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin.

//scale 2
//scale 1
//scale 10

### //transpose x/y/z/? x/y/z/?

Transpose the current WorldEdit positions and region along the x/y/z/? and x/y/z/? axes.
@@ -46,11 +46,17 @@ Duplicates the region defined by positions `pos1` and `pos2` along the `axis` ax

Returns the number of nodes stacked.

### count, newpos1, newpos2 = worldedit.scale(pos1, pos2, factor)

Scales the region defined by positions `pos1` and `pos2` by an factor of positive integer `factor` with `pos1` as the origin.

Returns the number of nodes scaled, the new scaled position 1, and the new scaled position 2.

### count, newpos1, newpos2 = worldedit.transpose(pos1, pos2, axis1, axis2)

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

Returns the number of nodes transposed, the new position 1, and the new position 2.
Returns the number of nodes transposed, the new transposed position 1, and the new transposed position 2.

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

@@ -222,7 +222,43 @@ worldedit.stack = function(pos1, pos2, axis, count, env)
return worldedit.volume(pos1, pos2)
end

--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
--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
worldedit.scale = function(pos1, pos2, factor, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
if env == nil then env = minetest.env end

local pos = {x=pos2.x, y=0, z=0}
local bigpos = {x=0, y=0, z=0}
size = factor - 1
while pos.x >= pos1.x do
pos.y = pos2.y
while pos.y >= pos1.y do
pos.z = pos2.z
while pos.z >= pos1.z do
local node = env:get_node(pos) --obtain current node
local meta = env:get_meta(pos):to_table() --get meta of current node
local value = pos[axis] --store current position
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
for x = 0, size do --fill in large node
for y = 0, size do
for z = 0, size do
bigpos.x, bigpos.y, bigpos.z = posx + x, posy + y, posz + z
env:add_node(bigpos, node) --copy node to new position
env:get_meta(bigpos):from_table(meta) --set metadata of new node
end
end
end
pos.z = pos.z - 1
end
pos.y = pos.y - 1
end
pos.x = pos.x - 1
end
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}
return worldedit.volume(pos1, pos2), pos1, newpos2
end

--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
worldedit.transpose = function(pos1, pos2, axis1, axis2, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)

@@ -631,6 +631,38 @@ minetest.register_chatcommand("/stack", {
end,
})

minetest.register_chatcommand("/scale", {
params = "<factor>",
description = "Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin",
privs = {worldedit=true},
func = function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
if pos1 == nil or pos2 == nil then
worldedit.player_notify(name, "no region selected")
return
end

local factor = tonumber(param)
if not factor or factor ~= math.floor(factor) or factor <= 0 then
worldedit.player_notify(name, "invalid scaling factor: " .. param)
end

local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor, tenv)

--reset markers to scaled positions
worldedit.pos1[name] = pos1
worldedit.pos2[name] = pos2
worldedit.mark_pos1(name)
worldedit.mark_pos2(name)

worldedit.player_notify(name, count .. " nodes scaled")
end,
})

minetest.register_chatcommand("/transpose", {
params = "x/y/z/? x/y/z/?",
description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",

0 comments on commit d418786

Please sign in to comment.