Add entities to mark the WorldEdit region positions and add the //reset command. Document regions, and the //reset command.

This commit is contained in:
Anthony Zhang 2012-07-16 14:38:15 -04:00
parent 6a6f37460d
commit b6933816b8
5 changed files with 110 additions and 9 deletions

View File

@ -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.

View File

@ -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

68
mark.lua Normal file
View File

@ -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,
})

BIN
textures/worldedit_pos1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

BIN
textures/worldedit_pos2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B