Documentation for `//stack2`, code style fixes, add author section to README.

This commit is contained in:
Uberi 2014-07-06 19:42:02 -04:00
parent b32aadd7fa
commit 175ac211ca
4 changed files with 162 additions and 143 deletions

View File

@ -98,13 +98,13 @@ Display the volume of the current WorldEdit region.
//volume //volume
### `//set <node>` ### `//set <node1> ...`
Set the current WorldEdit region to `<node>`. Set the current WorldEdit region to a random mix of `<node1>`, `...`.
//set air //set air
//set cactus //set cactus stone glass
//set Bronze Block //set Bronze
//set mesecons:wire_00000000_off //set mesecons:wire_00000000_off
### `//replace <search node> <replace node>` ### `//replace <search node> <replace node>`
@ -219,6 +219,13 @@ Stack the current WorldEdit region along the x/y/z/? axis `<count>` times.
//stack z +5 //stack z +5
//stack ? 12 //stack ? 12
### `//stack2 <count> <x> <y> <z>`
Stack the current WorldEdit region `<count>` times by offset `<x>`, `<y>`, `<z>`.
//stack2 5 3 8 2
//stack2 1 -1 -1 -1
### `//scale <factor>` ### `//scale <factor>`
Scale the current WorldEdit positions and region by a factor of positive integer `<factor>` with position 1 as the origin. Scale the current WorldEdit positions and region by a factor of positive integer `<factor>` with position 1 as the origin.

View File

@ -130,6 +130,21 @@ The WorldEdit Schematic format is accessed via the WorldEdit API, or WorldEdit s
The second is the Minetest Schematic format (MTS). The details of this format may be found in the Minetest documentation and are out of the scope of this document. Access to this format is done via specialized MTS commands such as `//mtschemcreate` and `//mtschemplace`. The second is the Minetest Schematic format (MTS). The details of this format may be found in the Minetest documentation and are out of the scope of this document. Access to this format is done via specialized MTS commands such as `//mtschemcreate` and `//mtschemplace`.
Authors
-------
WorldEdit would not be possible without the contributions of many developers and designers. Below, they are listed alphabetically:
cheapie
cornernote
cyisfor
electricface
kaeza
khonkhortisan
sfan5
ShadowNinja
spillz
Uberi/Temperest
License License
------- -------
Copyright 2013 sfan5, Anthony Zhang (Uberi/Temperest), and Brett O'Donnell (cornernote). Copyright 2013 sfan5, Anthony Zhang (Uberi/Temperest), and Brett O'Donnell (cornernote).

View File

@ -48,8 +48,16 @@ worldedit.set = function(pos1, pos2, nodenames)
for i,v in ipairs(nodenames) do for i,v in ipairs(nodenames) do
node_ids[i] = minetest.get_content_id(nodenames[i]) node_ids[i] = minetest.get_content_id(nodenames[i])
end end
for i in area:iterp(pos1, pos2) do if #node_ids == 1 then --only one type of node
nodes[i] = node_ids[math.random(#node_ids)] local id = node_ids[1]
for i in area:iterp(pos1, pos2) do
nodes[i] = node_ids[id]
end
else --fill randomly with all types of specified nodes
local id_count, rand = #node_ids, math.random
for i in area:iterp(pos1, pos2) do
nodes[i] = node_ids[rand(id_count)]
end
end end
--update map nodes --update map nodes
@ -173,126 +181,126 @@ worldedit.copy = function(pos1, pos2, axis, amount) --wip: replace the old versi
end end
worldedit.copy2 = function(pos1, pos2, direction, volume) worldedit.copy2 = function(pos1, pos2, direction, volume)
-- the overlap shouldn't matter as long as we -- the overlap shouldn't matter as long as we
-- 1) start at the furthest separated corner -- 1) start at the furthest separated corner
-- 2) complete an edge before moving inward, either edge works -- 2) complete an edge before moving inward, either edge works
-- 3) complete a face before moving inward, similarly -- 3) complete a face before moving inward, similarly
-- --
-- to do this I -- to do this I
-- 1) find the furthest destination in the direction, of each axis -- 1) find the furthest destination in the direction, of each axis
-- 2) call those the furthest separated corner -- 2) call those the furthest separated corner
-- 3) make sure to iterate inward from there -- 3) make sure to iterate inward from there
-- 4) nested loop to make sure complete edge, complete face, then complete cube. -- 4) nested loop to make sure complete edge, complete face, then complete cube.
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
local somemeta = get_meta(pos1) -- hax lol local somemeta = get_meta(pos1) -- hax lol
local to_table = somemeta.to_table local to_table = somemeta.to_table
local from_table = somemeta.from_table local from_table = somemeta.from_table
somemeta = nil somemeta = nil
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local manip = minetest.get_voxel_manip() local manip = minetest.get_voxel_manip()
manip:read_from_map(pos1, pos2) manip:read_from_map(pos1, pos2)
local sx,sy,sz -- direction sign local sx, sy, sz -- direction sign
local ix,iy,iz -- initial destination local ix, iy, iz -- initial destination
local ex,ey,ez -- final destination local ex, ey, ez -- final destination
local originalx,originaly,originalz -- source local originalx, originaly, originalz -- source
-- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g -- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g
if direction.x > 0 then if direction.x > 0 then
originalx = pos2.x originalx = pos2.x
ix = originalx + direction.x ix = originalx + direction.x
ex = pos1.x + direction.x ex = pos1.x + direction.x
sx = -1 sx = -1
elseif direction.x < 0 then elseif direction.x < 0 then
originalx = pos1.x originalx = pos1.x
ix = originalx + direction.x ix = originalx + direction.x
ex = pos2.x + direction.x ex = pos2.x + direction.x
sx = 1 sx = 1
else else
originalx = pos1.x originalx = pos1.x
ix = originalx -- whatever ix = originalx -- whatever
ex = pos2.x ex = pos2.x
sx = 1 sx = 1
end end
if direction.y > 0 then if direction.y > 0 then
originaly = pos2.y originaly = pos2.y
iy = originaly + direction.y iy = originaly + direction.y
ey = pos1.y + direction.y ey = pos1.y + direction.y
sy = -1 sy = -1
elseif direction.y < 0 then elseif direction.y < 0 then
originaly = pos1.y originaly = pos1.y
iy = originaly + direction.y iy = originaly + direction.y
ey = pos2.y + direction.y ey = pos2.y + direction.y
sy = 1 sy = 1
else else
originaly = pos1.y originaly = pos1.y
iy = originaly -- whatever iy = originaly -- whatever
ey = pos2.y ey = pos2.y
sy = 1 sy = 1
end end
if direction.z > 0 then if direction.z > 0 then
originalz = pos2.z originalz = pos2.z
iz = originalz + direction.z iz = originalz + direction.z
ez = pos1.z + direction.z ez = pos1.z + direction.z
sz = -1 sz = -1
elseif direction.z < 0 then elseif direction.z < 0 then
originalz = pos1.z originalz = pos1.z
iz = originalz + direction.z iz = originalz + direction.z
ez = pos2.z + direction.z ez = pos2.z + direction.z
sz = 1 sz = 1
else else
originalz = pos1.z originalz = pos1.z
iz = originalz -- whatever iz = originalz -- whatever
ez = pos2.z ez = pos2.z
sz = 1 sz = 1
end end
-- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz) -- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz)
local ox,oy,oz local ox,oy,oz
ox = originalx ox = originalx
for x = ix,ex,sx do for x = ix, ex, sx do
oy = originaly oy = originaly
for y = iy,ey,sy do for y = iy, ey, sy do
oz = originalz oz = originalz
for z = iz,ez,sz do for z = iz, ez, sz do
-- reusing pos1/pos2 as source/dest here -- reusing pos1/pos2 as source/dest here
pos1.x = ox; pos1.y = oy; pos1.z = oz pos1.x, pos1.y, pos1.z = ox, oy, oz
pos2.x = x; pos2.y = y; pos2.z = z pos2.x, pos2.y, pos2.z = x, y, z
local node = get_node(pos1) local node = get_node(pos1)
local meta = to_table(get_meta(pos1)) --get meta of current node local meta = to_table(get_meta(pos1)) --get meta of current node
add_node(pos2,node) add_node(pos2,node)
from_table(get_meta(pos2),meta) from_table(get_meta(pos2),meta)
oz = oz + sz oz = oz + sz
end end
oy = oy + sy oy = oy + sy
end end
ox = ox + sx ox = ox + sx
end end
end end
worldedit.stack2 = function(pos1, pos2, direction, amount, finished) worldedit.stack2 = function(pos1, pos2, direction, amount, finished)
local i = 0 local i = 0
local translated = {x=0,y=0,z=0} local translated = {x=0,y=0,z=0}
local function nextone() local function nextone()
if i <= amount then if i <= amount then
i = i + 1 i = i + 1
translated.x = translated.x + direction.x translated.x = translated.x + direction.x
translated.y = translated.y + direction.y translated.y = translated.y + direction.y
translated.z = translated.z + direction.z translated.z = translated.z + direction.z
worldedit.copy2(pos1,pos2,translated,volume) worldedit.copy2(pos1, pos2, translated, volume)
minetest.after(0,nextone) minetest.after(0, nextone)
else else
if finished then if finished then
finished() finished()
end end
end end
end end
nextone() nextone()
return nil return nil
end end
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied --copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied

View File

@ -279,19 +279,18 @@ minetest.register_chatcommand("/volume", {
}) })
minetest.register_chatcommand("/set", { minetest.register_chatcommand("/set", {
params = "<node>", params = "<node1> ...",
description = "Set the current WorldEdit region to <node>", description = "Set the current WorldEdit region to a random mix of <node1>, ...",
privs = {worldedit=true}, privs = {worldedit=true},
func = safe_region(function(name, param) func = safe_region(function(name, param)
local nodes = {} local nodes = {}
for nodename in param:gmatch("[^%s]+") do for nodename in param:gmatch("[^%s]+") do
local node = get_node(name, nodename) local node = get_node(name, nodename)
if not node then if not node then
worldedit.player_notify(name, 'Could not identify node "'..name..'"') worldedit.player_notify(name, "Could not identify node \"" .. name .. "\"")
return return
end end
nodes[#nodes+1] = node nodes[#nodes + 1] = node
end end
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
@ -620,47 +619,37 @@ minetest.register_chatcommand("/stack", {
}) })
minetest.register_chatcommand("/stack2", { minetest.register_chatcommand("/stack2", {
params = "<count> <x>/<y>/<z>", params = "<count> <x> <y> <z>",
description = "Stack the current WorldEdit region <count> times translating each time by x, y and z in the respective directions.", description = "Stack the current WorldEdit region <count> times by offset <x>, <y>, <z>",
privs = {worldedit=true}, privs = {worldedit=true},
func = function(name, param) func = function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
if pos1 == nil or pos2 == nil then if pos1 == nil or pos2 == nil then
worldedit.player_notify(name, "Select a position first!") worldedit.player_notify(name, "Select a position first!")
return return
end end
local repetitions, incs = param:match("([0-9]+)%s*(.+)") local repetitions, incs = param:match("(%d+)%s*(.+)")
repetitions = repetitions and tonumber(repetitions)
if repetitions == nil then if repetitions == nil then
worldedit.player_notify(name, "invalid count: " .. param) worldedit.player_notify(name, "invalid count: " .. param)
return return
end end
repetitions = tonumber(repetitions)
local x,y,z = incs:match("(.+)/(.+)/(.+)") local x, y, z = incs:match("([+-]?%d+) ([+-]%d+) ([+-]%d+)")
if x == nil then if x == nil then
worldedit.player_notify(name, "invalid increments: " .. param) worldedit.player_notify(name, "invalid increments: " .. param)
return return
end end
x = tonumber(x) x, y, z = tonumber(x), tonumber(y), tonumber(z)
y = tonumber(y)
z = tonumber(z)
if x == nil or y == nil or z == nil then
worldedit.player_notify(name, "increments must be numbers: " .. param)
return
end
local count = worldedit.volume(pos1,pos2) * repetitions local count = worldedit.volume(pos1, pos2) * repetitions
return safe_region(function() return safe_region(function()
worldedit.stack2(pos1, pos2, {x=x,y=y,z=z}, repetitions, worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions,
function() function() worldedit.player_notify(name, count .. " nodes stacked") end)
worldedit.player_notify(name, count .. " nodes stacked") end, function()
end) return count
end)(name,param) -- more hax
end,
function()
return count
end)(name,param) -- more hax
end end
}) })