1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2024-12-26 02:30:40 +01:00

Add Block Queue

This commit is contained in:
Sfan5 2013-04-28 19:08:09 +02:00
parent 71b6004b92
commit 5e5c1dc6c3
7 changed files with 292 additions and 84 deletions

View File

@ -12,3 +12,4 @@ loadmodule(path .. "/visualization.lua")
loadmodule(path .. "/serialization.lua") loadmodule(path .. "/serialization.lua")
loadmodule(path .. "/code.lua") loadmodule(path .. "/code.lua")
loadmodule(path .. "/compatibility.lua") loadmodule(path .. "/compatibility.lua")
loadmodule(path .. "/queue.lua")

View File

@ -23,9 +23,9 @@ worldedit.volume = function(pos1, pos2)
end end
--sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled --sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled
worldedit.set = function(pos1, pos2, nodename) worldedit.set = function(pos1, pos2, nodename, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env if env == nil then env = minetest.env end
local node = {name=nodename} local node = {name=nodename}
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}
@ -45,9 +45,9 @@ worldedit.set = function(pos1, pos2, nodename)
end end
--replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced --replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced
worldedit.replace = function(pos1, pos2, searchnode, replacenode) worldedit.replace = function(pos1, pos2, searchnode, replacenode, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env if env == nil then env = minetest.env end
if minetest.registered_nodes[searchnode] == nil then if minetest.registered_nodes[searchnode] == nil then
searchnode = "default:" .. searchnode searchnode = "default:" .. searchnode
@ -75,9 +75,9 @@ worldedit.replace = function(pos1, pos2, searchnode, replacenode)
end end
--replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced --replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced
worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode) worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env if env == nil then env = minetest.env end
if minetest.registered_nodes[searchnode] == nil then if minetest.registered_nodes[searchnode] == nil then
searchnode = "default:" .. searchnode searchnode = "default:" .. searchnode
@ -106,9 +106,9 @@ worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
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
worldedit.copy = function(pos1, pos2, axis, amount) worldedit.copy = function(pos1, pos2, axis, amount, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env if env == nil then env = minetest.env end
if amount < 0 then if amount < 0 then
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}
@ -155,9 +155,9 @@ worldedit.copy = function(pos1, pos2, axis, amount)
end end
--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 --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
worldedit.move = function(pos1, pos2, axis, amount) worldedit.move = function(pos1, pos2, axis, amount, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env if env == nil then env = minetest.env end
if amount < 0 then if amount < 0 then
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}
@ -206,7 +206,7 @@ worldedit.move = function(pos1, pos2, axis, amount)
end end
--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 --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
worldedit.stack = function(pos1, pos2, axis, count) worldedit.stack = function(pos1, pos2, axis, count, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local length = pos2[axis] - pos1[axis] + 1 local length = pos2[axis] - pos1[axis] + 1
if count < 0 then if count < 0 then
@ -217,13 +217,13 @@ worldedit.stack = function(pos1, pos2, axis, count)
local copy = worldedit.copy local copy = worldedit.copy
for i = 1, count do for i = 1, count do
amount = amount + length amount = amount + length
copy(pos1, pos2, axis, amount) copy(pos1, pos2, axis, amount, env)
end end
return worldedit.volume(pos1, pos2) return worldedit.volume(pos1, pos2)
end end
--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 --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
worldedit.transpose = function(pos1, pos2, axis1, axis2) worldedit.transpose = function(pos1, pos2, axis1, axis2, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local compare local compare
@ -245,7 +245,7 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
newpos2[axis2] = pos1[axis2] + extent1 newpos2[axis2] = pos1[axis2] + extent1
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}
local env = minetest.env if env == nil then env = minetest.env end
while pos.x <= pos2.x do while pos.x <= pos2.x do
pos.y = pos1.y pos.y = pos1.y
while pos.y <= pos2.y do while pos.y <= pos2.y do
@ -275,13 +275,13 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
end end
--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 --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
worldedit.flip = function(pos1, pos2, axis) worldedit.flip = function(pos1, pos2, axis, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}
local start = pos1[axis] + pos2[axis] local start = pos1[axis] + pos2[axis]
pos2[axis] = pos1[axis] + math.floor((pos2[axis] - pos1[axis]) / 2) pos2[axis] = pos1[axis] + math.floor((pos2[axis] - pos1[axis]) / 2)
local env = minetest.env if env == nil then env = minetest.env end
while pos.x <= pos2.x do while pos.x <= pos2.x do
pos.y = pos1.y pos.y = pos1.y
while pos.y <= pos2.y do while pos.y <= pos2.y do
@ -308,7 +308,7 @@ worldedit.flip = function(pos1, pos2, axis)
end end
--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 --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
worldedit.rotate = function(pos1, pos2, axis, angle) worldedit.rotate = function(pos1, pos2, axis, angle, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local axis1, axis2 local axis1, axis2
@ -323,23 +323,23 @@ worldedit.rotate = function(pos1, pos2, axis, angle)
local count local count
if angle == 90 then if angle == 90 then
worldedit.flip(pos1, pos2, axis1) worldedit.flip(pos1, pos2, axis1, env)
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2) count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, env)
elseif angle == 180 then elseif angle == 180 then
worldedit.flip(pos1, pos2, axis1) worldedit.flip(pos1, pos2, axis1, env)
count = worldedit.flip(pos1, pos2, axis2) count = worldedit.flip(pos1, pos2, axis2, env)
elseif angle == 270 then elseif angle == 270 then
worldedit.flip(pos1, pos2, axis2) worldedit.flip(pos1, pos2, axis2, env)
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2) count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, env)
end end
return count, pos1, pos2 return count, pos1, pos2
end end
--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 --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
worldedit.orient = function(pos1, pos2, angle) worldedit.orient = function(pos1, pos2, angle, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local nodes = minetest.registered_nodes local nodes = minetest.registered_nodes
local env = minetest.env if env == nil then env = minetest.env end
local wallmounted = { local wallmounted = {
[90]={[0]=0, [1]=1, [2]=5, [3]=4, [4]=2, [5]=3}, [90]={[0]=0, [1]=1, [2]=5, [3]=4, [4]=2, [5]=3},
[180]={[0]=0, [1]=1, [2]=3, [3]=2, [4]=5, [5]=4}, [180]={[0]=0, [1]=1, [2]=3, [3]=2, [4]=5, [5]=4},
@ -392,9 +392,9 @@ worldedit.orient = function(pos1, pos2, angle)
end end
--fixes the lighting in a region defined by positions `pos1` and `pos2`, returning the number of nodes updated --fixes the lighting in a region defined by positions `pos1` and `pos2`, returning the number of nodes updated
worldedit.fixlight = function(pos1, pos2) worldedit.fixlight = function(pos1, pos2, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env if env == nil then env = minetest.env end
local count = 0 local count = 0
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}

View File

@ -1,13 +1,13 @@
worldedit = worldedit or {} worldedit = worldedit or {}
--adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added --adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.hollow_sphere = function(pos, radius, nodename) worldedit.hollow_sphere = function(pos, radius, nodename, env)
local node = {name=nodename} local node = {name=nodename}
local pos1 = {x=0, y=0, z=0} local pos1 = {x=0, y=0, z=0}
local min_radius = radius * (radius - 1) local min_radius = radius * (radius - 1)
local max_radius = radius * (radius + 1) local max_radius = radius * (radius + 1)
local count = 0 local count = 0
local env = minetest.env if env == nil then env = minetest.env end
for x = -radius, radius do for x = -radius, radius do
pos1.x = pos.x + x pos1.x = pos.x + x
for y = -radius, radius do for y = -radius, radius do
@ -25,12 +25,12 @@ worldedit.hollow_sphere = function(pos, radius, nodename)
end end
--adds a sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added --adds a sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.sphere = function(pos, radius, nodename) worldedit.sphere = function(pos, radius, nodename, env)
local node = {name=nodename} local node = {name=nodename}
local pos1 = {x=0, y=0, z=0} local pos1 = {x=0, y=0, z=0}
local max_radius = radius * (radius + 1) local max_radius = radius * (radius + 1)
local count = 0 local count = 0
local env = minetest.env if env == nil then env = minetest.env end
for x = -radius, radius do for x = -radius, radius do
pos1.x = pos.x + x pos1.x = pos.x + x
for y = -radius, radius do for y = -radius, radius do
@ -48,13 +48,13 @@ worldedit.sphere = function(pos, radius, nodename)
end end
--adds a hollow dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added --adds a hollow dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.hollow_dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed worldedit.hollow_dome = function(pos, radius, nodename, env) --wip: use bresenham sphere for maximum speed
local node = {name=nodename} local node = {name=nodename}
local pos1 = {x=0, y=0, z=0} local pos1 = {x=0, y=0, z=0}
local min_radius = radius * (radius - 1) local min_radius = radius * (radius - 1)
local max_radius = radius * (radius + 1) local max_radius = radius * (radius + 1)
local count = 0 local count = 0
local env = minetest.env if env == nil then env = minetest.env end
for x = -radius, radius do for x = -radius, radius do
pos1.x = pos.x + x pos1.x = pos.x + x
for y = 0, radius do for y = 0, radius do
@ -72,12 +72,12 @@ worldedit.hollow_dome = function(pos, radius, nodename) --wip: use bresenham sph
end end
--adds a dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added --adds a dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed worldedit.dome = function(pos, radius, nodename, env) --wip: use bresenham sphere for maximum speed
local node = {name=nodename} local node = {name=nodename}
local pos1 = {x=0, y=0, z=0} local pos1 = {x=0, y=0, z=0}
local max_radius = radius * (radius + 1) local max_radius = radius * (radius + 1)
local count = 0 local count = 0
local env = minetest.env if env == nil then env = minetest.env end
for x = -radius, radius do for x = -radius, radius do
pos1.x = pos.x + x pos1.x = pos.x + x
for y = 0, radius do for y = 0, radius do
@ -95,7 +95,7 @@ worldedit.dome = function(pos, radius, nodename) --wip: use bresenham sphere for
end end
--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 --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
worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename) worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename, env)
local other1, other2 local other1, other2
if axis == "x" then if axis == "x" then
other1, other2 = "y", "z" other1, other2 = "y", "z"
@ -105,7 +105,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
other1, other2 = "x", "y" other1, other2 = "x", "y"
end end
local env = minetest.env if env == nil then env = minetest.env end
local currentpos = {x=pos.x, y=pos.y, z=pos.z} local currentpos = {x=pos.x, y=pos.y, z=pos.z}
local node = {name=nodename} local node = {name=nodename}
local count = 0 local count = 0
@ -156,7 +156,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
end end
--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 --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
worldedit.cylinder = function(pos, axis, length, radius, nodename) worldedit.cylinder = function(pos, axis, length, radius, nodename, env)
local other1, other2 local other1, other2
if axis == "x" then if axis == "x" then
other1, other2 = "y", "z" other1, other2 = "y", "z"
@ -166,7 +166,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
other1, other2 = "x", "y" other1, other2 = "x", "y"
end end
local env = minetest.env if env == nil then env = minetest.env end
local currentpos = {x=pos.x, y=pos.y, z=pos.z} local currentpos = {x=pos.x, y=pos.y, z=pos.z}
local node = {name=nodename} local node = {name=nodename}
local count = 0 local count = 0
@ -215,14 +215,14 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
end end
--adds a pyramid at `pos` with height `height`, composed of `nodename`, returning the number of nodes added --adds a pyramid at `pos` with height `height`, composed of `nodename`, returning the number of nodes added
worldedit.pyramid = function(pos, height, nodename) worldedit.pyramid = function(pos, height, nodename, env)
local pos1x, pos1y, pos1z = pos.x - height, pos.y, pos.z - height local pos1x, pos1y, pos1z = pos.x - height, pos.y, pos.z - height
local pos2x, pos2y, pos2z = pos.x + height, pos.y + height, pos.z + height local pos2x, pos2y, pos2z = pos.x + height, pos.y + height, pos.z + height
local pos = {x=0, y=pos1y, z=0} local pos = {x=0, y=pos1y, z=0}
local count = 0 local count = 0
local node = {name=nodename} local node = {name=nodename}
local env = minetest.env if env == nil then env = minetest.env end
while pos.y <= pos2y do --each vertical level of the pyramid while pos.y <= pos2y do --each vertical level of the pyramid
pos.x = pos1x pos.x = pos1x
while pos.x <= pos2x do while pos.x <= pos2x do
@ -244,7 +244,7 @@ worldedit.pyramid = function(pos, height, nodename)
end end
--adds a spiral at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`, returning the number of nodes added --adds a spiral at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`, returning the number of nodes added
worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean this up worldedit.spiral = function(pos, width, height, spacer, nodename, env) --wip: clean this up
-- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua -- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua
av, sn = math.abs, function(s) return s~=0 and s/av(s) or 0 end av, sn = math.abs, function(s) return s~=0 and s/av(s) or 0 end
local function sindex(z, x) -- returns the value at (x, z) in a spiral that starts at 1 and goes outwards 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
end end
return ret return ret
end end
if env == nil then env = minetest.env end
-- connect the joined parts -- connect the joined parts
local spiral = spiralt(width) local spiral = spiralt(width)
height = tonumber(height) height = tonumber(height)
@ -279,12 +280,12 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t
if lp.x~=np.x then if lp.x~=np.x then
if lp.x<np.x then if lp.x<np.x then
for i=lp.x+1,np.x do for i=lp.x+1,np.x do
minetest.env:add_node({x=i, y=np.y, z=np.z}, node) env:add_node({x=i, y=np.y, z=np.z}, node)
count = count + 1 count = count + 1
end end
else else
for i=np.x,lp.x-1 do for i=np.x,lp.x-1 do
minetest.env:add_node({x=i, y=np.y, z=np.z}, node) env:add_node({x=i, y=np.y, z=np.z}, node)
count = count + 1 count = count + 1
end end
end end
@ -292,12 +293,12 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t
if lp.z~=np.z then if lp.z~=np.z then
if lp.z<np.z then if lp.z<np.z then
for i=lp.z+1,np.z do for i=lp.z+1,np.z do
minetest.env:add_node({x=np.x, y=np.y, z=i}, node) env:add_node({x=np.x, y=np.y, z=i}, node)
count = count + 1 count = count + 1
end end
else else
for i=np.z,lp.z-1 do for i=np.z,lp.z-1 do
minetest.env:add_node({x=np.x, y=np.y, z=i}, node) env:add_node({x=np.x, y=np.y, z=i}, node)
count = count + 1 count = count + 1
end end
end end

108
worldedit/queue.lua Normal file
View File

@ -0,0 +1,108 @@
worldedit = worldedit or {}
worldedit.queue = {}
worldedit.ENABLE_QUEUE = true
worldedit.BLOCKS_PER_GLOBALSTEP = 512
minetest.register_globalstep(function(dtime)
i = 1
while i <= #worldedit.queue and i <= worldedit.BLOCKS_PER_GLOBALSTEP do
idx = (#worldedit.queue + 1) - i -- we use the last entry, so we don't spend days moving stuff in the table because we removed the first entry
if worldedit.queue[idx].t == "set_node" then
minetest.env:set_node(worldedit.queue[idx].pos, worldedit.queue[idx].node)
elseif worldedit.queue[idx].t == "remove_node" then
minetest.env:remove_node(worldedit.queue[idx].pos)
elseif worldedit.queue[idx].t == "place_node" then
minetest.env:place_node(worldedit.queue[idx].pos, worldedit.queue[idx].node)
elseif worldedit.queue[idx].t == "dig_node" then
minetest.env:dig_node(worldedit.queue[idx].pos)
elseif worldedit.queue[idx].t == "add_entity" then
minetest.env:add_entity(worldedit.queue[idx].pos, worldedit.queue[idx].name)
elseif worldedit.queue[idx].t == "add_item" then
minetest.env:add_item(worldedit.queue[idx].pos, worldedit.queue[idx].item)
elseif worldedit.queue[idx].t == "meta_from_table" then
minetest.env:get_meta(worldedit.queue[idx].pos):from_table(worldedit.queue[idx].table)
else
print("Unknown queue event type: " .. worldedit.queue[idx].t)
end
table.remove(worldedit.queue, idx)
i = i + 1
end
end)
function table.copy(t, seen)
seen = seen or {}
if t == nil then return nil end
if seen[t] then return seen[t] end
local nt = {}
for k, v in pairs(t) do
if type(v) == 'table' then
nt[k] = table.copy(v, seen)
else
nt[k] = v
end
end
seen[t] = nt
return nt
end
local quene_setnode = function(self, pos_, node_)
table.insert(worldedit.queue, {pos=table.copy(pos_), node=table.copy(node_), t="set_node"})
end
local quene_removenode = function(self, pos_)
table.insert(worldedit.queue, {pos=table.copy(pos_), t="remove_node"})
end
local quene_placenode = function(self, pos_, node_)
table.insert(worldedit.queue, {pos=table.copy(pos_), node=table.copy(node_), t="place_node"})
end
local quene_dignode = function(self, pos_)
table.insert(worldedit.queue, {pos=table.copy(pos_), t="dig_node"})
end
local quene_addentity = function(self, pos_, name_)
table.insert(worldedit.queue, {pos=table.copy(pos_), name=name_.."", t="add_entity"})
end
local quene_additem = function(self, pos_, item_)
table.insert(worldedit.queue, {pos=table.copy(pos_), item=item_.."", t="add_item"})
end
local quene_setmeta = function(self, pos_, table_)
table.insert(worldedit.queue, {pos=table.copy(pos_), table=table.copy(table_), t="meta_from_table"})
end
local aliasmeta = {
-- the other functions are left out because they are not used in worldedit
to_table = function(self) return minetest.env:get_meta(self._pos):to_table() end,
set_string = function(self, name_, value_) minetest.env:get_meta(self._pos):set_string(name_, value_) end,
from_table = function(self, tbl) quene_setmeta(nil, self._pos, tbl) end,
}
local get_meta_alias = function(self, pos)
local am = table.copy(aliasmeta)
am._pos = pos
return am
end
worldedit.quene_aliasenv = {
-- ALL functions that are not just piped to the real minetest.env function must copy the arguments, not just reference them
set_node = quene_setnode,
add_node = quene_setnode,
remove_node = quene_removenode,
get_node = function(self, pos) return minetest.env:get_node(pos) end,
get_node_or_nil = function(self, pos) return minetest.env:get_node_or_nil(pos) end,
get_node_light = function(self, pos, timeofday) return minetest.env:get_node_light(pos, timeofday) end,
place_node = quene_placenode,
dig_node = quene_dignode,
punch_node = function(self, pos) return minetest.env:punch_node(pos) end,
get_meta = get_meta_alias,
get_node_timer = function(self, pos) return minetest.env:get_node_timer(pos) end,
add_entity = quene_addentity,
add_item = quene_additem,
}

View File

@ -160,10 +160,10 @@ end
--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized --loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized
--contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible) --contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)
worldedit.deserialize = function(originpos, value) worldedit.deserialize = function(originpos, value, env)
local originx, originy, originz = originpos.x, originpos.y, originpos.z local originx, originy, originz = originpos.x, originpos.y, originpos.z
local count = 0 local count = 0
local env = minetest.env if env == nil then env = minetest.env end
local version = worldedit.valueversion(value) local version = worldedit.valueversion(value)
if version == 1 or version == 2 then --original flat table format if version == 1 or version == 2 then --original flat table format
--obtain the node table --obtain the node table

View File

@ -31,9 +31,9 @@ minetest.register_node("worldedit:placeholder", {
}) })
--hides all nodes in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes, returning the number of nodes hidden --hides all nodes in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes, returning the number of nodes hidden
worldedit.hide = function(pos1, pos2) worldedit.hide = function(pos1, pos2, tenv)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env if env == nil then env = minetest.env end
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}
local placeholder = {name="worldedit:placeholder", param1=0, param2=0} local placeholder = {name="worldedit:placeholder", param1=0, param2=0}
@ -59,9 +59,9 @@ worldedit.hide = function(pos1, pos2)
end end
--suppresses all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes, returning the number of nodes suppressed --suppresses all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes, returning the number of nodes suppressed
worldedit.suppress = function(pos1, pos2, nodename) worldedit.suppress = function(pos1, pos2, nodename, tenv)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env if env == nil then env = minetest.env end
if minetest.registered_nodes[nodename] == nil then if minetest.registered_nodes[nodename] == nil then
nodename = "default:" .. nodename nodename = "default:" .. nodename
@ -95,9 +95,9 @@ worldedit.suppress = function(pos1, pos2, nodename)
end end
--highlights all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes, returning the number of nodes found --highlights all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes, returning the number of nodes found
worldedit.highlight = function(pos1, pos2, nodename) worldedit.highlight = function(pos1, pos2, nodename, tenv)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env if env == nil then env = minetest.env end
if minetest.registered_nodes[nodename] == nil then if minetest.registered_nodes[nodename] == nil then
nodename = "default:" .. nodename nodename = "default:" .. nodename
@ -132,9 +132,9 @@ worldedit.highlight = function(pos1, pos2, nodename)
end end
--restores all nodes hidden with WorldEdit functions in a region defined by positions `pos1` and `pos2`, returning the number of nodes restored --restores all nodes hidden with WorldEdit functions in a region defined by positions `pos1` and `pos2`, returning the number of nodes restored
worldedit.restore = function(pos1, pos2) worldedit.restore = function(pos1, pos2, tenv)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local env = minetest.env if env == nil then env = minetest.env end
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}
local node = {name="", param1=0, param2=0} local node = {name="", param1=0, param2=0}

View File

@ -162,7 +162,11 @@ minetest.register_chatcommand("/set", {
return return
end end
local count = worldedit.set(pos1, pos2, param) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.set(pos1, pos2, param, tenv)
minetest.chat_send_player(name, count .. " nodes set", false) minetest.chat_send_player(name, count .. " nodes set", false)
end, end,
}) })
@ -192,7 +196,11 @@ minetest.register_chatcommand("/replace", {
return return
end end
local count = worldedit.replace(pos1, pos2, searchnode, replacenode) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.replace(pos1, pos2, searchnode, replacenode, tenv)
minetest.chat_send_player(name, count .. " nodes replaced", false) minetest.chat_send_player(name, count .. " nodes replaced", false)
end, end,
}) })
@ -222,7 +230,11 @@ minetest.register_chatcommand("/replaceinverse", {
return return
end end
local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode, tenv)
minetest.chat_send_player(name, count .. " nodes replaced", false) minetest.chat_send_player(name, count .. " nodes replaced", false)
end, end,
}) })
@ -248,7 +260,11 @@ minetest.register_chatcommand("/hollowsphere", {
return return
end end
local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename, tenv)
minetest.chat_send_player(name, count .. " nodes added", false) minetest.chat_send_player(name, count .. " nodes added", false)
end, end,
}) })
@ -274,7 +290,11 @@ minetest.register_chatcommand("/sphere", {
return return
end end
local count = worldedit.sphere(pos, tonumber(radius), nodename) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.sphere(pos, tonumber(radius), nodename, tenv)
minetest.chat_send_player(name, count .. " nodes added", false) minetest.chat_send_player(name, count .. " nodes added", false)
end, end,
}) })
@ -300,7 +320,11 @@ minetest.register_chatcommand("/hollowdome", {
return return
end end
local count = worldedit.hollow_dome(pos, tonumber(radius), nodename) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.hollow_dome(pos, tonumber(radius), nodename, tenv)
minetest.chat_send_player(name, count .. " nodes added", false) minetest.chat_send_player(name, count .. " nodes added", false)
end, end,
}) })
@ -326,7 +350,11 @@ minetest.register_chatcommand("/dome", {
return return
end end
local count = worldedit.dome(pos, tonumber(radius), nodename) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.dome(pos, tonumber(radius), nodename, tenv)
minetest.chat_send_player(name, count .. " nodes added", false) minetest.chat_send_player(name, count .. " nodes added", false)
end, end,
}) })
@ -356,7 +384,11 @@ minetest.register_chatcommand("/hollowcylinder", {
return return
end end
local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), nodename) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), nodename, tenv)
minetest.chat_send_player(name, count .. " nodes added", false) minetest.chat_send_player(name, count .. " nodes added", false)
end, end,
}) })
@ -386,7 +418,11 @@ minetest.register_chatcommand("/cylinder", {
return return
end end
local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), nodename) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), nodename, tenv)
minetest.chat_send_player(name, count .. " nodes added", false) minetest.chat_send_player(name, count .. " nodes added", false)
end, end,
}) })
@ -412,7 +448,11 @@ minetest.register_chatcommand("/pyramid", {
return return
end end
local count = worldedit.pyramid(pos, tonumber(size), nodename) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.pyramid(pos, tonumber(size), nodename, tenv)
minetest.chat_send_player(name, count .. " nodes added", false) minetest.chat_send_player(name, count .. " nodes added", false)
end, end,
}) })
@ -438,7 +478,11 @@ minetest.register_chatcommand("/spiral", {
return return
end end
local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), nodename) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), nodename, tenv)
minetest.chat_send_player(name, count .. " nodes changed", false) minetest.chat_send_player(name, count .. " nodes changed", false)
end, end,
}) })
@ -464,7 +508,11 @@ minetest.register_chatcommand("/copy", {
amount = amount * sign amount = amount * sign
end end
local count = worldedit.copy(pos1, pos2, axis, tonumber(amount)) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)
minetest.chat_send_player(name, count .. " nodes copied", false) minetest.chat_send_player(name, count .. " nodes copied", false)
end, end,
}) })
@ -497,6 +545,11 @@ minetest.register_chatcommand("/move", {
worldedit.mark_pos1(name) worldedit.mark_pos1(name)
worldedit.mark_pos2(name) worldedit.mark_pos2(name)
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)
minetest.chat_send_player(name, count .. " nodes moved", false) minetest.chat_send_player(name, count .. " nodes moved", false)
end, end,
}) })
@ -522,7 +575,11 @@ minetest.register_chatcommand("/stack", {
count = count * sign count = count * sign
end end
local count = worldedit.stack(pos1, pos2, axis, tonumber(count)) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.stack(pos1, pos2, axis, tonumber(count), tenv)
minetest.chat_send_player(name, count .. " nodes stacked", false) minetest.chat_send_player(name, count .. " nodes stacked", false)
end, end,
}) })
@ -554,7 +611,11 @@ minetest.register_chatcommand("/transpose", {
return return
end end
local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, tenv)
--reset markers to transposed positions --reset markers to transposed positions
worldedit.pos1[name] = pos1 worldedit.pos1[name] = pos1
@ -585,7 +646,11 @@ minetest.register_chatcommand("/flip", {
return return
end end
local count = worldedit.flip(pos1, pos2, param) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.flip(pos1, pos2, param, tenv)
minetest.chat_send_player(name, count .. " nodes flipped", false) minetest.chat_send_player(name, count .. " nodes flipped", false)
end, end,
}) })
@ -614,7 +679,11 @@ minetest.register_chatcommand("/rotate", {
return return
end end
local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle, tenv)
--reset markers to rotated positions --reset markers to rotated positions
worldedit.pos1[name] = pos1 worldedit.pos1[name] = pos1
@ -647,7 +716,11 @@ minetest.register_chatcommand("/orient", {
return return
end end
local count = worldedit.orient(pos1, pos2, angle) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.orient(pos1, pos2, angle, tenv)
minetest.chat_send_player(name, count .. " nodes oriented", false) minetest.chat_send_player(name, count .. " nodes oriented", false)
end, end,
@ -664,7 +737,11 @@ minetest.register_chatcommand("/fixlight", {
return return
end end
local count = worldedit.fixlight(pos1, pos2) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.fixlight(pos1, pos2, tenv)
minetest.chat_send_player(name, count .. " nodes updated", false) minetest.chat_send_player(name, count .. " nodes updated", false)
end, end,
}) })
@ -680,7 +757,11 @@ minetest.register_chatcommand("/hide", {
return return
end end
local count = worldedit.hide(pos1, pos2) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.hide(pos1, pos2, tenv)
minetest.chat_send_player(name, count .. " nodes hidden", false) minetest.chat_send_player(name, count .. " nodes hidden", false)
end, end,
}) })
@ -701,7 +782,11 @@ minetest.register_chatcommand("/suppress", {
return return
end end
local count = worldedit.suppress(pos1, pos2, param) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.suppress(pos1, pos2, param, tenv)
minetest.chat_send_player(name, count .. " nodes suppressed", false) minetest.chat_send_player(name, count .. " nodes suppressed", false)
end, end,
}) })
@ -722,7 +807,11 @@ minetest.register_chatcommand("/highlight", {
return return
end end
local count = worldedit.highlight(pos1, pos2, param) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.highlight(pos1, pos2, param, tenv)
minetest.chat_send_player(name, count .. " nodes highlighted", false) minetest.chat_send_player(name, count .. " nodes highlighted", false)
end, end,
}) })
@ -738,7 +827,11 @@ minetest.register_chatcommand("/restore", {
return return
end end
local count = worldedit.restore(pos1, pos2) local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.restore(pos1, pos2, tenv)
minetest.chat_send_player(name, count .. " nodes restored", false) minetest.chat_send_player(name, count .. " nodes restored", false)
end, end,
}) })
@ -857,7 +950,12 @@ minetest.register_chatcommand("/load", {
minetest.chat_send_player(name, "Invalid file: file is invalid or created with newer version of WorldEdit", false) minetest.chat_send_player(name, "Invalid file: file is invalid or created with newer version of WorldEdit", false)
return return
end end
local count = worldedit.deserialize(pos1, value)
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.quene_aliasenv
end
local count = worldedit.deserialize(pos1, value, tenv)
minetest.chat_send_player(name, count .. " nodes loaded", false) minetest.chat_send_player(name, count .. " nodes loaded", false)
end, end,