]> git.lizzy.rs Git - worldedit.git/blobdiff - init.lua
Replace worldedit.spiral with worldedit.pyramid, as well as related chat commands.
[worldedit.git] / init.lua
index 6820bbfacc7ec7bc018d7008d44f4b984b7333fc..da462c57a883f429ec355f99d3c0c5e96e8fd5a1 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -16,16 +16,18 @@ worldedit.node_is_valid = function(temp_pos, nodename)
        or minetest.registered_nodes["default:" .. nodename] ~= nil\r
 end\r
 \r
+--determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)\r
 worldedit.player_axis = function(name)\r
        local dir = minetest.env:get_player_by_name(name):get_look_dir()\r
-       if dir.x > dir.y then\r
-               if dir.x > dir.z then\r
-                       return "x"\r
+       local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)\r
+       if x > y then\r
+               if x > z then\r
+                       return "x", dir.x > 0 and 1 or -1\r
                end\r
-       elseif dir.y > dir.z then\r
-               return "y"\r
+       elseif y > z then\r
+               return "y", dir.y > 0 and 1 or -1\r
        end\r
-       return "z"\r
+       return "z", dir.z > 0 and 1 or -1\r
 end\r
 \r
 minetest.register_chatcommand("/reset", {\r
@@ -187,6 +189,58 @@ minetest.register_chatcommand("/replace", {
        end,\r
 })\r
 \r
+minetest.register_chatcommand("/hollowsphere", {\r
+       params = "<radius> <node>",\r
+       description = "Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               local pos = worldedit.pos1[name]\r
+               if pos == nil then\r
+                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+                       return\r
+               end\r
+\r
+               local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")\r
+               if found == nil then\r
+                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       return\r
+               end\r
+               if not worldedit.node_is_valid(pos, nodename) then\r
+                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
+                       return\r
+               end\r
+\r
+               local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename)\r
+               minetest.chat_send_player(name, count .. " nodes added")\r
+       end,\r
+})\r
+\r
+minetest.register_chatcommand("/sphere", {\r
+       params = "<radius> <node>",\r
+       description = "Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               local pos = worldedit.pos1[name]\r
+               if pos == nil then\r
+                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+                       return\r
+               end\r
+\r
+               local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")\r
+               if found == nil then\r
+                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       return\r
+               end\r
+               if not worldedit.node_is_valid(pos, nodename) then\r
+                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
+                       return\r
+               end\r
+\r
+               local count = worldedit.sphere(pos, tonumber(radius), nodename)\r
+               minetest.chat_send_player(name, count .. " nodes added")\r
+       end,\r
+})\r
+\r
 minetest.register_chatcommand("/hollowcylinder", {\r
        params = "x/y/z/? <length> <radius> <node>",\r
        description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",\r
@@ -204,7 +258,8 @@ minetest.register_chatcommand("/hollowcylinder", {
                        return\r
                end\r
                if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       length = length * sign\r
                end\r
                if not worldedit.node_is_valid(pos, nodename) then\r
                        minetest.chat_send_player(name, "Invalid node name: " .. param)\r
@@ -216,10 +271,9 @@ minetest.register_chatcommand("/hollowcylinder", {
        end,\r
 })\r
 \r
-\r
-minetest.register_chatcommand("/spiral", {\r
-       params = "<size> <node>",\r
-       description = "Add Spiral at WorldEdit position 1 with size <size>, composed of <node>",\r
+minetest.register_chatcommand("/pyramid", {\r
+       params = "<height> <node>",\r
+       description = "Add pyramid at WorldEdit position 1 with height <height>, composed of <node>",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
                local pos = worldedit.pos1[name]\r
@@ -238,8 +292,8 @@ minetest.register_chatcommand("/spiral", {
                        return\r
                end\r
 \r
-               local count = worldedit.spiral(pos, tonumber(size), nodename)\r
-               minetest.chat_send_player(name, count .. " nodes changed")\r
+               local count = worldedit.pyramid(pos, tonumber(size), nodename)\r
+               minetest.chat_send_player(name, count .. " nodes added")\r
        end,\r
 })\r
 \r
@@ -260,7 +314,8 @@ minetest.register_chatcommand("/cylinder", {
                        return\r
                end\r
                if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       length = length * sign\r
                end\r
                if not worldedit.node_is_valid(pos, nodename) then\r
                        minetest.chat_send_player(name, "Invalid node name: " .. param)\r
@@ -289,7 +344,8 @@ minetest.register_chatcommand("/copy", {
                        return\r
                end\r
                if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       amount = amount * sign\r
                end\r
 \r
                local count = worldedit.copy(pos1, pos2, axis, tonumber(amount))\r
@@ -314,10 +370,17 @@ minetest.register_chatcommand("/move", {
                        return\r
                end\r
                if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       amount = amount * sign\r
                end\r
 \r
                local count = worldedit.move(pos1, pos2, axis, tonumber(amount))\r
+\r
+               pos1[axis] = pos1[axis] + amount\r
+               pos2[axis] = pos2[axis] + amount\r
+               worldedit.mark_pos1(name)\r
+               worldedit.mark_pos2(name)\r
+\r
                minetest.chat_send_player(name, count .. " nodes moved")\r
        end,\r
 })\r
@@ -339,7 +402,8 @@ minetest.register_chatcommand("/stack", {
                        return\r
                end\r
                if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       count = count * sign\r
                end\r
 \r
                local count = worldedit.stack(pos1, pos2, axis, tonumber(count))\r
@@ -517,3 +581,49 @@ minetest.register_chatcommand("/load", {
                minetest.chat_send_player(name, count .. " nodes loaded")\r
        end,\r
 })\r
+\r
+minetest.register_chatcommand("/metasave", {\r
+       params = "<file>",\r
+       description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.wem\"",\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
+                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+                       return\r
+               end\r
+               if param == "" then\r
+                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       return\r
+               end\r
+               local count, err = worldedit.metasave(pos1, pos2, param)\r
+               if err then\r
+                       minetest.chat_send_player(name, "error loading file: " .. err)\r
+               else\r
+                       minetest.chat_send_player(name, count .. " nodes saved")\r
+               end\r
+       end,\r
+})\r
+\r
+minetest.register_chatcommand("/metaload", {\r
+       params = "<file>",\r
+       description = "Load nodes from \"(world folder)/schems/<file>.wem\" with position 1 of the current WorldEdit region as the origin",\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
+               if param == "" then\r
+                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       return\r
+               end\r
+               local count, err = worldedit.metaload(pos1, param)\r
+               if err then\r
+                       minetest.chat_send_player(name, "error loading file: " .. err)\r
+               else\r
+                       minetest.chat_send_player(name, count .. " nodes loaded")\r
+               end\r
+       end,\r
+})\r