summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSfan5 <sfan5@live.de>2013-04-28 19:08:09 +0200
committerSfan5 <sfan5@live.de>2013-04-28 19:08:09 +0200
commit5e5c1dc6c3a4aa26f094bbb998829d663dcda777 (patch)
tree1cccee98fd369b2af5d1cdee92435e427f498ca5
parent71b6004b928766abc3638aaca3526b80af642140 (diff)
Add Block Queue
-rw-r--r--worldedit/init.lua3
-rw-r--r--worldedit/manipulations.lua54
-rw-r--r--worldedit/primitives.lua41
-rw-r--r--worldedit/queue.lua108
-rw-r--r--worldedit/serialization.lua6
-rw-r--r--worldedit/visualization.lua18
-rw-r--r--worldedit_commands/init.lua146
7 files changed, 292 insertions, 84 deletions
diff --git a/worldedit/init.lua b/worldedit/init.lua
index f3eb9bb..fb4a0c8 100644
--- a/worldedit/init.lua
+++ b/worldedit/init.lua
@@ -11,4 +11,5 @@ loadmodule(path .. "/primitives.lua")
loadmodule(path .. "/visualization.lua")
loadmodule(path .. "/serialization.lua")
loadmodule(path .. "/code.lua")
-loadmodule(path .. "/compatibility.lua") \ No newline at end of file
+loadmodule(path .. "/compatibility.lua")
+loadmodule(path .. "/queue.lua")
diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua
index a38467d..71ff61e 100644
--- a/worldedit/manipulations.lua
+++ b/worldedit/manipulations.lua
@@ -23,9 +23,9 @@ worldedit.volume = function(pos1, pos2)
end
--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 env = minetest.env
+ if env == nil then env = minetest.env end
local node = {name=nodename}
local pos = {x=pos1.x, y=0, z=0}
@@ -45,9 +45,9 @@ worldedit.set = function(pos1, pos2, nodename)
end
--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 env = minetest.env
+ if env == nil then env = minetest.env end
if minetest.registered_nodes[searchnode] == nil then
searchnode = "default:" .. searchnode
@@ -75,9 +75,9 @@ worldedit.replace = function(pos1, pos2, searchnode, replacenode)
end
--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 env = minetest.env
+ if env == nil then env = minetest.env end
if minetest.registered_nodes[searchnode] == nil then
searchnode = "default:" .. searchnode
@@ -106,9 +106,9 @@ worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
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
-worldedit.copy = function(pos1, pos2, axis, amount)
+worldedit.copy = function(pos1, pos2, axis, amount, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
- local env = minetest.env
+ if env == nil then env = minetest.env end
if amount < 0 then
local pos = {x=pos1.x, y=0, z=0}
@@ -155,9 +155,9 @@ worldedit.copy = function(pos1, pos2, axis, amount)
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
-worldedit.move = function(pos1, pos2, axis, amount)
+worldedit.move = function(pos1, pos2, axis, amount, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
- local env = minetest.env
+ if env == nil then env = minetest.env end
if amount < 0 then
local pos = {x=pos1.x, y=0, z=0}
@@ -206,7 +206,7 @@ worldedit.move = function(pos1, pos2, axis, amount)
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
-worldedit.stack = function(pos1, pos2, axis, count)
+worldedit.stack = function(pos1, pos2, axis, count, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local length = pos2[axis] - pos1[axis] + 1
if count < 0 then
@@ -217,13 +217,13 @@ worldedit.stack = function(pos1, pos2, axis, count)
local copy = worldedit.copy
for i = 1, count do
amount = amount + length
- copy(pos1, pos2, axis, amount)
+ copy(pos1, pos2, axis, amount, env)
end
return worldedit.volume(pos1, pos2)
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
-worldedit.transpose = function(pos1, pos2, axis1, axis2)
+worldedit.transpose = function(pos1, pos2, axis1, axis2, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local compare
@@ -245,7 +245,7 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
newpos2[axis2] = pos1[axis2] + extent1
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
pos.y = pos1.y
while pos.y <= pos2.y do
@@ -275,13 +275,13 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2)
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
-worldedit.flip = function(pos1, pos2, axis)
+worldedit.flip = function(pos1, pos2, axis, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local pos = {x=pos1.x, y=0, z=0}
local start = pos1[axis] + pos2[axis]
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
pos.y = pos1.y
while pos.y <= pos2.y do
@@ -308,7 +308,7 @@ worldedit.flip = function(pos1, pos2, axis)
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
-worldedit.rotate = function(pos1, pos2, axis, angle)
+worldedit.rotate = function(pos1, pos2, axis, angle, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local axis1, axis2
@@ -323,23 +323,23 @@ worldedit.rotate = function(pos1, pos2, axis, angle)
local count
if angle == 90 then
- worldedit.flip(pos1, pos2, axis1)
- count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
+ worldedit.flip(pos1, pos2, axis1, env)
+ count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, env)
elseif angle == 180 then
- worldedit.flip(pos1, pos2, axis1)
- count = worldedit.flip(pos1, pos2, axis2)
+ worldedit.flip(pos1, pos2, axis1, env)
+ count = worldedit.flip(pos1, pos2, axis2, env)
elseif angle == 270 then
- worldedit.flip(pos1, pos2, axis2)
- count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
+ worldedit.flip(pos1, pos2, axis2, env)
+ count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, env)
end
return count, pos1, pos2
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
-worldedit.orient = function(pos1, pos2, angle)
+worldedit.orient = function(pos1, pos2, angle, env)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local nodes = minetest.registered_nodes
- local env = minetest.env
+ if env == nil then env = minetest.env end
local wallmounted = {
[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},
@@ -392,9 +392,9 @@ worldedit.orient = function(pos1, pos2, angle)
end
--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 env = minetest.env
+ if env == nil then env = minetest.env end
local count = 0
local pos = {x=pos1.x, y=0, z=0}
diff --git a/worldedit/primitives.lua b/worldedit/primitives.lua
index 8dfe88e..d0c93a7 100644
--- a/worldedit/primitives.lua
+++ b/worldedit/primitives.lua
@@ -1,13 +1,13 @@
worldedit = worldedit or {}
--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 pos1 = {x=0, y=0, z=0}
local min_radius = radius * (radius - 1)
local max_radius = radius * (radius + 1)
local count = 0
- local env = minetest.env
+ if env == nil then env = minetest.env end
for x = -radius, radius do
pos1.x = pos.x + x
for y = -radius, radius do
@@ -25,12 +25,12 @@ worldedit.hollow_sphere = function(pos, radius, nodename)
end
--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 pos1 = {x=0, y=0, z=0}
local max_radius = radius * (radius + 1)
local count = 0
- local env = minetest.env
+ if env == nil then env = minetest.env end
for x = -radius, radius do
pos1.x = pos.x + x
for y = -radius, radius do
@@ -48,13 +48,13 @@ worldedit.sphere = function(pos, radius, nodename)
end
--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 pos1 = {x=0, y=0, z=0}
local min_radius = radius * (radius - 1)
local max_radius = radius * (radius + 1)
local count = 0
- local env = minetest.env
+ if env == nil then env = minetest.env end
for x = -radius, radius do
pos1.x = pos.x + x
for y = 0, radius do
@@ -72,12 +72,12 @@ worldedit.hollow_dome = function(pos, radius, nodename) --wip: use bresenham sph
end
--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 pos1 = {x=0, y=0, z=0}
local max_radius = radius * (radius + 1)
local count = 0
- local env = minetest.env
+ if env == nil then env = minetest.env end
for x = -radius, radius do
pos1.x = pos.x + x
for y = 0, radius do
@@ -95,7 +95,7 @@ worldedit.dome = function(pos, radius, nodename) --wip: use bresenham sphere for
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
-worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
+worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename, env)
local other1, other2
if axis == "x" then
other1, other2 = "y", "z"
@@ -105,7 +105,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
other1, other2 = "x", "y"
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 node = {name=nodename}
local count = 0
@@ -156,7 +156,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
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
-worldedit.cylinder = function(pos, axis, length, radius, nodename)
+worldedit.cylinder = function(pos, axis, length, radius, nodename, env)
local other1, other2
if axis == "x" then
other1, other2 = "y", "z"
@@ -166,7 +166,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
other1, other2 = "x", "y"
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 node = {name=nodename}
local count = 0
@@ -215,14 +215,14 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
end
--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 pos2x, pos2y, pos2z = pos.x + height, pos.y + height, pos.z + height
local pos = {x=0, y=pos1y, z=0}
local count = 0
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
pos.x = pos1x
while pos.x <= pos2x do
@@ -244,7 +244,7 @@ worldedit.pyramid = function(pos, height, nodename)
end
--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
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
@@ -262,6 +262,7 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t
end
return ret
end
+ if env == nil then env = minetest.env end
-- connect the joined parts
local spiral = spiralt(width)
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
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
end
else
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
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
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
end
else
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
end
end
@@ -307,4 +308,4 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t
end
end
return count
-end \ No newline at end of file
+end
diff --git a/worldedit/queue.lua b/worldedit/queue.lua
new file mode 100644
index 0000000..77b0fdc
--- /dev/null
+++ b/worldedit/queue.lua
@@ -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,
+}
+
diff --git a/worldedit/serialization.lua b/worldedit/serialization.lua
index 985e3d7..d5b660b 100644
--- a/worldedit/serialization.lua
+++ b/worldedit/serialization.lua
@@ -160,10 +160,10 @@ end
--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)
-worldedit.deserialize = function(originpos, value)
+worldedit.deserialize = function(originpos, value, env)
local originx, originy, originz = originpos.x, originpos.y, originpos.z
local count = 0
- local env = minetest.env
+ if env == nil then env = minetest.env end
local version = worldedit.valueversion(value)
if version == 1 or version == 2 then --original flat table format
--obtain the node table
@@ -239,4 +239,4 @@ worldedit.deserialize = function(originpos, value)
end
end
return count
-end \ No newline at end of file
+end
diff --git a/worldedit/visualization.lua b/worldedit/visualization.lua
index 3c1a2db..9e99659 100644
--- a/worldedit/visualization.lua
+++ b/worldedit/visualization.lua
@@ -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
-worldedit.hide = function(pos1, pos2)
+worldedit.hide = function(pos1, pos2, tenv)
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 placeholder = {name="worldedit:placeholder", param1=0, param2=0}
@@ -59,9 +59,9 @@ worldedit.hide = function(pos1, pos2)
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
-worldedit.suppress = function(pos1, pos2, nodename)
+worldedit.suppress = function(pos1, pos2, nodename, tenv)
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
nodename = "default:" .. nodename
@@ -95,9 +95,9 @@ worldedit.suppress = function(pos1, pos2, nodename)
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
-worldedit.highlight = function(pos1, pos2, nodename)
+worldedit.highlight = function(pos1, pos2, nodename, tenv)
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
nodename = "default:" .. nodename
@@ -132,9 +132,9 @@ worldedit.highlight = function(pos1, pos2, nodename)
end
--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 env = minetest.env
+ if env == nil then env = minetest.env end
local pos = {x=pos1.x, y=0, z=0}
local node = {name="", param1=0, param2=0}
@@ -161,4 +161,4 @@ worldedit.restore = function(pos1, pos2)
pos.x = pos.x + 1
end
return count
-end \ No newline at end of file
+end
diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua
index fb01ce7..93db72a 100644
--- a/worldedit_commands/init.lua
+++ b/worldedit_commands/init.lua
@@ -162,7 +162,11 @@ minetest.register_chatcommand("/set", {
return
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)
end,
})
@@ -192,7 +196,11 @@ minetest.register_chatcommand("/replace", {
return
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)
end,
})
@@ -222,7 +230,11 @@ minetest.register_chatcommand("/replaceinverse", {
return
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)
end,
})
@@ -248,7 +260,11 @@ minetest.register_chatcommand("/hollowsphere", {
return
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)
end,
})
@@ -274,7 +290,11 @@ minetest.register_chatcommand("/sphere", {
return
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)
end,
})
@@ -300,7 +320,11 @@ minetest.register_chatcommand("/hollowdome", {
return
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)
end,
})
@@ -326,7 +350,11 @@ minetest.register_chatcommand("/dome", {
return
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)
end,
})
@@ -356,7 +384,11 @@ minetest.register_chatcommand("/hollowcylinder", {
return
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)
end,
})
@@ -386,7 +418,11 @@ minetest.register_chatcommand("/cylinder", {
return
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)
end,
})
@@ -412,7 +448,11 @@ minetest.register_chatcommand("/pyramid", {
return
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)
end,
})
@@ -438,7 +478,11 @@ minetest.register_chatcommand("/spiral", {
return
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)
end,
})
@@ -464,7 +508,11 @@ minetest.register_chatcommand("/copy", {
amount = amount * sign
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)
end,
})
@@ -497,6 +545,11 @@ minetest.register_chatcommand("/move", {
worldedit.mark_pos1(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)
end,
})
@@ -522,7 +575,11 @@ minetest.register_chatcommand("/stack", {
count = count * sign
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)
end,
})
@@ -554,7 +611,11 @@ minetest.register_chatcommand("/transpose", {
return
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
worldedit.pos1[name] = pos1
@@ -585,7 +646,11 @@ minetest.register_chatcommand("/flip", {
return
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)
end,
})
@@ -614,7 +679,11 @@ minetest.register_chatcommand("/rotate", {
return
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
worldedit.pos1[name] = pos1
@@ -647,7 +716,11 @@ minetest.register_chatcommand("/orient", {
return
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)
end,
@@ -664,7 +737,11 @@ minetest.register_chatcommand("/fixlight", {
return
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)
end,
})
@@ -680,7 +757,11 @@ minetest.register_chatcommand("/hide", {
return
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)
end,
})
@@ -701,7 +782,11 @@ minetest.register_chatcommand("/suppress", {
return
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)
end,
})
@@ -722,7 +807,11 @@ minetest.register_chatcommand("/highlight", {
return
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)
end,
})
@@ -738,7 +827,11 @@ minetest.register_chatcommand("/restore", {
return
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)
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)
return
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)
end,
@@ -895,4 +993,4 @@ minetest.register_chatcommand("/luatransform", {
minetest.chat_send_player(name, "Code successfully executed", false)
end
end,
-}) \ No newline at end of file
+})