]> git.lizzy.rs Git - worldedit.git/commitdiff
Fix bugs in visualization API and make it ore robust. Fix bugs in //fixedpos, //suppr...
authorAnthony Zhang <azhang9@gmail.com>
Sun, 28 Jul 2013 22:15:46 +0000 (18:15 -0400)
committerAnthony Zhang <azhang9@gmail.com>
Sun, 28 Jul 2013 22:15:46 +0000 (18:15 -0400)
worldedit/primitives.lua
worldedit/serialization.lua
worldedit/visualization.lua
worldedit_commands/init.lua

index b4b7bc7438e0df4c7b8a359fc7f7845763e30161..cdb6e0f328f0a1fca7613c86c6fe62dbae5ef9f2 100644 (file)
@@ -136,7 +136,7 @@ worldedit.hollow_dome = function(pos, radius, nodename)
 end\r
 \r
 --adds a dome centered at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added\r
-worldedit.dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed\r
+worldedit.dome = function(pos, radius, nodename)\r
        --set up voxel manipulator\r
        local manip = minetest.get_voxel_manip()\r
        local pos1 = {x=pos.x - radius, y=pos.y, z=pos.z - radius}\r
@@ -361,9 +361,8 @@ worldedit.pyramid = function(pos, height, nodename, env)
 end\r
 \r
 --adds a spiral centered at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`, returning the number of nodes added\r
-worldedit.spiral = function(pos, width, height, spacer, nodename, env) --wip: clean this up\r
+worldedit.spiral = function(pos, width, height, spacer, nodename, env) --wip: rewrite this whole thing, nobody can understand it anyways\r
        -- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua\r
-       --wip: rewrite this whole thing, nobody can understand it anyways\r
        av, sn = math.abs, function(s) return s~=0 and s/av(s) or 0 end\r
        local function sindex(z, x) -- returns the value at (x, z) in a spiral that starts at 1 and goes outwards\r
                if z == -x and z >= x then return (2*z+1)^2 end\r
index e0d960d3ee7b2845aec3a5d6c7c4979211ef3bd9..5fbc16ca6ed66a5cf6b1591e4dc8ab77e185448b 100644 (file)
@@ -33,7 +33,7 @@ worldedit.valueversion = function(value)
 end\r
 \r
 --converts the region defined by positions `pos1` and `pos2` into a single string, returning the serialized data and the number of nodes serialized\r
-worldedit.serialize = function(pos1, pos2) --wip: check for ItemStacks and whether they can be serialized\r
+worldedit.serialize = function(pos1, pos2)\r
        --make area stay loaded\r
        local manip = minetest.get_voxel_manip()\r
        manip:read_from_map(pos1, pos2)\r
index d65414653d00f299db8245226707913ae1836f01..7b600d5cb770a5e28025fc132032a1525d16756d 100644 (file)
@@ -39,7 +39,6 @@ worldedit.hide = function(pos1, pos2)
 \r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
        local pos = {x=pos1.x, y=0, z=0}\r
-       local placeholder = {name="worldedit:placeholder", param1=0, param2=0}\r
        local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node\r
        while pos.x <= pos2.x do\r
                pos.y = pos1.y\r
@@ -47,12 +46,13 @@ worldedit.hide = function(pos1, pos2)
                        pos.z = pos1.z\r
                        while pos.z <= pos2.z do\r
                                local node = get_node(pos)\r
-                               placeholder.param1, placeholder.param2 = node.param1, node.param2 --copy node's param1 and param2\r
-                               local data = get_meta(pos):to_table() --obtain metadata of original node\r
-                               add_node(pos, placeholder) --add placeholder node\r
-                               local meta = get_meta(pos) --obtain placeholder meta\r
-                               meta:from_table(data) --set placeholder metadata to the original node's metadata\r
-                               meta:set_string("worldedit_placeholder", node.name)  --add the node's name\r
+                               if node.name ~= "worldedit:placeholder" then\r
+                                       local data = get_meta(pos):to_table() --obtain metadata of original node\r
+                                       data.fields.worldedit_placeholder = node.name --add the node's name\r
+                                       node.name = "worldedit:placeholder" --set node name\r
+                                       add_node(pos, node) --add placeholder node\r
+                                       get_meta(pos):from_table(data) --set placeholder metadata to the original node's metadata\r
+                               end\r
                                pos.z = pos.z + 1\r
                        end\r
                        pos.y = pos.y + 1\r
@@ -64,22 +64,25 @@ end
 \r
 --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\r
 worldedit.suppress = function(pos1, pos2, nodename)\r
+       --ignore placeholder supression\r
+       if nodename == "worldedit:placeholder" then\r
+               return 0\r
+       end\r
+\r
        --make area stay loaded\r
        local manip = minetest.get_voxel_manip()\r
        manip:read_from_map(pos1, pos2)\r
 \r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
-       local placeholder = {name="worldedit:placeholder", param1=0, param2=0}\r
        local nodes = minetest.find_nodes_in_area(pos1, pos2, nodename)\r
        local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node\r
        for _, pos in ipairs(nodes) do\r
                local node = get_node(pos)\r
-               placeholder.param1, placeholder.param2 = node.param1, node.param2 --copy node's param1 and param2\r
                local data = get_meta(pos):to_table() --obtain metadata of original node\r
-               add_node(pos, placeholder) --add placeholder node\r
-               local meta = get_meta(pos) --obtain placeholder meta\r
-               meta:from_table(data) --set placeholder metadata to the original node's metadata\r
-               meta:set_string("worldedit_placeholder", nodename)  --add the node's name\r
+               data.fields.worldedit_placeholder = node.name --add the node's name\r
+               node.name = "worldedit:placeholder" --set node name\r
+               add_node(pos, node) --add placeholder node\r
+               get_meta(pos):from_table(data) --set placeholder metadata to the original node's metadata\r
        end\r
        return #nodes\r
 end\r
@@ -92,7 +95,6 @@ worldedit.highlight = function(pos1, pos2, nodename) --wip: speed this up with v
 \r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
        local pos = {x=pos1.x, y=0, z=0}\r
-       local placeholder = {name="worldedit:placeholder", param1=0, param2=0}\r
        local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node\r
        local count = 0\r
        while pos.x <= pos2.x do\r
@@ -103,13 +105,12 @@ worldedit.highlight = function(pos1, pos2, nodename) --wip: speed this up with v
                                local node = get_node(pos)\r
                                if node.name == nodename then --node found\r
                                        count = count + 1\r
-                               else --hide other nodes\r
-                                       placeholder.param1, placeholder.param2 = node.param1, node.param2 --copy node's param1 and param2\r
+                               elseif node.name ~= "worldedit:placeholder" then --hide other nodes\r
                                        local data = get_meta(pos):to_table() --obtain metadata of original node\r
-                                       add_node(pos, placeholder) --add placeholder node\r
-                                       local meta = get_meta(pos) --obtain placeholder meta\r
-                                       meta:from_table(data) --set placeholder metadata to the original node's metadata\r
-                                       meta:set_string("worldedit_placeholder", node.name)  --add the node's name\r
+                                       data.fields.worldedit_placeholder = node.name --add the node's name\r
+                                       node.name = "worldedit:placeholder" --set node name\r
+                                       add_node(pos, node) --add placeholder node\r
+                                       get_meta(pos):from_table(data) --set placeholder metadata to the original node's metadata\r
                                end\r
                                pos.z = pos.z + 1\r
                        end\r
@@ -127,16 +128,14 @@ worldedit.restore = function(pos1, pos2)
        manip:read_from_map(pos1, pos2)\r
 \r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
-       local node = {name="", param1=0, param2=0}\r
        local nodes = minetest.find_nodes_in_area(pos1, pos2, "worldedit:placeholder")\r
        local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node\r
        for _, pos in ipairs(nodes) do\r
-               local currentnode = get_node(pos)\r
-               node.param1, node.param2 = currentnode.param1, currentnode.param2 --copy node's param1 and param2\r
+               local node = get_node(pos)\r
                local data = get_meta(pos):to_table() --obtain node metadata\r
                node.name = data.fields.worldedit_placeholder --set node name\r
                data.fields.worldedit_placeholder = nil --delete old nodename\r
-               add_node(pos, placeholder) --add original node\r
+               add_node(pos, node) --add original node\r
                get_meta(pos):from_table(data) --set original node metadata\r
        end\r
        return #nodes\r
index 40f8ffcc0c2b5b56eb2fcd96a31a27c9f7ea562b..0ecd0937474ef46df72f4fcb52dbc56c99a9b91c 100644 (file)
@@ -183,7 +183,7 @@ minetest.register_chatcommand("/fixedpos", {
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
-               local pos = {x=x, y=y, z=z}\r
+               local pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}\r
                if flag == "set1" then\r
                        worldedit.pos1[name] = pos\r
                        worldedit.mark_pos1(name)\r
@@ -887,11 +887,7 @@ minetest.register_chatcommand("/hide", {
                        return\r
                end\r
 \r
-               local tenv = minetest.env\r
-               if worldedit.ENABLE_QUEUE then\r
-                       tenv = worldedit.queue_aliasenv\r
-               end\r
-               local count = worldedit.hide(pos1, pos2, tenv)\r
+               local count = worldedit.hide(pos1, pos2)\r
                worldedit.player_notify(name, count .. " nodes hidden")\r
        end,\r
 })\r
@@ -907,7 +903,7 @@ minetest.register_chatcommand("/suppress", {
                        return\r
                end\r
 \r
-               local node = worldedit.node_is_valid(param)\r
+               local node = worldedit.normalize_nodename(param)\r
                if param == "" or not node then\r
                        worldedit.player_notify(name, "invalid node name: " .. param)\r
                        return\r
@@ -933,7 +929,7 @@ minetest.register_chatcommand("/highlight", {
                        return\r
                end\r
 \r
-               local node = worldedit.node_is_valid(param)\r
+               local node = worldedit.normalize_nodename(param)\r
                if param == "" or not node then\r
                        worldedit.player_notify(name, "invalid node name: " .. param)\r
                        return\r