]> git.lizzy.rs Git - worldedit.git/commitdiff
Rename //find to //highlight and worldedit.find to worldedit.highlight, add //allocat...
authorAnthony Zhang <azhang9@gmail.com>
Sun, 21 Oct 2012 21:49:43 +0000 (17:49 -0400)
committerAnthony Zhang <azhang9@gmail.com>
Sun, 21 Oct 2012 21:49:43 +0000 (17:49 -0400)
Chat Commands.md
WorldEdit API.md
worldedit/serialization.lua
worldedit/visualization.lua
worldedit_commands/init.lua

index 8e8da96640a0a5ac17d4bb2d7e0c949cb26c4d96..b90318b996fed3a4d95014775d4744f109bd7c7c 100644 (file)
@@ -182,13 +182,13 @@ Suppress all <node> in the current WorldEdit region non-destructively.
     //suppress default:glass\r
     //suppress mesecons:mesecon\r
 \r
-### //find <node>\r
+### //highlight <node>\r
 \r
-Find <node> in the current WorldEdit region by hiding everything else non-destructively.\r
+Highlight <node> in the current WorldEdit region by hiding everything else non-destructively.\r
 \r
-    //find dirt\r
-    //find default:glass\r
-    //find mesecons:mesecon\r
+    //highlight dirt\r
+    //highlight default:glass\r
+    //highlight mesecons:mesecon\r
 \r
 ### //restore\r
 \r
@@ -203,6 +203,13 @@ Save the current WorldEdit region to "(world folder)/schems/<file>.we".
     //save some random filename\r
     //save huge_base\r
 \r
+### //allocate <file>\r
+\r
+Set the region defined by nodes from "(world folder)/schems/<file>.we" as the current WorldEdit region.\r
+\r
+    //allocate some random filename\r
+    //allocate huge_base\r
+\r
 ### //load <file>\r
 \r
 Load nodes from "(world folder)/schems/<file>.we" with position 1 of the current WorldEdit region as the origin.\r
index 30e4437f0e03908b6efa39c1d84cb8eb99588ca7..ddf9a1e3330a106d5837f16f71222ef774563693 100644 (file)
@@ -8,63 +8,55 @@ Manipulations
 -------------\r
 Contained in manipulations.lua, this module allows several node operations to be applied over a region.\r
 \r
-### worldedit.volume(pos1, pos2)\r
-\r
-Determines the volume of the region defined by positions `pos1` and `pos2`.\r
-\r
-Returns the volume.\r
-\r
-### worldedit.set(pos1, pos2, nodename)\r
+### count = worldedit.set(pos1, pos2, nodename)\r
 \r
 Sets a region defined by positions `pos1` and `pos2` to `nodename`. To clear to region, use "air" as the value of `nodename`.\r
 \r
 Returns the number of nodes set.\r
 \r
-### worldedit.replace(pos1, pos2, searchnode, replacenode)\r
+### count = worldedit.replace(pos1, pos2, searchnode, replacenode)\r
 \r
 Replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.\r
 \r
 Returns the number of nodes replaced.\r
 \r
-Returns the number of nodes added.\r
-\r
-### worldedit.copy(pos1, pos2, axis, amount)\r
+### count = worldedit.copy(pos1, pos2, axis, amount)\r
 \r
 Copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.\r
 \r
 Returns the number of nodes copied.\r
 \r
-### worldedit.move(pos1, pos2, axis, amount)\r
+### count = worldedit.move(pos1, pos2, axis, amount)\r
 \r
 Moves the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.\r
 \r
 Returns the number of nodes moved.\r
 \r
-### worldedit.stack(pos1, pos2, axis, count)\r
+### count = worldedit.stack(pos1, pos2, axis, count)\r
 \r
 Duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times.\r
 \r
 Returns the number of nodes stacked.\r
 \r
-### worldedit.transpose(pos1, pos2, axis1, axis2)\r
+### count = worldedit.transpose(pos1, pos2, axis1, axis2)\r
 \r
 Transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes ("x" or "y" or "z").\r
 \r
 Returns the number of nodes transposed.\r
 \r
-### worldedit.flip(pos1, pos2, axis)\r
+### count = worldedit.flip(pos1, pos2, axis)\r
 \r
 Flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z").\r
 \r
 Returns the number of nodes flipped.\r
 \r
-### worldedit.rotate(pos1, pos2, angle)\r
+### count = worldedit.rotate(pos1, pos2, angle)\r
 \r
 Rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around the y axis (supporting 90 degree increments only).\r
 \r
 Returns the number of nodes rotated.\r
 \r
-### worldedit.dig(pos1, pos2)\r
+### count = worldedit.dig(pos1, pos2)\r
 \r
 Digs a region defined by positions `pos1` and `pos2`.\r
 \r
@@ -74,37 +66,37 @@ Primitives
 ----------\r
 Contained in primitives.lua, this module allows the creation of several geometric primitives.\r
 \r
-### worldedit.hollow_sphere = function(pos, radius, nodename)\r
+### count = worldedit.hollow_sphere(pos, radius, nodename)\r
 \r
 Adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`.\r
 \r
 Returns the number of nodes added.\r
 \r
-### worldedit.sphere = function(pos, radius, nodename)\r
+### count = worldedit.sphere(pos, radius, nodename)\r
 \r
 Adds a sphere at `pos` with radius `radius`, composed of `nodename`.\r
 \r
 Returns the number of nodes added.\r
 \r
-### worldedit.hollow_cylinder(pos, axis, length, radius, nodename)\r
+### count = worldedit.hollow_cylinder(pos, axis, length, radius, nodename)\r
 \r
 Adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`.\r
 \r
 Returns the number of nodes added.\r
 \r
-### worldedit.cylinder(pos, axis, length, radius, nodename)\r
+### count = worldedit.cylinder(pos, axis, length, radius, nodename)\r
 \r
 Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`.\r
 \r
 Returns the number of nodes added.\r
 \r
-### worldedit.pyramid(pos, height, nodename)\r
+### count = worldedit.pyramid(pos, height, nodename)\r
 \r
 Adds a pyramid at `pos` with height `height`.\r
 \r
 Returns the number of nodes added.\r
 \r
-### worldedit.spiral(pos, width, height, spacer, nodename)\r
+### count = worldedit.spiral(pos, width, height, spacer, nodename)\r
 \r
 Adds a spiral at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`.\r
 \r
@@ -112,25 +104,31 @@ Visualization
 -------------\r
 Contained in visualization.lua, this module allows nodes to be visualized in different ways.\r
 \r
-### worldedit.hide(pos1, pos2)\r
+### volume = worldedit.volume(pos1, pos2)\r
+\r
+Determines the volume of the region defined by positions `pos1` and `pos2`.\r
+\r
+Returns the volume.\r
+\r
+### count = worldedit.hide(pos1, pos2)\r
 \r
 Hides all nodes in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.\r
 \r
 Returns the number of nodes hidden.\r
 \r
-### worldedit.suppress(pos1, pos2, nodename)\r
+### count = worldedit.suppress(pos1, pos2, nodename)\r
 \r
 Suppresses all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively replacing them with invisible nodes.\r
 \r
 Returns the number of nodes suppressed.\r
 \r
-### worldedit.find(pos1, pos2, nodename)\r
+### count = worldedit.highlight(pos1, pos2, nodename)\r
 \r
-Finds all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes.\r
+Highlights all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes.\r
 \r
 Returns the number of nodes found.\r
 \r
-### worldedit.restore(pos1, pos2)\r
+### count = worldedit.restore(pos1, pos2)\r
 \r
 Restores all nodes hidden with WorldEdit functions in a region defined by positions `pos1` and `pos2`.\r
 \r
@@ -140,19 +138,25 @@ Serialization
 -------------\r
 Contained in serialization.lua, this module allows regions of nodes to be serialized and deserialized to formats suitable for use outside MineTest.\r
 \r
-### worldedit.serialize(pos1, pos2)\r
+### data, count = worldedit.serialize(pos1, pos2)\r
 \r
 Converts the region defined by positions `pos1` and `pos2` into a single string.\r
 \r
 Returns the serialized data and the number of nodes serialized.\r
 \r
-### worldedit.deserialize(originpos, value)\r
+### pos1, pos2, count = worldedit.allocate(originpos, value)\r
+\r
+Determines the volume the nodes represented by string `value` would occupy if deserialized at `originpos`.\r
+\r
+Returns the two corner positions and the number of nodes.\r
+\r
+### count = worldedit.deserialize(originpos, value)\r
 \r
 Loads the nodes represented by string `value` at position `originpos`.\r
 \r
 Returns the number of nodes deserialized.\r
 \r
-### worldedit.deserialize_old(originpos, value)\r
+### count = worldedit.deserialize_old(originpos, value)\r
 \r
 Loads the nodes represented by string `value` at position `originpos`, using the older table-based WorldEdit format.\r
 \r
@@ -160,13 +164,13 @@ This function is deprecated, and should not be used unless there is a need to su
 \r
 Returns the number of nodes deserialized.\r
 \r
-### worldedit.metasave(pos1, pos2, file)\r
+### count = worldedit.metasave(pos1, pos2, file)\r
 \r
 Saves the nodes and meta defined by positions `pos1` and `pos2` into a file.\r
 \r
 Returns the number of nodes saved.\r
 \r
-### worldedit.metaload(pos1, file)\r
+### count = worldedit.metaload(pos1, file)\r
 \r
 Loads the nodes and meta from `file` to position `pos1`.\r
 \r
index ae095ebd230ef53b1037fe8c548092d20b582972..a8e2aa8f4f5f55f019a366b66a84ce587d521b0e 100644 (file)
@@ -45,16 +45,49 @@ worldedit.serialize = function(pos1, pos2)
        return result, count\r
 end\r
 \r
+--determines the volume the nodes represented by string `value` would occupy if deserialized at `originpos`, returning the two corner positions and the number of nodes\r
+worldedit.allocate = function(originpos, value)\r
+       local huge = math.huge\r
+       local pos1 = {x=huge, y=huge, z=huge}\r
+       local pos2 = {x=-huge, y=-huge, z=-huge}\r
+       local originx, originy, originz = originpos.x, originpos.y, originpos.z\r
+       local count = 0\r
+       for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries\r
+               x, y, z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)\r
+               if x < pos1.x then\r
+                       pos1.x = x\r
+               end\r
+               if y < pos1.y then\r
+                       pos1.y = y\r
+               end\r
+               if z < pos1.z then\r
+                       pos1.z = z\r
+               end\r
+               if x > pos2.x then\r
+                       pos2.x = x\r
+               end\r
+               if y > pos2.y then\r
+                       pos2.y = y\r
+               end\r
+               if z > pos2.z then\r
+                       pos2.z = z\r
+               end\r
+               count = count + 1\r
+       end\r
+       return pos1, pos2, count\r
+end\r
+\r
 --loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized\r
 worldedit.deserialize = function(originpos, value)\r
        local pos = {x=0, y=0, z=0}\r
        local node = {name="", param1=0, param2=0}\r
+       local originx, originy, originz = originpos.x, originpos.y, originpos.z\r
        local count = 0\r
        local env = minetest.env\r
        for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries\r
-               pos.x = originpos.x + tonumber(x)\r
-               pos.y = originpos.y + tonumber(y)\r
-               pos.z = originpos.z + tonumber(z)\r
+               pos.x = originx + tonumber(x)\r
+               pos.y = originy + tonumber(y)\r
+               pos.z = originz + tonumber(z)\r
                node.name = name\r
                node.param1 = param1\r
                node.param2 = param2\r
index f3d4a353d85e94f4fac47ec3d252b3bbc2f2927b..3c1a2dbcb52a3f9866fffa01cbc799b646d4cc67 100644 (file)
@@ -94,8 +94,8 @@ worldedit.suppress = function(pos1, pos2, nodename)
        return count\r
 end\r
 \r
---finds 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\r
-worldedit.find = function(pos1, pos2, nodename)\r
+--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\r
+worldedit.highlight = function(pos1, pos2, nodename)\r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
        local env = minetest.env\r
 \r
index 1fb59d3b65a0772415204cd485613e599eb55546..3931df0695de9eeef30c1c6fcb34ace28c90703d 100644 (file)
@@ -567,9 +567,9 @@ minetest.register_chatcommand("/hide", {
        end,\r
 })\r
 \r
-minetest.register_chatcommand("/find", {\r
+minetest.register_chatcommand("/highlight", {\r
        params = "<node>",\r
-       description = "Find <node> in the current WorldEdit region by hiding everything else non-destructively",\r
+       description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
                local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
@@ -583,8 +583,8 @@ minetest.register_chatcommand("/find", {
                        return\r
                end\r
 \r
-               local count = worldedit.find(pos1, pos2, param)\r
-               minetest.chat_send_player(name, count .. " nodes found")\r
+               local count = worldedit.highlight(pos1, pos2, param)\r
+               minetest.chat_send_player(name, count .. " nodes highlighted")\r
        end,\r
 })\r
 \r
@@ -638,6 +638,42 @@ minetest.register_chatcommand("/save", {
        end,\r
 })\r
 \r
+minetest.register_chatcommand("/allocate", {\r
+       params = "<file>",\r
+       description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               local pos1 = worldedit.pos1[name]\r
+               if pos1 == nil then\r
+                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+                       return\r
+               end\r
+\r
+               if param == "" then\r
+                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       return\r
+               end\r
+\r
+               local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"\r
+               local file, err = io.open(filename, "rb")\r
+               if err ~= nil then\r
+                       minetest.chat_send_player(name, "Could not open file \"" .. filename .. "\"")\r
+                       return\r
+               end\r
+               local value = file:read("*a")\r
+               file:close()\r
+\r
+               local nodepos1, nodepos2, count = worldedit.allocate(pos1, value)\r
+\r
+               worldedit.pos1[name] = nodepos1\r
+               worldedit.mark_pos1(name)\r
+               worldedit.pos2[name] = nodepos2\r
+               worldedit.mark_pos2(name)\r
+\r
+               minetest.chat_send_player(name, count .. " nodes allocated")\r
+       end,\r
+})\r
+\r
 minetest.register_chatcommand("/load", {\r
        params = "<file>",\r
        description = "Load nodes from \"(world folder)/schems/<file>.we\" with position 1 of the current WorldEdit region as the origin",\r