forked from mtcontrib/Minetest-WorldEdit
Fix bugs in visualization API and make it ore robust. Fix bugs in //fixedpos, //suppress, and //highlight.
This commit is contained in:
parent
b252df2166
commit
c1f3cfc1e4
@ -136,7 +136,7 @@ worldedit.hollow_dome = function(pos, radius, nodename)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--adds a dome centered at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
|
--adds a dome centered 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)
|
||||||
--set up voxel manipulator
|
--set up voxel manipulator
|
||||||
local manip = minetest.get_voxel_manip()
|
local manip = minetest.get_voxel_manip()
|
||||||
local pos1 = {x=pos.x - radius, y=pos.y, z=pos.z - radius}
|
local pos1 = {x=pos.x - radius, y=pos.y, z=pos.z - radius}
|
||||||
@ -361,9 +361,8 @@ worldedit.pyramid = function(pos, height, nodename, env)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--adds a spiral centered at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`, returning the number of nodes added
|
--adds a spiral centered 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, env) --wip: clean this up
|
worldedit.spiral = function(pos, width, height, spacer, nodename, env) --wip: rewrite this whole thing, nobody can understand it anyways
|
||||||
-- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua
|
-- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua
|
||||||
--wip: rewrite this whole thing, nobody can understand it anyways
|
|
||||||
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
|
||||||
if z == -x and z >= x then return (2*z+1)^2 end
|
if z == -x and z >= x then return (2*z+1)^2 end
|
||||||
|
@ -33,7 +33,7 @@ worldedit.valueversion = function(value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--converts the region defined by positions `pos1` and `pos2` into a single string, returning the serialized data and the number of nodes serialized
|
--converts the region defined by positions `pos1` and `pos2` into a single string, returning the serialized data and the number of nodes serialized
|
||||||
worldedit.serialize = function(pos1, pos2) --wip: check for ItemStacks and whether they can be serialized
|
worldedit.serialize = function(pos1, pos2)
|
||||||
--make area stay loaded
|
--make area stay loaded
|
||||||
local manip = minetest.get_voxel_manip()
|
local manip = minetest.get_voxel_manip()
|
||||||
manip:read_from_map(pos1, pos2)
|
manip:read_from_map(pos1, pos2)
|
||||||
|
@ -39,7 +39,6 @@ worldedit.hide = function(pos1, pos2)
|
|||||||
|
|
||||||
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 placeholder = {name="worldedit:placeholder", param1=0, param2=0}
|
|
||||||
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||||
while pos.x <= pos2.x do
|
while pos.x <= pos2.x do
|
||||||
pos.y = pos1.y
|
pos.y = pos1.y
|
||||||
@ -47,12 +46,13 @@ worldedit.hide = function(pos1, pos2)
|
|||||||
pos.z = pos1.z
|
pos.z = pos1.z
|
||||||
while pos.z <= pos2.z do
|
while pos.z <= pos2.z do
|
||||||
local node = get_node(pos)
|
local node = get_node(pos)
|
||||||
placeholder.param1, placeholder.param2 = node.param1, node.param2 --copy node's param1 and param2
|
if node.name ~= "worldedit:placeholder" then
|
||||||
local data = get_meta(pos):to_table() --obtain metadata of original node
|
local data = get_meta(pos):to_table() --obtain metadata of original node
|
||||||
add_node(pos, placeholder) --add placeholder node
|
data.fields.worldedit_placeholder = node.name --add the node's name
|
||||||
local meta = get_meta(pos) --obtain placeholder meta
|
node.name = "worldedit:placeholder" --set node name
|
||||||
meta:from_table(data) --set placeholder metadata to the original node's metadata
|
add_node(pos, node) --add placeholder node
|
||||||
meta:set_string("worldedit_placeholder", node.name) --add the node's name
|
get_meta(pos):from_table(data) --set placeholder metadata to the original node's metadata
|
||||||
|
end
|
||||||
pos.z = pos.z + 1
|
pos.z = pos.z + 1
|
||||||
end
|
end
|
||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
@ -64,22 +64,25 @@ 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)
|
||||||
|
--ignore placeholder supression
|
||||||
|
if nodename == "worldedit:placeholder" then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
--make area stay loaded
|
--make area stay loaded
|
||||||
local manip = minetest.get_voxel_manip()
|
local manip = minetest.get_voxel_manip()
|
||||||
manip:read_from_map(pos1, pos2)
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
local placeholder = {name="worldedit:placeholder", param1=0, param2=0}
|
|
||||||
local nodes = minetest.find_nodes_in_area(pos1, pos2, nodename)
|
local nodes = minetest.find_nodes_in_area(pos1, pos2, nodename)
|
||||||
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||||
for _, pos in ipairs(nodes) do
|
for _, pos in ipairs(nodes) do
|
||||||
local node = get_node(pos)
|
local node = get_node(pos)
|
||||||
placeholder.param1, placeholder.param2 = node.param1, node.param2 --copy node's param1 and param2
|
|
||||||
local data = get_meta(pos):to_table() --obtain metadata of original node
|
local data = get_meta(pos):to_table() --obtain metadata of original node
|
||||||
add_node(pos, placeholder) --add placeholder node
|
data.fields.worldedit_placeholder = node.name --add the node's name
|
||||||
local meta = get_meta(pos) --obtain placeholder meta
|
node.name = "worldedit:placeholder" --set node name
|
||||||
meta:from_table(data) --set placeholder metadata to the original node's metadata
|
add_node(pos, node) --add placeholder node
|
||||||
meta:set_string("worldedit_placeholder", nodename) --add the node's name
|
get_meta(pos):from_table(data) --set placeholder metadata to the original node's metadata
|
||||||
end
|
end
|
||||||
return #nodes
|
return #nodes
|
||||||
end
|
end
|
||||||
@ -92,7 +95,6 @@ worldedit.highlight = function(pos1, pos2, nodename) --wip: speed this up with v
|
|||||||
|
|
||||||
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 placeholder = {name="worldedit:placeholder", param1=0, param2=0}
|
|
||||||
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||||
local count = 0
|
local count = 0
|
||||||
while pos.x <= pos2.x do
|
while pos.x <= pos2.x do
|
||||||
@ -103,13 +105,12 @@ worldedit.highlight = function(pos1, pos2, nodename) --wip: speed this up with v
|
|||||||
local node = get_node(pos)
|
local node = get_node(pos)
|
||||||
if node.name == nodename then --node found
|
if node.name == nodename then --node found
|
||||||
count = count + 1
|
count = count + 1
|
||||||
else --hide other nodes
|
elseif node.name ~= "worldedit:placeholder" then --hide other nodes
|
||||||
placeholder.param1, placeholder.param2 = node.param1, node.param2 --copy node's param1 and param2
|
|
||||||
local data = get_meta(pos):to_table() --obtain metadata of original node
|
local data = get_meta(pos):to_table() --obtain metadata of original node
|
||||||
add_node(pos, placeholder) --add placeholder node
|
data.fields.worldedit_placeholder = node.name --add the node's name
|
||||||
local meta = get_meta(pos) --obtain placeholder meta
|
node.name = "worldedit:placeholder" --set node name
|
||||||
meta:from_table(data) --set placeholder metadata to the original node's metadata
|
add_node(pos, node) --add placeholder node
|
||||||
meta:set_string("worldedit_placeholder", node.name) --add the node's name
|
get_meta(pos):from_table(data) --set placeholder metadata to the original node's metadata
|
||||||
end
|
end
|
||||||
pos.z = pos.z + 1
|
pos.z = pos.z + 1
|
||||||
end
|
end
|
||||||
@ -127,16 +128,14 @@ worldedit.restore = function(pos1, pos2)
|
|||||||
manip:read_from_map(pos1, pos2)
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
local node = {name="", param1=0, param2=0}
|
|
||||||
local nodes = minetest.find_nodes_in_area(pos1, pos2, "worldedit:placeholder")
|
local nodes = minetest.find_nodes_in_area(pos1, pos2, "worldedit:placeholder")
|
||||||
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||||
for _, pos in ipairs(nodes) do
|
for _, pos in ipairs(nodes) do
|
||||||
local currentnode = get_node(pos)
|
local node = get_node(pos)
|
||||||
node.param1, node.param2 = currentnode.param1, currentnode.param2 --copy node's param1 and param2
|
|
||||||
local data = get_meta(pos):to_table() --obtain node metadata
|
local data = get_meta(pos):to_table() --obtain node metadata
|
||||||
node.name = data.fields.worldedit_placeholder --set node name
|
node.name = data.fields.worldedit_placeholder --set node name
|
||||||
data.fields.worldedit_placeholder = nil --delete old nodename
|
data.fields.worldedit_placeholder = nil --delete old nodename
|
||||||
add_node(pos, placeholder) --add original node
|
add_node(pos, node) --add original node
|
||||||
get_meta(pos):from_table(data) --set original node metadata
|
get_meta(pos):from_table(data) --set original node metadata
|
||||||
end
|
end
|
||||||
return #nodes
|
return #nodes
|
||||||
|
@ -183,7 +183,7 @@ minetest.register_chatcommand("/fixedpos", {
|
|||||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local pos = {x=x, y=y, z=z}
|
local pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}
|
||||||
if flag == "set1" then
|
if flag == "set1" then
|
||||||
worldedit.pos1[name] = pos
|
worldedit.pos1[name] = pos
|
||||||
worldedit.mark_pos1(name)
|
worldedit.mark_pos1(name)
|
||||||
@ -887,11 +887,7 @@ minetest.register_chatcommand("/hide", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local tenv = minetest.env
|
local count = worldedit.hide(pos1, pos2)
|
||||||
if worldedit.ENABLE_QUEUE then
|
|
||||||
tenv = worldedit.queue_aliasenv
|
|
||||||
end
|
|
||||||
local count = worldedit.hide(pos1, pos2, tenv)
|
|
||||||
worldedit.player_notify(name, count .. " nodes hidden")
|
worldedit.player_notify(name, count .. " nodes hidden")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -907,7 +903,7 @@ minetest.register_chatcommand("/suppress", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local node = worldedit.node_is_valid(param)
|
local node = worldedit.normalize_nodename(param)
|
||||||
if param == "" or not node then
|
if param == "" or not node then
|
||||||
worldedit.player_notify(name, "invalid node name: " .. param)
|
worldedit.player_notify(name, "invalid node name: " .. param)
|
||||||
return
|
return
|
||||||
@ -933,7 +929,7 @@ minetest.register_chatcommand("/highlight", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local node = worldedit.node_is_valid(param)
|
local node = worldedit.normalize_nodename(param)
|
||||||
if param == "" or not node then
|
if param == "" or not node then
|
||||||
worldedit.player_notify(name, "invalid node name: " .. param)
|
worldedit.player_notify(name, "invalid node name: " .. param)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user