Skip to content

Commit 420655b

Browse files
committedJul 12, 2014
Merge pull request #51 from cyisfor/master
I think that's the optimization you mentioned?
2 parents ea84eee + f5b67c5 commit 420655b

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed
 

‎worldedit/manipulations.lua

+20-11
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ end
2525

2626
--sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled
2727
worldedit.set = function(pos1, pos2, nodenames)
28+
local oneNode
2829
if type(nodenames) == 'string' then
29-
nodenames = {nodenames}
30+
oneNode = true
31+
else
32+
oneNode = false
3033
end
3134

3235
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
@@ -48,10 +51,10 @@ worldedit.set = function(pos1, pos2, nodenames)
4851
for i,v in ipairs(nodenames) do
4952
node_ids[i] = minetest.get_content_id(nodenames[i])
5053
end
51-
if #node_ids == 1 then --only one type of node
52-
local id = node_ids[1]
54+
if oneNode then --only one type of node
55+
local id = node_ids
5356
for i in area:iterp(pos1, pos2) do nodes[i] = id end --fill area with node
54-
else --several tpyes of nodes specified
57+
else --several types of nodes specified
5558
local id_count, rand = #node_ids, math.random
5659
for i in area:iterp(pos1, pos2) do nodes[i] = node_ids[rand(id_count)] end --fill randomly with all types of specified nodes
5760
end
@@ -417,13 +420,19 @@ worldedit.stack = function(pos1, pos2, axis, count)
417420
if count < 0 then
418421
count = -count
419422
length = -length
420-
end
421-
local amount = 0
422-
local copy = worldedit.copy
423-
for i = 1, count do
424-
amount = amount + length
425-
copy(pos1, pos2, axis, amount)
426-
end
423+
end
424+
local amount = 0
425+
local copy = worldedit.copy
426+
local i = 1
427+
function nextone()
428+
if i <= count then
429+
i = i + 1
430+
amount = amount + length
431+
copy(pos1, pos2, axis, amount)
432+
minetest.after(0,nextone)
433+
end
434+
end
435+
nextone()
427436
return worldedit.volume(pos1, pos2) * count
428437
end
429438

0 commit comments

Comments
 (0)
Please sign in to comment.