diff options
Diffstat (limited to 'worldedit_commands')
-rw-r--r-- | worldedit_commands/init.lua | 61 | ||||
-rw-r--r-- | worldedit_commands/mark.lua | 41 | ||||
-rw-r--r-- | worldedit_commands/wand.lua | 34 |
3 files changed, 116 insertions, 20 deletions
diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index b9313cc..d47c6e2 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -12,6 +12,7 @@ end dofile(minetest.get_modpath("worldedit_commands") .. "/cuboid.lua")
dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")
+dofile(minetest.get_modpath("worldedit_commands") .. "/wand.lua")
local safe_region, check_region = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")
local function get_position(name) --position 1 retrieval function for when not using `safe_region`
@@ -92,6 +93,56 @@ minetest.register_chatcommand("/about", { end,
})
+-- mostly copied from builtin/chatcommands.lua with minor modifications
+minetest.register_chatcommand("/help", {
+ privs = {},
+ params = "[all/<cmd>]",
+ description = "Get help for WorldEdit commands",
+ func = function(name, param)
+ local function is_we_command(cmd)
+ return cmd:sub(0, 1) == "/"
+ end
+ local function format_help_line(cmd, def)
+ local msg = minetest.colorize("#00ffff", "/"..cmd)
+ if def.params and def.params ~= "" then
+ msg = msg .. " " .. def.params
+ end
+ if def.description and def.description ~= "" then
+ msg = msg .. ": " .. def.description
+ end
+ return msg
+ end
+
+ if not minetest.check_player_privs(name, "worldedit") then
+ return false, "You are not allowed to use any WorldEdit commands."
+ end
+ if param == "" then
+ local msg = ""
+ local cmds = {}
+ for cmd, def in pairs(minetest.chatcommands) do
+ if is_we_command(cmd) and minetest.check_player_privs(name, def.privs) then
+ cmds[#cmds + 1] = cmd:sub(2) -- strip the /
+ end
+ end
+ table.sort(cmds)
+ return true, "Available commands: " .. table.concat(cmds, " ") .. "\n"
+ .. "Use '//help <cmd>' to get more information,"
+ .. " or '//help all' to list everything."
+ elseif param == "all" then
+ local cmds = {}
+ for cmd, def in pairs(minetest.chatcommands) do
+ if is_we_command(cmd) and minetest.check_player_privs(name, def.privs) then
+ cmds[#cmds + 1] = format_help_line(cmd, def)
+ end
+ end
+ table.sort(cmds)
+ return true, "Available commands:\n"..table.concat(cmds, "\n")
+ else
+ return minetest.chatcommands["help"].func(name, "/" .. param)
+ end
+ end,
+})
+
minetest.register_chatcommand("/inspect", {
params = "on/off/1/0/true/false/yes/no/enable/disable/<blank>",
description = "Enable or disable node inspection",
@@ -114,13 +165,9 @@ minetest.register_chatcommand("/inspect", { minetest.register_on_punchnode(function(pos, node, puncher)
local name = puncher:get_player_name()
if worldedit.inspect[name] then
- if minetest.check_player_privs(name, {worldedit=true}) then
- local axis, sign = worldedit.player_axis(name)
- message = string.format("inspector: %s at %s (param1=%d, param2=%d) punched by %s facing the %s axis",
- node.name, minetest.pos_to_string(pos), node.param1, node.param2, name, axis .. (sign > 0 and "+" or "-"))
- else
- message = "inspector: worldedit privileges required"
- end
+ local axis, sign = worldedit.player_axis(name)
+ message = string.format("inspector: %s at %s (param1=%d, param2=%d, light=%d) punched facing the %s axis",
+ node.name, minetest.pos_to_string(pos), node.param1, node.param2, minetest.get_node_light(pos), axis .. (sign > 0 and "+" or "-"))
worldedit.player_notify(name, message)
end
end)
diff --git a/worldedit_commands/mark.lua b/worldedit_commands/mark.lua index 7f880ea..9d41bda 100644 --- a/worldedit_commands/mark.lua +++ b/worldedit_commands/mark.lua @@ -58,8 +58,19 @@ worldedit.mark_region = function(name) end
worldedit.marker_region[name] = nil
end
+
if pos1 ~= nil and pos2 ~= nil then
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
+
+ local vec = vector.subtract(pos2, pos1)
+ local maxside = math.max(vec.x, math.max(vec.y, vec.z))
+ local limit = tonumber(minetest.setting_get("active_object_send_range_blocks")) * 16
+ if maxside > limit * 1.5 then
+ -- The client likely won't be able to see the plane markers as intended anyway,
+ -- thus don't place them and also don't load the area into memory
+ return
+ end
+
local thickness = 0.2
local sizex, sizey, sizez = (1 + pos2.x - pos1.x) / 2, (1 + pos2.y - pos1.y) / 2, (1 + pos2.z - pos1.z) / 2
@@ -72,24 +83,28 @@ worldedit.mark_region = function(name) --XY plane markers
for _, z in ipairs({pos1.z - 0.5, pos2.z + 0.5}) do
local marker = minetest.add_entity({x=pos1.x + sizex - 0.5, y=pos1.y + sizey - 0.5, z=z}, "worldedit:region_cube")
- marker:set_properties({
- visual_size={x=sizex * 2, y=sizey * 2},
- collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
- })
- marker:get_luaentity().player_name = name
- table.insert(markers, marker)
+ if marker ~= nil then
+ marker:set_properties({
+ visual_size={x=sizex * 2, y=sizey * 2},
+ collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
+ })
+ marker:get_luaentity().player_name = name
+ table.insert(markers, marker)
+ end
end
--YZ plane markers
for _, x in ipairs({pos1.x - 0.5, pos2.x + 0.5}) do
local marker = minetest.add_entity({x=x, y=pos1.y + sizey - 0.5, z=pos1.z + sizez - 0.5}, "worldedit:region_cube")
- marker:set_properties({
- visual_size={x=sizez * 2, y=sizey * 2},
- collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
- })
- marker:setyaw(math.pi / 2)
- marker:get_luaentity().player_name = name
- table.insert(markers, marker)
+ if marker ~= nil then
+ marker:set_properties({
+ visual_size={x=sizez * 2, y=sizey * 2},
+ collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
+ })
+ marker:setyaw(math.pi / 2)
+ marker:get_luaentity().player_name = name
+ table.insert(markers, marker)
+ end
end
worldedit.marker_region[name] = markers
diff --git a/worldedit_commands/wand.lua b/worldedit_commands/wand.lua new file mode 100644 index 0000000..79d9eb2 --- /dev/null +++ b/worldedit_commands/wand.lua @@ -0,0 +1,34 @@ +minetest.register_tool(":worldedit:wand", { + description = "WorldEdit Wand tool, Left-click to set 1st position, right-click to set 2nd", + inventory_image = "worldedit_wand.png", + stack_max = 1, -- there is no need to have more than one + liquids_pointable = true, -- ground with only water on can be selected as well + -- the tool_capabilities are completely irrelevant here - no need to dig + tool_capabilities = { + full_punch_interval = 1.0, + max_drop_level = 0, + groupcaps={ + fleshy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1}, + snappy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1}, + choppy={times={[3]=0.90}, maxwear=0.05, maxlevel=0} + } + }, + + on_use = function(itemstack, placer, pointed_thing) + if placer ~= nil and pointed_thing ~= nil and pointed_thing.type == "node" then + local name = placer:get_player_name() + worldedit.pos1[name] = pointed_thing.under + worldedit.mark_pos1(name) + end + return itemstack -- nothing consumed, nothing changed + end, + + on_place = function(itemstack, placer, pointed_thing) -- Left Click + if placer ~= nil and pointed_thing ~= nil and pointed_thing.type == "node" then + local name = placer:get_player_name() + worldedit.pos2[name] = pointed_thing.under + worldedit.mark_pos2(name) + end + return itemstack -- nothing consumed, nothing changed + end, +}) |