Skip to content

Commit 5e5c1dc

Browse files
committedApr 28, 2013
Add Block Queue
1 parent 71b6004 commit 5e5c1dc

File tree

7 files changed

+292
-84
lines changed

7 files changed

+292
-84
lines changed
 

‎worldedit/init.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ loadmodule(path .. "/primitives.lua")
1111
loadmodule(path .. "/visualization.lua")
1212
loadmodule(path .. "/serialization.lua")
1313
loadmodule(path .. "/code.lua")
14-
loadmodule(path .. "/compatibility.lua")
14+
loadmodule(path .. "/compatibility.lua")
15+
loadmodule(path .. "/queue.lua")

‎worldedit/manipulations.lua

+27-27
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ worldedit.volume = function(pos1, pos2)
2323
end
2424

2525
--sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled
26-
worldedit.set = function(pos1, pos2, nodename)
26+
worldedit.set = function(pos1, pos2, nodename, env)
2727
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
28-
local env = minetest.env
28+
if env == nil then env = minetest.env end
2929

3030
local node = {name=nodename}
3131
local pos = {x=pos1.x, y=0, z=0}
@@ -45,9 +45,9 @@ worldedit.set = function(pos1, pos2, nodename)
4545
end
4646

4747
--replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced
48-
worldedit.replace = function(pos1, pos2, searchnode, replacenode)
48+
worldedit.replace = function(pos1, pos2, searchnode, replacenode, env)
4949
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
50-
local env = minetest.env
50+
if env == nil then env = minetest.env end
5151

5252
if minetest.registered_nodes[searchnode] == nil then
5353
searchnode = "default:" .. searchnode
@@ -75,9 +75,9 @@ worldedit.replace = function(pos1, pos2, searchnode, replacenode)
7575
end
7676

7777
--replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced
78-
worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
78+
worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode, env)
7979
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
80-
local env = minetest.env
80+
if env == nil then env = minetest.env end
8181

8282
if minetest.registered_nodes[searchnode] == nil then
8383
searchnode = "default:" .. searchnode
@@ -106,9 +106,9 @@ worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
106106
end
107107

108108
--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
109-
worldedit.copy = function(pos1, pos2, axis, amount)
109+
worldedit.copy = function(pos1, pos2, axis, amount, env)
110110
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
111-
local env = minetest.env
111+
if env == nil then env = minetest.env end
112112

113113
if amount < 0 then
114114
local pos = {x=pos1.x, y=0, z=0}
@@ -155,9 +155,9 @@ worldedit.copy = function(pos1, pos2, axis, amount)
155155
end
156156

157157
--moves 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 moved
158-
worldedit.move = function(pos1, pos2, axis, amount)
158+
worldedit.move = function(pos1, pos2, axis, amount, env)
159159
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
160-
local env = minetest.env
160+
if env == nil then env = minetest.env end
161161

162162
if amount < 0 then
163163
local pos = {x=pos1.x, y=0, z=0}
@@ -206,7 +206,7 @@ worldedit.move = function(pos1, pos2, axis, amount)
206206
end
207207

208208
--duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times, returning the number of nodes stacked
209-
worldedit.stack = function(pos1, pos2, axis, count)
209+
worldedit.stack = function(pos1, pos2, axis, count, env)
210210
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
211211
local length = pos2[axis] - pos1[axis] + 1
212212
if count < 0 then
@@ -217,13 +217,13 @@ worldedit.stack = function(pos1, pos2, axis, count)
217217
local copy = worldedit.copy
218218
for i = 1, count do
219219
amount = amount + length
220-
copy(pos1, pos2, axis, amount)
220+
copy(pos1, pos2, axis, amount, env)
221221
end
222222
return worldedit.volume(pos1, pos2)
223223
end
224224

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

229229
local compare
@@ -245,7 +245,7 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
245245
newpos2[axis2] = pos1[axis2] + extent1
246246

247247
local pos = {x=pos1.x, y=0, z=0}
248-
local env = minetest.env
248+
if env == nil then env = minetest.env end
249249
while pos.x <= pos2.x do
250250
pos.y = pos1.y
251251
while pos.y <= pos2.y do
@@ -275,13 +275,13 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
275275
end
276276

277277
--flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z"), returning the number of nodes flipped
278-
worldedit.flip = function(pos1, pos2, axis)
278+
worldedit.flip = function(pos1, pos2, axis, env)
279279
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
280280

281281
local pos = {x=pos1.x, y=0, z=0}
282282
local start = pos1[axis] + pos2[axis]
283283
pos2[axis] = pos1[axis] + math.floor((pos2[axis] - pos1[axis]) / 2)
284-
local env = minetest.env
284+
if env == nil then env = minetest.env end
285285
while pos.x <= pos2.x do
286286
pos.y = pos1.y
287287
while pos.y <= pos2.y do
@@ -308,7 +308,7 @@ worldedit.flip = function(pos1, pos2, axis)
308308
end
309309

310310
--rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around axis `axis` (90 degree increment), returning the number of nodes rotated
311-
worldedit.rotate = function(pos1, pos2, axis, angle)
311+
worldedit.rotate = function(pos1, pos2, axis, angle, env)
312312
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
313313

314314
local axis1, axis2
@@ -323,23 +323,23 @@ worldedit.rotate = function(pos1, pos2, axis, angle)
323323

324324
local count
325325
if angle == 90 then
326-
worldedit.flip(pos1, pos2, axis1)
327-
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
326+
worldedit.flip(pos1, pos2, axis1, env)
327+
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, env)
328328
elseif angle == 180 then
329-
worldedit.flip(pos1, pos2, axis1)
330-
count = worldedit.flip(pos1, pos2, axis2)
329+
worldedit.flip(pos1, pos2, axis1, env)
330+
count = worldedit.flip(pos1, pos2, axis2, env)
331331
elseif angle == 270 then
332-
worldedit.flip(pos1, pos2, axis2)
333-
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
332+
worldedit.flip(pos1, pos2, axis2, env)
333+
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, env)
334334
end
335335
return count, pos1, pos2
336336
end
337337

338338
--rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis, returning the number of nodes oriented
339-
worldedit.orient = function(pos1, pos2, angle)
339+
worldedit.orient = function(pos1, pos2, angle, env)
340340
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
341341
local nodes = minetest.registered_nodes
342-
local env = minetest.env
342+
if env == nil then env = minetest.env end
343343
local wallmounted = {
344344
[90]={[0]=0, [1]=1, [2]=5, [3]=4, [4]=2, [5]=3},
345345
[180]={[0]=0, [1]=1, [2]=3, [3]=2, [4]=5, [5]=4},
@@ -392,9 +392,9 @@ worldedit.orient = function(pos1, pos2, angle)
392392
end
393393

394394
--fixes the lighting in a region defined by positions `pos1` and `pos2`, returning the number of nodes updated
395-
worldedit.fixlight = function(pos1, pos2)
395+
worldedit.fixlight = function(pos1, pos2, env)
396396
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
397-
local env = minetest.env
397+
if env == nil then env = minetest.env end
398398
local count = 0
399399

400400
local pos = {x=pos1.x, y=0, z=0}

‎worldedit/primitives.lua

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
worldedit = worldedit or {}
22

33
--adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
4-
worldedit.hollow_sphere = function(pos, radius, nodename)
4+
worldedit.hollow_sphere = function(pos, radius, nodename, env)
55
local node = {name=nodename}
66
local pos1 = {x=0, y=0, z=0}
77
local min_radius = radius * (radius - 1)
88
local max_radius = radius * (radius + 1)
99
local count = 0
10-
local env = minetest.env
10+
if env == nil then env = minetest.env end
1111
for x = -radius, radius do
1212
pos1.x = pos.x + x
1313
for y = -radius, radius do
@@ -25,12 +25,12 @@ worldedit.hollow_sphere = function(pos, radius, nodename)
2525
end
2626

2727
--adds a sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
28-
worldedit.sphere = function(pos, radius, nodename)
28+
worldedit.sphere = function(pos, radius, nodename, env)
2929
local node = {name=nodename}
3030
local pos1 = {x=0, y=0, z=0}
3131
local max_radius = radius * (radius + 1)
3232
local count = 0
33-
local env = minetest.env
33+
if env == nil then env = minetest.env end
3434
for x = -radius, radius do
3535
pos1.x = pos.x + x
3636
for y = -radius, radius do
@@ -48,13 +48,13 @@ worldedit.sphere = function(pos, radius, nodename)
4848
end
4949

5050
--adds a hollow dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
51-
worldedit.hollow_dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
51+
worldedit.hollow_dome = function(pos, radius, nodename, env) --wip: use bresenham sphere for maximum speed
5252
local node = {name=nodename}
5353
local pos1 = {x=0, y=0, z=0}
5454
local min_radius = radius * (radius - 1)
5555
local max_radius = radius * (radius + 1)
5656
local count = 0
57-
local env = minetest.env
57+
if env == nil then env = minetest.env end
5858
for x = -radius, radius do
5959
pos1.x = pos.x + x
6060
for y = 0, radius do
@@ -72,12 +72,12 @@ worldedit.hollow_dome = function(pos, radius, nodename) --wip: use bresenham sph
7272
end
7373

7474
--adds a dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
75-
worldedit.dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
75+
worldedit.dome = function(pos, radius, nodename, env) --wip: use bresenham sphere for maximum speed
7676
local node = {name=nodename}
7777
local pos1 = {x=0, y=0, z=0}
7878
local max_radius = radius * (radius + 1)
7979
local count = 0
80-
local env = minetest.env
80+
if env == nil then env = minetest.env end
8181
for x = -radius, radius do
8282
pos1.x = pos.x + x
8383
for y = 0, radius do
@@ -95,7 +95,7 @@ worldedit.dome = function(pos, radius, nodename) --wip: use bresenham sphere for
9595
end
9696

9797
--adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added
98-
worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
98+
worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename, env)
9999
local other1, other2
100100
if axis == "x" then
101101
other1, other2 = "y", "z"
@@ -105,7 +105,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
105105
other1, other2 = "x", "y"
106106
end
107107

108-
local env = minetest.env
108+
if env == nil then env = minetest.env end
109109
local currentpos = {x=pos.x, y=pos.y, z=pos.z}
110110
local node = {name=nodename}
111111
local count = 0
@@ -156,7 +156,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
156156
end
157157

158158
--adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added
159-
worldedit.cylinder = function(pos, axis, length, radius, nodename)
159+
worldedit.cylinder = function(pos, axis, length, radius, nodename, env)
160160
local other1, other2
161161
if axis == "x" then
162162
other1, other2 = "y", "z"
@@ -166,7 +166,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
166166
other1, other2 = "x", "y"
167167
end
168168

169-
local env = minetest.env
169+
if env == nil then env = minetest.env end
170170
local currentpos = {x=pos.x, y=pos.y, z=pos.z}
171171
local node = {name=nodename}
172172
local count = 0
@@ -215,14 +215,14 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
215215
end
216216

217217
--adds a pyramid at `pos` with height `height`, composed of `nodename`, returning the number of nodes added
218-
worldedit.pyramid = function(pos, height, nodename)
218+
worldedit.pyramid = function(pos, height, nodename, env)
219219
local pos1x, pos1y, pos1z = pos.x - height, pos.y, pos.z - height
220220
local pos2x, pos2y, pos2z = pos.x + height, pos.y + height, pos.z + height
221221
local pos = {x=0, y=pos1y, z=0}
222222

223223
local count = 0
224224
local node = {name=nodename}
225-
local env = minetest.env
225+
if env == nil then env = minetest.env end
226226
while pos.y <= pos2y do --each vertical level of the pyramid
227227
pos.x = pos1x
228228
while pos.x <= pos2x do
@@ -244,7 +244,7 @@ worldedit.pyramid = function(pos, height, nodename)
244244
end
245245

246246
--adds a spiral at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`, returning the number of nodes added
247-
worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean this up
247+
worldedit.spiral = function(pos, width, height, spacer, nodename, env) --wip: clean this up
248248
-- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua
249249
av, sn = math.abs, function(s) return s~=0 and s/av(s) or 0 end
250250
local function sindex(z, x) -- returns the value at (x, z) in a spiral that starts at 1 and goes outwards
@@ -262,6 +262,7 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t
262262
end
263263
return ret
264264
end
265+
if env == nil then env = minetest.env end
265266
-- connect the joined parts
266267
local spiral = spiralt(width)
267268
height = tonumber(height)
@@ -279,25 +280,25 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t
279280
if lp.x~=np.x then
280281
if lp.x<np.x then
281282
for i=lp.x+1,np.x do
282-
minetest.env:add_node({x=i, y=np.y, z=np.z}, node)
283+
env:add_node({x=i, y=np.y, z=np.z}, node)
283284
count = count + 1
284285
end
285286
else
286287
for i=np.x,lp.x-1 do
287-
minetest.env:add_node({x=i, y=np.y, z=np.z}, node)
288+
env:add_node({x=i, y=np.y, z=np.z}, node)
288289
count = count + 1
289290
end
290291
end
291292
end
292293
if lp.z~=np.z then
293294
if lp.z<np.z then
294295
for i=lp.z+1,np.z do
295-
minetest.env:add_node({x=np.x, y=np.y, z=i}, node)
296+
env:add_node({x=np.x, y=np.y, z=i}, node)
296297
count = count + 1
297298
end
298299
else
299300
for i=np.z,lp.z-1 do
300-
minetest.env:add_node({x=np.x, y=np.y, z=i}, node)
301+
env:add_node({x=np.x, y=np.y, z=i}, node)
301302
count = count + 1
302303
end
303304
end
@@ -307,4 +308,4 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t
307308
end
308309
end
309310
return count
310-
end
311+
end

0 commit comments

Comments
 (0)
Please sign in to comment.