]> git.lizzy.rs Git - worldedit.git/commitdiff
Add entities to mark the WorldEdit region positions and add the //reset command....
authorAnthony Zhang <azhang9@gmail.com>
Mon, 16 Jul 2012 18:38:15 +0000 (14:38 -0400)
committerAnthony Zhang <azhang9@gmail.com>
Mon, 16 Jul 2012 18:38:15 +0000 (14:38 -0400)
README.md
init.lua
mark.lua [new file with mode: 0644]
textures/worldedit_pos1.png [new file with mode: 0644]
textures/worldedit_pos2.png [new file with mode: 0644]

index b6f6e6c50c5e74af3034ce755e49ddcab0be8b6a..84e2820c089fa1e69c48551fe4d813e522fd22ef 100644 (file)
--- a/README.md
+++ b/README.md
@@ -12,9 +12,21 @@ WorldEdit has a huge potential for abuse by untrusted players. Therefore, users
 
 For in-game information about these commands, type `/help <command name>` in the chat. For example, to learn more about the `//copy` command, simply type `/help /copy` to display information relevant to copying a region.
 
+Regions
+-------
+Most WorldEdit commands operate on regions. Regions are a set of two positions that define a 3D cube. They are local to each player and chat commands affect only the region for the player giving the commands.
+
+Each positions together define two opposing corners of the cube. With two opposing corners it is possible to determine both the location and dimensions of the region.
+
+Regions are not saved between server restarts. They start off as empty regions, and cannot be used with most WorldEdit commands until they are set to valid values.
+
 Commands
 --------
 
+### //reset
+
+Reset the region so that it is empty.
+
 ### //pos1
 
 Set WorldEdit region position 1 to the player's location.
index 3191bd0f6be8b6d9e468b9a01da835ae590a9c67..c64be04101aceb78a523791d1fd89c3560e3019f 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -1,25 +1,42 @@
 minetest.register_privilege("worldedit", "Can use WorldEdit commands")\r
 \r
-worldedit = {}\r
+--wip: check to make sure player positions are set before doing editing\r
+--wip; fix meseconedit to export to new WorldEdit format\r
 \r
-dofile(minetest.get_modpath("worldedit") .. "/functions.lua")\r
+worldedit = {}\r
 \r
 worldedit.set_pos = {}\r
 \r
 worldedit.pos1 = {}\r
 worldedit.pos2 = {}\r
 \r
+dofile(minetest.get_modpath("worldedit") .. "/functions.lua")\r
+dofile(minetest.get_modpath("worldedit") .. "/mark.lua")\r
+\r
 --determines whether `nodename` is a valid node name, returning a boolean\r
 worldedit.node_is_valid = function(temp_pos, nodename)\r
-       local originalnode = minetest.env:get_node(temp_pos)\r
-       minetest.env:add_node(temp_pos, {name=nodename})\r
-       local value = minetest.env:get_node(temp_pos).name\r
-       local equal = value == nodename or value == "default:" .. nodename\r
-       minetest.env:add_node(temp_pos, originalnode)\r
-       return equal\r
+       local originalnode = minetest.env:get_node(temp_pos) --save the original node to restore later\r
+       minetest.env:add_node(temp_pos, {name=nodename}) --attempt to add the node\r
+       local value = minetest.env:get_node(temp_pos).name --obtain the name of the newly added node\r
+       if value == nodename or value == "default:" .. nodename then --successfully added node\r
+               minetest.env:add_node(temp_pos, originalnode) --restore the original node\r
+               return true --node is valid\r
+       end\r
+       return false --node is not valid\r
 end\r
 \r
---wip: check to make sure player positions are set before doing editing\r
+minetest.register_chatcommand("/reset", {\r
+       params = "",\r
+       description = "Reset the region so that it is empty",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               worldedit.pos1[name] = nil\r
+               worldedit.pos2[name] = nil\r
+               worldedit.mark_pos1(name)\r
+               worldedit.mark_pos2(name)\r
+               minetest.chat_send_player(name, "WorldEdit region reset")\r
+       end,\r
+})\r
 \r
 minetest.register_chatcommand("/pos1", {\r
        params = "",\r
@@ -31,6 +48,7 @@ minetest.register_chatcommand("/pos1", {
                pos.y = math.floor(pos.y)\r
                pos.z = math.floor(pos.z)\r
                worldedit.pos1[name] = pos\r
+               worldedit.mark_pos1(name)\r
                minetest.chat_send_player(name, "WorldEdit position 1 set to (" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")")\r
        end,\r
 })\r
@@ -42,6 +60,7 @@ minetest.register_chatcommand("/pos2", {
        func = function(name, param)\r
                local pos = minetest.env:get_player_by_name(name):getpos()\r
                worldedit.pos2[name] = pos\r
+               worldedit.mark_pos2(name)\r
                minetest.chat_send_player(name, "WorldEdit position 2 set to (" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")")\r
        end,\r
 })\r
@@ -71,10 +90,12 @@ minetest.register_on_punchnode(function(pos, node, puncher)
                if worldedit.set_pos[name] == 1 then --setting position 1\r
                        worldedit.set_pos[name] = 2 --set position 2 on the next invocation\r
                        worldedit.pos1[name] = pos\r
+                       worldedit.mark_pos1(name)\r
                        minetest.chat_send_player(name, "WorldEdit region position 1 set to (" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")")\r
                else --setting position 2\r
                        worldedit.set_pos[name] = nil --finished setting positions\r
                        worldedit.pos2[name] = pos\r
+                       worldedit.mark_pos2(name)\r
                        minetest.chat_send_player(name, "WorldEdit region position 2 set to (" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")")\r
                end\r
        end\r
diff --git a/mark.lua b/mark.lua
new file mode 100644 (file)
index 0000000..228b8f0
--- /dev/null
+++ b/mark.lua
@@ -0,0 +1,68 @@
+worldedit.marker1 = {}\r
+worldedit.marker2 = {}\r
+\r
+--marks worldedit region position 1\r
+worldedit.mark_pos1 = function(name)\r
+       local pos = worldedit.pos1[name]\r
+       if worldedit.marker1[name] == nil then --marker does not yet exist\r
+               if pos ~= nil then --add marker\r
+                       worldedit.marker1[name] = minetest.env:add_entity(pos, "worldedit:pos1")\r
+               end\r
+       else --marker already exists\r
+               if pos == nil then --remove marker\r
+                       worldedit.marker1[name]:remove()\r
+                       worldedit.marker1[name] = nil\r
+               else --move marker\r
+                       worldedit.marker1[name]:setpos(pos)\r
+               end\r
+       end\r
+end\r
+\r
+--marks worldedit region position 2\r
+worldedit.mark_pos2 = function(name)\r
+       local pos = worldedit.pos2[name]\r
+       if worldedit.marker2[name] == nil then --marker does not yet exist\r
+               if pos ~= nil then --add marker\r
+                       worldedit.marker2[name] = minetest.env:add_entity(pos, "worldedit:pos2")\r
+               end\r
+       else --marker already exists\r
+               if pos == nil then --remove marker\r
+                       worldedit.marker2[name]:remove()\r
+                       worldedit.marker2[name] = nil\r
+               else --move marker\r
+                       worldedit.marker2[name]:setpos(pos)\r
+               end\r
+       end\r
+end\r
+\r
+minetest.register_entity("worldedit:pos1", {\r
+       initial_properties = {\r
+               visual = "cube",\r
+               visual_size = {x=1.1, y=1.1},\r
+               textures = {"worldedit_pos1.png", "worldedit_pos1.png",\r
+                       "worldedit_pos1.png", "worldedit_pos1.png",\r
+                       "worldedit_pos1.png", "worldedit_pos1.png"},\r
+               collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},\r
+       },\r
+       on_punch = function(self, hitter)\r
+               self.object:remove()\r
+               local name = hitter:get_player_name()\r
+               worldedit.marker1[name] = nil\r
+       end,\r
+})\r
+\r
+minetest.register_entity("worldedit:pos2", {\r
+       initial_properties = {\r
+               visual = "cube",\r
+               visual_size = {x=1.1, y=1.1},\r
+               textures = {"worldedit_pos2.png", "worldedit_pos2.png",\r
+                       "worldedit_pos2.png", "worldedit_pos2.png",\r
+                       "worldedit_pos2.png", "worldedit_pos2.png"},\r
+               collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},\r
+       },\r
+       on_punch = function(self, hitter)\r
+               self.object:remove()\r
+               local name = hitter:get_player_name()\r
+               worldedit.marker2[name] = nil\r
+       end,\r
+})
\ No newline at end of file
diff --git a/textures/worldedit_pos1.png b/textures/worldedit_pos1.png
new file mode 100644 (file)
index 0000000..4c304aa
Binary files /dev/null and b/textures/worldedit_pos1.png differ
diff --git a/textures/worldedit_pos2.png b/textures/worldedit_pos2.png
new file mode 100644 (file)
index 0000000..1502f16
Binary files /dev/null and b/textures/worldedit_pos2.png differ