diff options
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | init.lua | 39 | ||||
-rw-r--r-- | mark.lua | 68 | ||||
-rw-r--r-- | textures/worldedit_pos1.png | bin | 0 -> 142 bytes | |||
-rw-r--r-- | textures/worldedit_pos2.png | bin | 0 -> 157 bytes |
5 files changed, 110 insertions, 9 deletions
@@ -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. @@ -1,25 +1,42 @@ minetest.register_privilege("worldedit", "Can use WorldEdit commands")
-worldedit = {}
+--wip: check to make sure player positions are set before doing editing
+--wip; fix meseconedit to export to new WorldEdit format
-dofile(minetest.get_modpath("worldedit") .. "/functions.lua")
+worldedit = {}
worldedit.set_pos = {}
worldedit.pos1 = {}
worldedit.pos2 = {}
+dofile(minetest.get_modpath("worldedit") .. "/functions.lua")
+dofile(minetest.get_modpath("worldedit") .. "/mark.lua")
+
--determines whether `nodename` is a valid node name, returning a boolean
worldedit.node_is_valid = function(temp_pos, nodename)
- local originalnode = minetest.env:get_node(temp_pos)
- minetest.env:add_node(temp_pos, {name=nodename})
- local value = minetest.env:get_node(temp_pos).name
- local equal = value == nodename or value == "default:" .. nodename
- minetest.env:add_node(temp_pos, originalnode)
- return equal
+ local originalnode = minetest.env:get_node(temp_pos) --save the original node to restore later
+ minetest.env:add_node(temp_pos, {name=nodename}) --attempt to add the node
+ local value = minetest.env:get_node(temp_pos).name --obtain the name of the newly added node
+ if value == nodename or value == "default:" .. nodename then --successfully added node
+ minetest.env:add_node(temp_pos, originalnode) --restore the original node
+ return true --node is valid
+ end
+ return false --node is not valid
end
---wip: check to make sure player positions are set before doing editing
+minetest.register_chatcommand("/reset", {
+ params = "",
+ description = "Reset the region so that it is empty",
+ privs = {worldedit=true},
+ func = function(name, param)
+ worldedit.pos1[name] = nil
+ worldedit.pos2[name] = nil
+ worldedit.mark_pos1(name)
+ worldedit.mark_pos2(name)
+ minetest.chat_send_player(name, "WorldEdit region reset")
+ end,
+})
minetest.register_chatcommand("/pos1", {
params = "",
@@ -31,6 +48,7 @@ minetest.register_chatcommand("/pos1", { pos.y = math.floor(pos.y)
pos.z = math.floor(pos.z)
worldedit.pos1[name] = pos
+ worldedit.mark_pos1(name)
minetest.chat_send_player(name, "WorldEdit position 1 set to (" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")")
end,
})
@@ -42,6 +60,7 @@ minetest.register_chatcommand("/pos2", { func = function(name, param)
local pos = minetest.env:get_player_by_name(name):getpos()
worldedit.pos2[name] = pos
+ worldedit.mark_pos2(name)
minetest.chat_send_player(name, "WorldEdit position 2 set to (" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")")
end,
})
@@ -71,10 +90,12 @@ minetest.register_on_punchnode(function(pos, node, puncher) if worldedit.set_pos[name] == 1 then --setting position 1
worldedit.set_pos[name] = 2 --set position 2 on the next invocation
worldedit.pos1[name] = pos
+ worldedit.mark_pos1(name)
minetest.chat_send_player(name, "WorldEdit region position 1 set to (" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")")
else --setting position 2
worldedit.set_pos[name] = nil --finished setting positions
worldedit.pos2[name] = pos
+ worldedit.mark_pos2(name)
minetest.chat_send_player(name, "WorldEdit region position 2 set to (" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")")
end
end
diff --git a/mark.lua b/mark.lua new file mode 100644 index 0000000..228b8f0 --- /dev/null +++ b/mark.lua @@ -0,0 +1,68 @@ +worldedit.marker1 = {}
+worldedit.marker2 = {}
+
+--marks worldedit region position 1
+worldedit.mark_pos1 = function(name)
+ local pos = worldedit.pos1[name]
+ if worldedit.marker1[name] == nil then --marker does not yet exist
+ if pos ~= nil then --add marker
+ worldedit.marker1[name] = minetest.env:add_entity(pos, "worldedit:pos1")
+ end
+ else --marker already exists
+ if pos == nil then --remove marker
+ worldedit.marker1[name]:remove()
+ worldedit.marker1[name] = nil
+ else --move marker
+ worldedit.marker1[name]:setpos(pos)
+ end
+ end
+end
+
+--marks worldedit region position 2
+worldedit.mark_pos2 = function(name)
+ local pos = worldedit.pos2[name]
+ if worldedit.marker2[name] == nil then --marker does not yet exist
+ if pos ~= nil then --add marker
+ worldedit.marker2[name] = minetest.env:add_entity(pos, "worldedit:pos2")
+ end
+ else --marker already exists
+ if pos == nil then --remove marker
+ worldedit.marker2[name]:remove()
+ worldedit.marker2[name] = nil
+ else --move marker
+ worldedit.marker2[name]:setpos(pos)
+ end
+ end
+end
+
+minetest.register_entity("worldedit:pos1", {
+ initial_properties = {
+ visual = "cube",
+ visual_size = {x=1.1, y=1.1},
+ textures = {"worldedit_pos1.png", "worldedit_pos1.png",
+ "worldedit_pos1.png", "worldedit_pos1.png",
+ "worldedit_pos1.png", "worldedit_pos1.png"},
+ collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
+ },
+ on_punch = function(self, hitter)
+ self.object:remove()
+ local name = hitter:get_player_name()
+ worldedit.marker1[name] = nil
+ end,
+})
+
+minetest.register_entity("worldedit:pos2", {
+ initial_properties = {
+ visual = "cube",
+ visual_size = {x=1.1, y=1.1},
+ textures = {"worldedit_pos2.png", "worldedit_pos2.png",
+ "worldedit_pos2.png", "worldedit_pos2.png",
+ "worldedit_pos2.png", "worldedit_pos2.png"},
+ collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
+ },
+ on_punch = function(self, hitter)
+ self.object:remove()
+ local name = hitter:get_player_name()
+ worldedit.marker2[name] = nil
+ end,
+})
\ No newline at end of file diff --git a/textures/worldedit_pos1.png b/textures/worldedit_pos1.png Binary files differnew file mode 100644 index 0000000..4c304aa --- /dev/null +++ b/textures/worldedit_pos1.png diff --git a/textures/worldedit_pos2.png b/textures/worldedit_pos2.png Binary files differnew file mode 100644 index 0000000..1502f16 --- /dev/null +++ b/textures/worldedit_pos2.png |