summaryrefslogtreecommitdiff
path: root/worldedit/manipulations.lua
diff options
context:
space:
mode:
authorAnthony Zhang <azhang9@gmail.com>2014-07-12 16:31:27 -0400
committerAnthony Zhang <azhang9@gmail.com>2014-07-12 16:31:27 -0400
commit420655bd945d43a38ced9062b40070dded12f62d (patch)
tree359204a9f433323407a5f3b905fdac1c17d16981 /worldedit/manipulations.lua
parentea84eee0e51d410b9bc6cefa41efb5499ebd41ef (diff)
parentf5b67c5bc2de047ec322c5e284bafe00becc84b1 (diff)
Merge pull request #51 from cyisfor/master
I think that's the optimization you mentioned?
Diffstat (limited to 'worldedit/manipulations.lua')
-rw-r--r--worldedit/manipulations.lua31
1 files changed, 20 insertions, 11 deletions
diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua
index ee73a2d..2fa9a1e 100644
--- a/worldedit/manipulations.lua
+++ b/worldedit/manipulations.lua
@@ -25,8 +25,11 @@ end
--sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled
worldedit.set = function(pos1, pos2, nodenames)
+ local oneNode
if type(nodenames) == 'string' then
- nodenames = {nodenames}
+ oneNode = true
+ else
+ oneNode = false
end
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
@@ -48,10 +51,10 @@ worldedit.set = function(pos1, pos2, nodenames)
for i,v in ipairs(nodenames) do
node_ids[i] = minetest.get_content_id(nodenames[i])
end
- if #node_ids == 1 then --only one type of node
- local id = node_ids[1]
+ if oneNode then --only one type of node
+ local id = node_ids
for i in area:iterp(pos1, pos2) do nodes[i] = id end --fill area with node
- else --several tpyes of nodes specified
+ else --several types of nodes specified
local id_count, rand = #node_ids, math.random
for i in area:iterp(pos1, pos2) do nodes[i] = node_ids[rand(id_count)] end --fill randomly with all types of specified nodes
end
@@ -417,13 +420,19 @@ worldedit.stack = function(pos1, pos2, axis, count)
if count < 0 then
count = -count
length = -length
- end
- local amount = 0
- local copy = worldedit.copy
- for i = 1, count do
- amount = amount + length
- copy(pos1, pos2, axis, amount)
- end
+ end
+ local amount = 0
+ local copy = worldedit.copy
+ local i = 1
+ function nextone()
+ if i <= count then
+ i = i + 1
+ amount = amount + length
+ copy(pos1, pos2, axis, amount)
+ minetest.after(0,nextone)
+ end
+ end
+ nextone()
return worldedit.volume(pos1, pos2) * count
end