]> git.lizzy.rs Git - worldedit.git/commitdiff
Documentation for `//stack2`, code style fixes, add author section to README.
authorUberi <azhang9@gmail.com>
Sun, 6 Jul 2014 23:42:02 +0000 (19:42 -0400)
committerUberi <azhang9@gmail.com>
Sun, 6 Jul 2014 23:42:02 +0000 (19:42 -0400)
Chat Commands.md
README.md
worldedit/manipulations.lua
worldedit_commands/init.lua

index c3d525035b34e5d9825857a8ffc84150aa252ade..8faac6545d0e55dd587bda8a5348ee56d8bd6a85 100644 (file)
@@ -98,13 +98,13 @@ Display the volume of the current WorldEdit region.
 \r
     //volume\r
 \r
-### `//set <node>`\r
+### `//set <node1> ...`\r
 \r
-Set the current WorldEdit region to `<node>`.\r
+Set the current WorldEdit region to a random mix of `<node1>`, `...`.\r
 \r
     //set air\r
-    //set cactus\r
-    //set Bronze Block\r
+    //set cactus stone glass\r
+    //set Bronze\r
     //set mesecons:wire_00000000_off\r
 \r
 ### `//replace <search node> <replace node>`\r
@@ -219,6 +219,13 @@ Stack the current WorldEdit region along the x/y/z/? axis `<count>` times.
     //stack z +5\r
     //stack ? 12\r
 \r
+### `//stack2 <count> <x> <y> <z>`\r
+\r
+Stack the current WorldEdit region `<count>` times by offset `<x>`, `<y>`, `<z>`.\r
+\r
+    //stack2 5 3 8 2\r
+    //stack2 1 -1 -1 -1\r
+\r
 ### `//scale <factor>`\r
 \r
 Scale the current WorldEdit positions and region by a factor of positive integer `<factor>` with position 1 as the origin.\r
index 62d245a66b7ebdaf4df43da3202ac2e6d79aa212..2bb37356f751bcebf24f265b82377f60417e1e2d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -130,6 +130,21 @@ The WorldEdit Schematic format is accessed via the WorldEdit API, or WorldEdit s
 
 The second is the Minetest Schematic format (MTS). The details of this format may be found in the Minetest documentation and are out of the scope of this document. Access to this format is done via specialized MTS commands such as `//mtschemcreate` and `//mtschemplace`.
 
+Authors
+-------
+WorldEdit would not be possible without the contributions of many developers and designers. Below, they are listed alphabetically:
+
+    cheapie
+    cornernote
+    cyisfor
+    electricface
+    kaeza
+    khonkhortisan
+    sfan5
+    ShadowNinja
+    spillz
+    Uberi/Temperest
+
 License
 -------
 Copyright 2013 sfan5, Anthony Zhang (Uberi/Temperest), and Brett O'Donnell (cornernote).
index 0a37e16cfb5ffed562ed08d650f8708dc3f80edf..80541fcd30bb8e76b78afc26bb5b5ec22120aed9 100644 (file)
@@ -48,8 +48,16 @@ worldedit.set = function(pos1, pos2, nodenames)
     for i,v in ipairs(nodenames) do\r
         node_ids[i] = minetest.get_content_id(nodenames[i])\r
     end\r
-       for i in area:iterp(pos1, pos2) do\r
-               nodes[i] = node_ids[math.random(#node_ids)]\r
+       if #node_ids == 1 then --only one type of node\r
+               local id = node_ids[1]\r
+               for i in area:iterp(pos1, pos2) do\r
+                       nodes[i] = node_ids[id]\r
+               end\r
+       else --fill randomly with all types of specified nodes\r
+               local id_count, rand = #node_ids, math.random\r
+               for i in area:iterp(pos1, pos2) do\r
+                       nodes[i] = node_ids[rand(id_count)]\r
+               end\r
        end\r
 \r
        --update map nodes\r
@@ -173,126 +181,126 @@ worldedit.copy = function(pos1, pos2, axis, amount) --wip: replace the old versi
 end\r
 \r
 worldedit.copy2 = function(pos1, pos2, direction, volume)\r
-    -- the overlap shouldn't matter as long as we\r
-    -- 1) start at the furthest separated corner\r
-    -- 2) complete an edge before moving inward, either edge works\r
-    -- 3) complete a face before moving inward, similarly\r
-    --\r
-    -- to do this I\r
-    -- 1) find the furthest destination in the direction, of each axis\r
-    -- 2) call those the furthest separated corner\r
-    -- 3) make sure to iterate inward from there\r
-    -- 4) nested loop to make sure complete edge, complete face, then complete cube.\r
-    \r
+       -- the overlap shouldn't matter as long as we\r
+       -- 1) start at the furthest separated corner\r
+       -- 2) complete an edge before moving inward, either edge works\r
+       -- 3) complete a face before moving inward, similarly\r
+       --\r
+       -- to do this I\r
+       -- 1) find the furthest destination in the direction, of each axis\r
+       -- 2) call those the furthest separated corner\r
+       -- 3) make sure to iterate inward from there\r
+       -- 4) nested loop to make sure complete edge, complete face, then complete cube.\r
+\r
        local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node\r
-    local somemeta = get_meta(pos1) -- hax lol\r
-    local to_table = somemeta.to_table\r
-    local from_table = somemeta.from_table\r
-    somemeta = nil\r
+       local somemeta = get_meta(pos1) -- hax lol\r
+       local to_table = somemeta.to_table\r
+       local from_table = somemeta.from_table\r
+       somemeta = nil\r
 \r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
        local manip = minetest.get_voxel_manip()\r
        manip:read_from_map(pos1, pos2)\r
 \r
-    local sx,sy,sz -- direction sign\r
-    local ix,iy,iz -- initial destination\r
-    local ex,ey,ez -- final destination\r
-    local originalx,originaly,originalz -- source \r
-    -- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g\r
-    if direction.x > 0 then \r
-        originalx = pos2.x\r
-        ix = originalx + direction.x\r
-        ex = pos1.x + direction.x\r
-        sx = -1\r
-    elseif direction.x < 0 then \r
-        originalx = pos1.x\r
-        ix = originalx + direction.x\r
-        ex = pos2.x + direction.x\r
-        sx = 1\r
-    else \r
-        originalx = pos1.x\r
-        ix = originalx -- whatever\r
-        ex = pos2.x\r
-        sx = 1\r
-    end\r
+       local sx, sy, sz -- direction sign\r
+       local ix, iy, iz -- initial destination\r
+       local ex, ey, ez -- final destination\r
+       local originalx, originaly, originalz -- source\r
+       -- vim -> :'<,'>s/\<\([ioes]\?\)x\>/\1y/g\r
+       if direction.x > 0 then\r
+               originalx = pos2.x\r
+               ix = originalx + direction.x\r
+               ex = pos1.x + direction.x\r
+               sx = -1\r
+       elseif direction.x < 0 then\r
+               originalx = pos1.x\r
+               ix = originalx + direction.x\r
+               ex = pos2.x + direction.x\r
+               sx = 1\r
+       else\r
+               originalx = pos1.x\r
+               ix = originalx -- whatever\r
+               ex = pos2.x\r
+               sx = 1\r
+       end\r
 \r
-    if direction.y > 0 then \r
-        originaly = pos2.y\r
-        iy = originaly + direction.y\r
-        ey = pos1.y + direction.y\r
-        sy = -1\r
-    elseif direction.y < 0 then \r
-        originaly = pos1.y\r
-        iy = originaly + direction.y\r
-        ey = pos2.y + direction.y\r
-        sy = 1\r
-    else \r
-        originaly = pos1.y\r
-        iy = originaly -- whatever\r
-        ey = pos2.y\r
-        sy = 1\r
-    end\r
+       if direction.y > 0 then\r
+               originaly = pos2.y\r
+               iy = originaly + direction.y\r
+               ey = pos1.y + direction.y\r
+               sy = -1\r
+       elseif direction.y < 0 then\r
+               originaly = pos1.y\r
+               iy = originaly + direction.y\r
+               ey = pos2.y + direction.y\r
+               sy = 1\r
+       else\r
+               originaly = pos1.y\r
+               iy = originaly -- whatever\r
+               ey = pos2.y\r
+               sy = 1\r
+       end\r
 \r
-    if direction.z > 0 then \r
-        originalz = pos2.z\r
-        iz = originalz + direction.z\r
-        ez = pos1.z + direction.z\r
-        sz = -1\r
-    elseif direction.z < 0 then \r
-        originalz = pos1.z\r
-        iz = originalz + direction.z\r
-        ez = pos2.z + direction.z\r
-        sz = 1\r
-    else \r
-        originalz = pos1.z\r
-        iz = originalz -- whatever\r
-        ez = pos2.z\r
-        sz = 1\r
-    end\r
-    -- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz)\r
-\r
-    local ox,oy,oz\r
-\r
-    ox = originalx\r
-    for x = ix,ex,sx do\r
-        oy = originaly\r
-        for y = iy,ey,sy do\r
-            oz = originalz\r
-            for z = iz,ez,sz do\r
-                -- reusing pos1/pos2 as source/dest here\r
-                pos1.x = ox; pos1.y = oy; pos1.z = oz\r
-                pos2.x = x; pos2.y = y; pos2.z = z\r
-                local node = get_node(pos1)\r
+       if direction.z > 0 then\r
+               originalz = pos2.z\r
+               iz = originalz + direction.z\r
+               ez = pos1.z + direction.z\r
+               sz = -1\r
+       elseif direction.z < 0 then\r
+               originalz = pos1.z\r
+               iz = originalz + direction.z\r
+               ez = pos2.z + direction.z\r
+               sz = 1\r
+       else\r
+               originalz = pos1.z\r
+               iz = originalz -- whatever\r
+               ez = pos2.z\r
+               sz = 1\r
+       end\r
+       -- print('copy',originalx,ix,ex,sx,originaly,iy,ey,sy,originalz,iz,ez,sz)\r
+\r
+       local ox,oy,oz\r
+\r
+       ox = originalx\r
+       for x = ix, ex, sx do\r
+               oy = originaly\r
+               for y = iy, ey, sy do\r
+                       oz = originalz\r
+                       for z = iz, ez, sz do\r
+                               -- reusing pos1/pos2 as source/dest here\r
+                               pos1.x, pos1.y, pos1.z = ox, oy, oz\r
+                               pos2.x, pos2.y, pos2.z = x, y, z\r
+                               local node = get_node(pos1)\r
                                local meta = to_table(get_meta(pos1)) --get meta of current node\r
-                add_node(pos2,node)\r
-                from_table(get_meta(pos2),meta)\r
-                oz = oz + sz\r
-            end\r
-            oy = oy + sy\r
-        end\r
-        ox = ox + sx\r
-    end\r
-end            \r
-\r
-worldedit.stack2 = function(pos1, pos2, direction, amount, finished) \r
-    local i = 0\r
-    local translated = {x=0,y=0,z=0}\r
-    local function nextone()\r
-        if i <= amount then\r
-            i = i + 1\r
-            translated.x = translated.x + direction.x\r
-            translated.y = translated.y + direction.y\r
-            translated.z = translated.z + direction.z\r
-            worldedit.copy2(pos1,pos2,translated,volume)\r
-            minetest.after(0,nextone)\r
-        else\r
-            if finished then\r
-                finished()\r
-            end\r
-        end\r
-    end\r
-    nextone()\r
-    return nil\r
+                               add_node(pos2,node)\r
+                               from_table(get_meta(pos2),meta)\r
+                               oz = oz + sz\r
+                       end\r
+                       oy = oy + sy\r
+               end\r
+               ox = ox + sx\r
+       end\r
+end\r
+\r
+worldedit.stack2 = function(pos1, pos2, direction, amount, finished)\r
+       local i = 0\r
+       local translated = {x=0,y=0,z=0}\r
+       local function nextone()\r
+               if i <= amount then\r
+                       i = i + 1\r
+                       translated.x = translated.x + direction.x\r
+                       translated.y = translated.y + direction.y\r
+                       translated.z = translated.z + direction.z\r
+                       worldedit.copy2(pos1, pos2, translated, volume)\r
+                       minetest.after(0, nextone)\r
+               else\r
+                       if finished then\r
+                               finished()\r
+                       end\r
+               end\r
+       end\r
+       nextone()\r
+       return nil\r
 end\r
 \r
 --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\r
index e7b0f748a19dce839afd1c894dd6f633a9c64981..3fa9422dfdc9f1c11bc903a20da592a4925929d1 100644 (file)
@@ -279,19 +279,18 @@ minetest.register_chatcommand("/volume", {
 })\r
 \r
 minetest.register_chatcommand("/set", {\r
-       params = "<node>",\r
-       description = "Set the current WorldEdit region to <node>",\r
+       params = "<node1> ...",\r
+       description = "Set the current WorldEdit region to a random mix of <node1>, ...",\r
        privs = {worldedit=true},\r
        func = safe_region(function(name, param)\r
         local nodes = {}\r
-\r
         for nodename in param:gmatch("[^%s]+") do\r
             local node = get_node(name, nodename)\r
             if not node then\r
-                worldedit.player_notify(name, 'Could not identify node "'..name..'"')\r
+                worldedit.player_notify(name, "Could not identify node \"" .. name .. "\"")\r
                 return\r
             end\r
-            nodes[#nodes+1] = node\r
+            nodes[#nodes + 1] = node\r
         end\r
 \r
                local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
@@ -620,47 +619,37 @@ minetest.register_chatcommand("/stack", {
 })\r
 \r
 minetest.register_chatcommand("/stack2", {\r
-       params = "<count> <x>/<y>/<z>",\r
-       description = "Stack the current WorldEdit region <count> times translating each time by x, y and z in the respective directions.",\r
+       params = "<count> <x> <y> <z>",\r
+       description = "Stack the current WorldEdit region <count> times by offset <x>, <y>, <z>",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
                local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
         if pos1 == nil or pos2 == nil then\r
-            worldedit.player_notify(name, "Select a position first!")\r
+                       worldedit.player_notify(name, "Select a position first!")\r
             return\r
         end\r
-        local repetitions, incs = param:match("([0-9]+)%s*(.+)")\r
-        repetitions = repetitions and tonumber(repetitions)\r
+        local repetitions, incs = param:match("(%d+)%s*(.+)")\r
         if repetitions == nil then\r
                        worldedit.player_notify(name, "invalid count: " .. param)\r
-            return \r
+            return\r
         end\r
+               repetitions = tonumber(repetitions)\r
 \r
-        local x,y,z = incs:match("(.+)/(.+)/(.+)")\r
+        local x, y, z = incs:match("([+-]?%d+) ([+-]%d+) ([+-]%d+)")\r
         if x == nil then\r
             worldedit.player_notify(name, "invalid increments: " .. param)\r
             return\r
         end\r
-        x = tonumber(x)\r
-        y = tonumber(y)\r
-        z = tonumber(z)\r
-        if x == nil or y == nil or z == nil then\r
-            worldedit.player_notify(name, "increments must be numbers: " .. param)\r
-            return\r
-        end\r
+        x, y, z = tonumber(x), tonumber(y), tonumber(z)\r
 \r
-        local count = worldedit.volume(pos1,pos2) * repetitions\r
+        local count = worldedit.volume(pos1, pos2) * repetitions\r
 \r
         return safe_region(function()\r
-                 worldedit.stack2(pos1, pos2, {x=x,y=y,z=z}, repetitions,\r
-          function()\r
-                   worldedit.player_notify(name, count .. " nodes stacked")\r
-        end)\r
-\r
-        end,\r
-        function() \r
-            return count\r
-       end)(name,param) -- more hax\r
+                       worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions,\r
+                               function() worldedit.player_notify(name, count .. " nodes stacked") end)\r
+               end, function()\r
+                       return count\r
+               end)(name,param) -- more hax\r
        end\r
 })\r
 \r