for i,v in ipairs(nodenames) do\r
node_ids[i] = minetest.get_content_id(nodenames[i])\r
end\r
- for i in area:iterp(pos1, pos2) do\r
- nodes[i] = node_ids[math.random(#node_ids)]\r
+ if #node_ids == 1 then --only one type of node\r
+ local id = node_ids[1]\r
+ for i in area:iterp(pos1, pos2) do\r
+ nodes[i] = node_ids[id]\r
+ end\r
+ else --fill randomly with all types of specified nodes\r
+ local id_count, rand = #node_ids, math.random\r
+ for i in area:iterp(pos1, pos2) do\r
+ nodes[i] = node_ids[rand(id_count)]\r
+ end\r
end\r
\r
--update map nodes\r
end\r
\r
worldedit.copy2 = function(pos1, pos2, direction, volume)\r
- -- the overlap shouldn't matter as long as we\r
- -- 1) start at the furthest separated corner\r
- -- 2) complete an edge before moving inward, either edge works\r
- -- 3) complete a face before moving inward, similarly\r
- --\r
- -- to do this I\r
- -- 1) find the furthest destination in the direction, of each axis\r
- -- 2) call those the furthest separated corner\r
- -- 3) make sure to iterate inward from there\r
- -- 4) nested loop to make sure complete edge, complete face, then complete cube.\r
- \r
+ -- the overlap shouldn't matter as long as we\r
+ -- 1) start at the furthest separated corner\r
+ -- 2) complete an edge before moving inward, either edge works\r
+ -- 3) complete a face before moving inward, similarly\r
+ --\r
+ -- to do this I\r
+ -- 1) find the furthest destination in the direction, of each axis\r
+ -- 2) call those the furthest separated corner\r
+ -- 3) make sure to iterate inward from there\r
+ -- 4) nested loop to make sure complete edge, complete face, then complete cube.\r
+\r
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node\r
- local somemeta = get_meta(pos1) -- hax lol\r
- local to_table = somemeta.to_table\r
- local from_table = somemeta.from_table\r
- somemeta = nil\r
+ local somemeta = get_meta(pos1) -- hax lol\r
+ local to_table = somemeta.to_table\r
+ local from_table = somemeta.from_table\r
+ somemeta = nil\r
\r
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
local manip = minetest.get_voxel_manip()\r
manip:read_from_map(pos1, pos2)\r
\r
- local sx,sy,sz -- direction sign\r
- local ix,iy,iz -- initial destination\r
- local ex,ey,ez -- final destination\r
- local originalx,originaly,originalz -- source \r
- -- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g\r
- if direction.x > 0 then \r
- originalx = pos2.x\r
- ix = originalx + direction.x\r
- ex = pos1.x + direction.x\r
- sx = -1\r
- elseif direction.x < 0 then \r
- originalx = pos1.x\r
- ix = originalx + direction.x\r
- ex = pos2.x + direction.x\r
- sx = 1\r
- else \r
- originalx = pos1.x\r
- ix = originalx -- whatever\r
- ex = pos2.x\r
- sx = 1\r
- end\r
+ local sx, sy, sz -- direction sign\r
+ local ix, iy, iz -- initial destination\r
+ local ex, ey, ez -- final destination\r
+ local originalx, originaly, originalz -- source\r
+ -- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g\r
+ if direction.x > 0 then\r
+ originalx = pos2.x\r
+ ix = originalx + direction.x\r
+ ex = pos1.x + direction.x\r
+ sx = -1\r
+ elseif direction.x < 0 then\r
+ originalx = pos1.x\r
+ ix = originalx + direction.x\r
+ ex = pos2.x + direction.x\r
+ sx = 1\r
+ else\r
+ originalx = pos1.x\r
+ ix = originalx -- whatever\r
+ ex = pos2.x\r
+ sx = 1\r
+ end\r
\r
- if direction.y > 0 then \r
- originaly = pos2.y\r
- iy = originaly + direction.y\r
- ey = pos1.y + direction.y\r
- sy = -1\r
- elseif direction.y < 0 then \r
- originaly = pos1.y\r
- iy = originaly + direction.y\r
- ey = pos2.y + direction.y\r
- sy = 1\r
- else \r
- originaly = pos1.y\r
- iy = originaly -- whatever\r
- ey = pos2.y\r
- sy = 1\r
- end\r
+ if direction.y > 0 then\r
+ originaly = pos2.y\r
+ iy = originaly + direction.y\r
+ ey = pos1.y + direction.y\r
+ sy = -1\r
+ elseif direction.y < 0 then\r
+ originaly = pos1.y\r
+ iy = originaly + direction.y\r
+ ey = pos2.y + direction.y\r
+ sy = 1\r
+ else\r
+ originaly = pos1.y\r
+ iy = originaly -- whatever\r
+ ey = pos2.y\r
+ sy = 1\r
+ end\r
\r
- if direction.z > 0 then \r
- originalz = pos2.z\r
- iz = originalz + direction.z\r
- ez = pos1.z + direction.z\r
- sz = -1\r
- elseif direction.z < 0 then \r
- originalz = pos1.z\r
- iz = originalz + direction.z\r
- ez = pos2.z + direction.z\r
- sz = 1\r
- else \r
- originalz = pos1.z\r
- iz = originalz -- whatever\r
- ez = pos2.z\r
- sz = 1\r
- end\r
- -- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz)\r
-\r
- local ox,oy,oz\r
-\r
- ox = originalx\r
- for x = ix,ex,sx do\r
- oy = originaly\r
- for y = iy,ey,sy do\r
- oz = originalz\r
- for z = iz,ez,sz do\r
- -- reusing pos1/pos2 as source/dest here\r
- pos1.x = ox; pos1.y = oy; pos1.z = oz\r
- pos2.x = x; pos2.y = y; pos2.z = z\r
- local node = get_node(pos1)\r
+ if direction.z > 0 then\r
+ originalz = pos2.z\r
+ iz = originalz + direction.z\r
+ ez = pos1.z + direction.z\r
+ sz = -1\r
+ elseif direction.z < 0 then\r
+ originalz = pos1.z\r
+ iz = originalz + direction.z\r
+ ez = pos2.z + direction.z\r
+ sz = 1\r
+ else\r
+ originalz = pos1.z\r
+ iz = originalz -- whatever\r
+ ez = pos2.z\r
+ sz = 1\r
+ end\r
+ -- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz)\r
+\r
+ local ox,oy,oz\r
+\r
+ ox = originalx\r
+ for x = ix, ex, sx do\r
+ oy = originaly\r
+ for y = iy, ey, sy do\r
+ oz = originalz\r
+ for z = iz, ez, sz do\r
+ -- reusing pos1/pos2 as source/dest here\r
+ pos1.x, pos1.y, pos1.z = ox, oy, oz\r
+ pos2.x, pos2.y, pos2.z = x, y, z\r
+ local node = get_node(pos1)\r
local meta = to_table(get_meta(pos1)) --get meta of current node\r
- add_node(pos2,node)\r
- from_table(get_meta(pos2),meta)\r
- oz = oz + sz\r
- end\r
- oy = oy + sy\r
- end\r
- ox = ox + sx\r
- end\r
-end \r
-\r
-worldedit.stack2 = function(pos1, pos2, direction, amount, finished) \r
- local i = 0\r
- local translated = {x=0,y=0,z=0}\r
- local function nextone()\r
- if i <= amount then\r
- i = i + 1\r
- translated.x = translated.x + direction.x\r
- translated.y = translated.y + direction.y\r
- translated.z = translated.z + direction.z\r
- worldedit.copy2(pos1,pos2,translated,volume)\r
- minetest.after(0,nextone)\r
- else\r
- if finished then\r
- finished()\r
- end\r
- end\r
- end\r
- nextone()\r
- return nil\r
+ add_node(pos2,node)\r
+ from_table(get_meta(pos2),meta)\r
+ oz = oz + sz\r
+ end\r
+ oy = oy + sy\r
+ end\r
+ ox = ox + sx\r
+ end\r
+end\r
+\r
+worldedit.stack2 = function(pos1, pos2, direction, amount, finished)\r
+ local i = 0\r
+ local translated = {x=0,y=0,z=0}\r
+ local function nextone()\r
+ if i <= amount then\r
+ i = i + 1\r
+ translated.x = translated.x + direction.x\r
+ translated.y = translated.y + direction.y\r
+ translated.z = translated.z + direction.z\r
+ worldedit.copy2(pos1, pos2, translated, volume)\r
+ minetest.after(0, nextone)\r
+ else\r
+ if finished then\r
+ finished()\r
+ end\r
+ end\r
+ end\r
+ nextone()\r
+ return nil\r
end\r
\r
--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\r
})\r
\r
minetest.register_chatcommand("/set", {\r
- params = "<node>",\r
- description = "Set the current WorldEdit region to <node>",\r
+ params = "<node1> ...",\r
+ description = "Set the current WorldEdit region to a random mix of <node1>, ...",\r
privs = {worldedit=true},\r
func = safe_region(function(name, param)\r
local nodes = {}\r
-\r
for nodename in param:gmatch("[^%s]+") do\r
local node = get_node(name, nodename)\r
if not node then\r
- worldedit.player_notify(name, 'Could not identify node "'..name..'"')\r
+ worldedit.player_notify(name, "Could not identify node \"" .. name .. "\"")\r
return\r
end\r
- nodes[#nodes+1] = node\r
+ nodes[#nodes + 1] = node\r
end\r
\r
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
})\r
\r
minetest.register_chatcommand("/stack2", {\r
- params = "<count> <x>/<y>/<z>",\r
- description = "Stack the current WorldEdit region <count> times translating each time by x, y and z in the respective directions.",\r
+ params = "<count> <x> <y> <z>",\r
+ description = "Stack the current WorldEdit region <count> times by offset <x>, <y>, <z>",\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, "Select a position first!")\r
+ worldedit.player_notify(name, "Select a position first!")\r
return\r
end\r
- local repetitions, incs = param:match("([0-9]+)%s*(.+)")\r
- repetitions = repetitions and tonumber(repetitions)\r
+ local repetitions, incs = param:match("(%d+)%s*(.+)")\r
if repetitions == nil then\r
worldedit.player_notify(name, "invalid count: " .. param)\r
- return \r
+ return\r
end\r
+ repetitions = tonumber(repetitions)\r
\r
- local x,y,z = incs:match("(.+)/(.+)/(.+)")\r
+ local x, y, z = incs:match("([+-]?%d+) ([+-]%d+) ([+-]%d+)")\r
if x == nil then\r
worldedit.player_notify(name, "invalid increments: " .. param)\r
return\r
end\r
- x = tonumber(x)\r
- y = tonumber(y)\r
- z = tonumber(z)\r
- if x == nil or y == nil or z == nil then\r
- worldedit.player_notify(name, "increments must be numbers: " .. param)\r
- return\r
- end\r
+ x, y, z = tonumber(x), tonumber(y), tonumber(z)\r
\r
- local count = worldedit.volume(pos1,pos2) * repetitions\r
+ local count = worldedit.volume(pos1, pos2) * repetitions\r
\r
return safe_region(function()\r
- worldedit.stack2(pos1, pos2, {x=x,y=y,z=z}, repetitions,\r
- function()\r
- worldedit.player_notify(name, count .. " nodes stacked")\r
- end)\r
-\r
- end,\r
- function() \r
- return count\r
- end)(name,param) -- more hax\r
+ worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions,\r
+ function() worldedit.player_notify(name, count .. " nodes stacked") end)\r
+ end, function()\r
+ return count\r
+ end)(name,param) -- more hax\r
end\r
})\r
\r