forked from mtcontrib/Minetest-WorldEdit
Version MFF
This commit is contained in:
1
worldedit_commands/.gitignore
vendored
Normal file
1
worldedit_commands/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*~
|
240
worldedit_commands/cuboid.lua
Normal file
240
worldedit_commands/cuboid.lua
Normal file
@ -0,0 +1,240 @@
|
||||
minetest.register_chatcommand("/outset", {
|
||||
params = "[h|v] <amount>",
|
||||
description = "outset the selection",
|
||||
privs = {worldedit=true},
|
||||
func = function(name, param)
|
||||
local find, _, dir, amount = param:find("(%a*)%s*([+-]?%d+)")
|
||||
|
||||
if find == nil then
|
||||
return false, "invalid usage: " .. param
|
||||
end
|
||||
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local pos2 = worldedit.pos2[name]
|
||||
|
||||
if pos1 == nil or pos2 == nil then
|
||||
return false,
|
||||
"Undefined region. Region must be defined beforehand."
|
||||
end
|
||||
|
||||
local hv_test = dir:find("[^hv]+")
|
||||
|
||||
if hv_test ~= nil then
|
||||
return false, "Invalid direction."
|
||||
end
|
||||
|
||||
if dir == "" or dir == "hv" or dir == "vh" then
|
||||
assert(worldedit.cuboid_volumetric_expand(name, amount))
|
||||
elseif dir == "h" then
|
||||
assert(worldedit.cuboid_linear_expand(name, 'x', 1, amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'x', -1, amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'z', 1, amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'z', -1, amount))
|
||||
elseif dir == "v" then
|
||||
assert(worldedit.cuboid_linear_expand(name, 'y', 1, amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'y', -1, amount))
|
||||
else
|
||||
return false, "Invalid number of arguments"
|
||||
end
|
||||
|
||||
worldedit.marker_update(name)
|
||||
return true, "Region outset by " .. amount .. " blocks"
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
minetest.register_chatcommand("/inset", {
|
||||
params = "[h|v] <amount>",
|
||||
description = "inset the selection",
|
||||
privs = {worldedit=true},
|
||||
func = function(name, param)
|
||||
local find, _, dir, amount = param:find("(%a*)%s*([+-]?%d+)")
|
||||
|
||||
if find == nil then
|
||||
return false, "invalid usage: " .. param
|
||||
end
|
||||
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local pos2 = worldedit.pos2[name]
|
||||
|
||||
if pos1 == nil or pos2 == nil then
|
||||
return false,
|
||||
"Undefined region. Region must be defined beforehand."
|
||||
end
|
||||
|
||||
local hv_test = dir:find("[^hv]+")
|
||||
|
||||
if hv_test ~= nil then
|
||||
return false, "Invalid direction."
|
||||
end
|
||||
|
||||
if dir == "" or dir == "vh" or dir == "hv" then
|
||||
assert(worldedit.cuboid_volumetric_expand(name, -amount))
|
||||
elseif dir == "h" then
|
||||
assert(worldedit.cuboid_linear_expand(name, 'x', 1, -amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'x', -1, -amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'z', 1, -amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'z', -1, -amount))
|
||||
elseif dir == "v" then
|
||||
assert(worldedit.cuboid_linear_expand(name, 'y', 1, -amount))
|
||||
assert(worldedit.cuboid_linear_expand(name, 'y', -1, -amount))
|
||||
else
|
||||
return false, "Invalid number of arguments"
|
||||
end
|
||||
|
||||
worldedit.marker_update(name)
|
||||
return true, "Region inset by " .. amount .. " blocks"
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
minetest.register_chatcommand("/shift", {
|
||||
params = "[x|y|z|?|up|down|left|right|front|back] [+|-]<amount>",
|
||||
description = "Moves the selection region. Does not move contents.",
|
||||
privs = {worldedit=true},
|
||||
func = function(name, param)
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local pos2 = worldedit.pos2[name]
|
||||
local find, _, direction, amount = param:find("([%?%l]+)%s*([+-]?%d+)")
|
||||
|
||||
if find == nil then
|
||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||
return
|
||||
end
|
||||
|
||||
if pos1 == nil or pos2 == nil then
|
||||
worldedit.player_notify(name,
|
||||
"Undefined region. Region must be defined beforehand.")
|
||||
return
|
||||
end
|
||||
|
||||
local axis, dir
|
||||
if direction == "x" or direction == "y" or direction == "z" then
|
||||
axis, dir = direction, 1
|
||||
elseif direction == "?" then
|
||||
axis, dir = worldedit.player_axis(name)
|
||||
else
|
||||
axis, dir = worldedit.translate_direction(name, direction)
|
||||
end
|
||||
|
||||
if axis == nil or dir == nil then
|
||||
return false, "Invalid if looking straight up or down"
|
||||
end
|
||||
|
||||
assert(worldedit.cuboid_shift(name, axis, amount * dir))
|
||||
worldedit.marker_update(name)
|
||||
|
||||
return true, "Region shifted by " .. amount .. " nodes"
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
minetest.register_chatcommand("/expand", {
|
||||
params = "[+|-]<x|y|z|?|up|down|left|right|front|back> <amount> [reverse-amount]",
|
||||
description = "expand the selection in one or two directions at once",
|
||||
privs = {worldedit=true},
|
||||
func = function(name, param)
|
||||
local find, _, sign, direction, amount,
|
||||
rev_amount = param:find("([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)")
|
||||
|
||||
if find == nil then
|
||||
worldedit.player_notify(name, "invalid use: " .. param)
|
||||
return
|
||||
end
|
||||
|
||||
if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then
|
||||
worldedit.player_notify(name,
|
||||
"Undefined region. Region must be defined beforehand.")
|
||||
return
|
||||
end
|
||||
|
||||
local absolute = direction:find("[xyz?]")
|
||||
local dir, axis
|
||||
|
||||
if rev_amount == "" then
|
||||
rev_amount = 0
|
||||
end
|
||||
|
||||
if absolute == nil then
|
||||
axis, dir = worldedit.translate_direction(name, direction)
|
||||
|
||||
if axis == nil or dir == nil then
|
||||
return false, "Invalid if looking straight up or down"
|
||||
end
|
||||
else
|
||||
if direction == "?" then
|
||||
axis, dir = worldedit.player_axis(name)
|
||||
else
|
||||
axis = direction
|
||||
dir = 1
|
||||
end
|
||||
end
|
||||
|
||||
if sign == "-" then
|
||||
dir = -dir
|
||||
end
|
||||
|
||||
worldedit.cuboid_linear_expand(name, axis, dir, amount)
|
||||
worldedit.cuboid_linear_expand(name, axis, -dir, rev_amount)
|
||||
worldedit.marker_update(name)
|
||||
return true, "Region expanded by " .. (amount + rev_amount) .. " nodes"
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
minetest.register_chatcommand("/contract", {
|
||||
params = "[+|-]<x|y|z|?|up|down|left|right|front|back> <amount> [reverse-amount]",
|
||||
description = "contract the selection in one or two directions at once",
|
||||
privs = {worldedit=true},
|
||||
func = function(name, param)
|
||||
local find, _, sign, direction, amount,
|
||||
rev_amount = param:find("([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)")
|
||||
|
||||
if find == nil then
|
||||
worldedit.player_notify(name, "invalid use: " .. param)
|
||||
return
|
||||
end
|
||||
|
||||
if worldedit.pos1[name] == nil or worldedit.pos2[name] == nil then
|
||||
worldedit.player_notify(name,
|
||||
"Undefined region. Region must be defined beforehand.")
|
||||
return
|
||||
end
|
||||
|
||||
local absolute = direction:find("[xyz?]")
|
||||
local dir, axis
|
||||
|
||||
if rev_amount == "" then
|
||||
rev_amount = 0
|
||||
end
|
||||
|
||||
if absolute == nil then
|
||||
axis, dir = worldedit.translate_direction(name, direction)
|
||||
|
||||
if axis == nil or dir == nil then
|
||||
return false, "Invalid if looking straight up or down"
|
||||
end
|
||||
else
|
||||
if direction == "?" then
|
||||
axis, dir = worldedit.player_axis(name)
|
||||
else
|
||||
axis = direction
|
||||
dir = 1
|
||||
end
|
||||
end
|
||||
|
||||
if sign == "-" then
|
||||
dir = -dir
|
||||
end
|
||||
|
||||
worldedit.cuboid_linear_expand(name, axis, dir, -amount)
|
||||
worldedit.cuboid_linear_expand(name, axis, -dir, -rev_amount)
|
||||
worldedit.marker_update(name)
|
||||
return true, "Region contracted by " .. (amount + rev_amount) .. " nodes"
|
||||
end,
|
||||
}
|
||||
)
|
0
worldedit_commands/depends.txt
Normal file → Executable file
0
worldedit_commands/depends.txt
Normal file → Executable file
@ -10,10 +10,12 @@ if minetest.place_schematic then
|
||||
worldedit.prob_list = {}
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("worldedit_commands") .. "/cuboid.lua")
|
||||
dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")
|
||||
dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua"); safe_region = safe_region or function(callback) return callback end
|
||||
dofile(minetest.get_modpath("worldedit_commands") .. "/wand.lua")
|
||||
local safe_region, check_region, reset_pending = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")
|
||||
|
||||
local get_position = function(name) --position 1 retrieval function for when not using `safe_region`
|
||||
local function get_position(name) --position 1 retrieval function for when not using `safe_region`
|
||||
local pos1 = worldedit.pos1[name]
|
||||
if pos1 == nil then
|
||||
worldedit.player_notify(name, "no position 1 selected")
|
||||
@ -21,7 +23,7 @@ local get_position = function(name) --position 1 retrieval function for when not
|
||||
return pos1
|
||||
end
|
||||
|
||||
local get_node = function(name, nodename)
|
||||
local function get_node(name, nodename)
|
||||
local node = worldedit.normalize_nodename(nodename)
|
||||
if not node then
|
||||
worldedit.player_notify(name, "invalid node name: " .. nodename)
|
||||
@ -30,7 +32,7 @@ local get_node = function(name, nodename)
|
||||
return node
|
||||
end
|
||||
|
||||
worldedit.player_notify = function(name, message)
|
||||
function worldedit.player_notify(name, message)
|
||||
minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)
|
||||
end
|
||||
|
||||
@ -56,8 +58,8 @@ worldedit.normalize_nodename = function(nodename)
|
||||
return nil
|
||||
end
|
||||
|
||||
--determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
|
||||
worldedit.player_axis = function(name)
|
||||
-- Determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
|
||||
function worldedit.player_axis(name)
|
||||
local dir = minetest.get_player_by_name(name):get_look_dir()
|
||||
local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
|
||||
if x > y then
|
||||
@ -70,6 +72,19 @@ worldedit.player_axis = function(name)
|
||||
return "z", dir.z > 0 and 1 or -1
|
||||
end
|
||||
|
||||
local function mkdir(path)
|
||||
if minetest.mkdir then
|
||||
minetest.mkdir(path)
|
||||
else
|
||||
os.execute('mkdir "' .. path .. '"')
|
||||
end
|
||||
end
|
||||
|
||||
local function check_filename(name)
|
||||
return name:find("^[%w%s%^&'@{}%[%],%$=!%-#%(%)%%%.%+~_]+$") ~= nil
|
||||
end
|
||||
|
||||
|
||||
minetest.register_chatcommand("/about", {
|
||||
params = "",
|
||||
description = "Get information about the mod",
|
||||
@ -78,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",
|
||||
@ -97,16 +162,28 @@ minetest.register_chatcommand("/inspect", {
|
||||
end,
|
||||
})
|
||||
|
||||
local function get_node_rlight(pos)
|
||||
local vecs = { -- neighboring nodes
|
||||
{x= 1, y= 0, z= 0},
|
||||
{x=-1, y= 0, z= 0},
|
||||
{x= 0, y= 1, z= 0},
|
||||
{x= 0, y=-1, z= 0},
|
||||
{x= 0, y= 0, z= 1},
|
||||
{x= 0, y= 0, z=-1},
|
||||
}
|
||||
local ret = 0
|
||||
for _, v in ipairs(vecs) do
|
||||
ret = math.max(ret, minetest.get_node_light(vector.add(pos, v)))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
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, received light=%d) punched facing the %s axis",
|
||||
node.name, minetest.pos_to_string(pos), node.param1, node.param2, get_node_rlight(pos), axis .. (sign > 0 and "+" or "-"))
|
||||
worldedit.player_notify(name, message)
|
||||
end
|
||||
end)
|
||||
@ -121,6 +198,8 @@ minetest.register_chatcommand("/reset", {
|
||||
worldedit.mark_pos1(name)
|
||||
worldedit.mark_pos2(name)
|
||||
worldedit.set_pos[name] = nil
|
||||
--make sure the user does not try to confirm an operation after resetting pos:
|
||||
reset_pending(name)
|
||||
worldedit.player_notify(name, "region reset")
|
||||
end,
|
||||
})
|
||||
@ -277,6 +356,21 @@ minetest.register_chatcommand("/volume", {
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("/deleteblocks", {
|
||||
params = "",
|
||||
description = "remove all MapBlocks (16x16x16) containing the selected area from the map",
|
||||
privs = {worldedit=true},
|
||||
func = safe_region(function(name, param)
|
||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||
local success = minetest.delete_area(pos1, pos2)
|
||||
if success then
|
||||
worldedit.player_notify(name, "Area deleted.")
|
||||
else
|
||||
worldedit.player_notify(name, "There was an error during deletion of the area.")
|
||||
end
|
||||
end),
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("/set", {
|
||||
params = "<node>",
|
||||
description = "Set the current WorldEdit region to <node>",
|
||||
@ -488,6 +582,39 @@ minetest.register_chatcommand("/cylinder", {
|
||||
end, check_cylinder),
|
||||
})
|
||||
|
||||
local check_pyramid = function(name, param)
|
||||
if worldedit.pos1[name] == nil then
|
||||
worldedit.player_notify(name, "no position 1 selected")
|
||||
return nil
|
||||
end
|
||||
local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
|
||||
if found == nil then
|
||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||
return nil
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
if not node then return nil end
|
||||
height = tonumber(height)
|
||||
return math.ceil(((height * 2 + 1) ^ 2) * height / 3)
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("/hollowpyramid", {
|
||||
params = "x/y/z/? <height> <node>",
|
||||
description = "Add hollow pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",
|
||||
privs = {worldedit=true},
|
||||
func = safe_region(function(name, param)
|
||||
local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
|
||||
height = tonumber(height)
|
||||
if axis == "?" then
|
||||
axis, sign = worldedit.player_axis(name)
|
||||
height = height * sign
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node, true)
|
||||
worldedit.player_notify(name, count .. " nodes added")
|
||||
end, check_pyramid),
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("/pyramid", {
|
||||
params = "x/y/z/? <height> <node>",
|
||||
description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",
|
||||
@ -502,22 +629,7 @@ minetest.register_chatcommand("/pyramid", {
|
||||
local node = get_node(name, nodename)
|
||||
local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node)
|
||||
worldedit.player_notify(name, count .. " nodes added")
|
||||
end,
|
||||
function(name, param)
|
||||
if worldedit.pos1[name] == nil then
|
||||
worldedit.player_notify(name, "no position 1 selected")
|
||||
return nil
|
||||
end
|
||||
local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
|
||||
if found == nil then
|
||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||
return nil
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
if not node then return nil end
|
||||
height = tonumber(height)
|
||||
return math.ceil(((height * 2 + 1) ^ 2) * height / 3)
|
||||
end),
|
||||
end, check_pyramid),
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("/spiral", {
|
||||
@ -542,7 +654,7 @@ minetest.register_chatcommand("/spiral", {
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
if not node then return nil end
|
||||
return check_region(name, param)
|
||||
return 1 -- TODO: return an useful value
|
||||
end),
|
||||
})
|
||||
|
||||
@ -810,6 +922,30 @@ minetest.register_chatcommand("/fixlight", {
|
||||
end),
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("/drain", {
|
||||
params = "",
|
||||
description = "Remove any fluid node within the current WorldEdit region",
|
||||
privs = {worldedit=true},
|
||||
func = safe_region(function(name, param)
|
||||
-- TODO: make an API function for this
|
||||
local count = 0
|
||||
local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name])
|
||||
for x = pos1.x, pos2.x do
|
||||
for y = pos1.y, pos2.y do
|
||||
for z = pos1.z, pos2.z do
|
||||
local n = minetest.get_node({x=x, y=y, z=z}).name
|
||||
local d = minetest.registered_nodes[n]
|
||||
if d ~= nil and (d["drawtype"] == "liquid" or d["drawtype"] == "flowingliquid") then
|
||||
minetest.remove_node({x=x, y=y, z=z})
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
worldedit.player_notify(name, count .. " nodes updated")
|
||||
end),
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("/hide", {
|
||||
params = "",
|
||||
description = "Hide all nodes in the current WorldEdit region non-destructively",
|
||||
@ -861,20 +997,21 @@ minetest.register_chatcommand("/save", {
|
||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||
return
|
||||
end
|
||||
if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then
|
||||
worldedit.player_notify(name, "invalid file name: " .. param)
|
||||
if not check_filename(param) then
|
||||
worldedit.player_notify(name, "Disallowed file name: " .. param)
|
||||
return
|
||||
end
|
||||
|
||||
local result, count = worldedit.serialize(worldedit.pos1[name], worldedit.pos2[name])
|
||||
local result, count = worldedit.serialize(worldedit.pos1[name],
|
||||
worldedit.pos2[name])
|
||||
|
||||
local path = minetest.get_worldpath() .. "/schems"
|
||||
-- Create directory if it does not already exist
|
||||
mkdir(path)
|
||||
|
||||
local filename = path .. "/" .. param .. ".we"
|
||||
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\") --escape any nasty characters
|
||||
os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
|
||||
local file, err = io.open(filename, "wb")
|
||||
if err ~= nil then
|
||||
worldedit.player_notify(name, "could not save file to \"" .. filename .. "\"")
|
||||
worldedit.player_notify(name, "Could not save file to \"" .. filename .. "\"")
|
||||
return
|
||||
end
|
||||
file:write(result)
|
||||
@ -897,8 +1034,8 @@ minetest.register_chatcommand("/allocate", {
|
||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||
return
|
||||
end
|
||||
if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then
|
||||
worldedit.player_notify(name, "invalid file name: " .. param)
|
||||
if not check_filename(param) then
|
||||
worldedit.player_notify(name, "Disallowed file name: " .. param)
|
||||
return
|
||||
end
|
||||
|
||||
@ -986,11 +1123,6 @@ minetest.register_chatcommand("/lua", {
|
||||
description = "Executes <code> as a Lua chunk in the global namespace",
|
||||
privs = {worldedit=true, server=true},
|
||||
func = function(name, param)
|
||||
local admin = minetest.setting_get("name")
|
||||
if not admin or not name == admin then
|
||||
worldedit.player_notify(name, "this command can only be run by the server administrator")
|
||||
return
|
||||
end
|
||||
local err = worldedit.lua(param)
|
||||
if err then
|
||||
worldedit.player_notify(name, "code error: " .. err)
|
||||
@ -1005,12 +1137,6 @@ minetest.register_chatcommand("/luatransform", {
|
||||
description = "Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region",
|
||||
privs = {worldedit=true, server=true},
|
||||
func = safe_region(function(name, param)
|
||||
local admin = minetest.setting_get("name")
|
||||
if not admin or not name == admin then
|
||||
worldedit.player_notify(name, "this command can only be run by the server administrator")
|
||||
return
|
||||
end
|
||||
|
||||
local err = worldedit.luatransform(worldedit.pos1[name], worldedit.pos2[name], param)
|
||||
if err then
|
||||
worldedit.player_notify(name, "code error: " .. err, false)
|
||||
@ -1022,24 +1148,31 @@ minetest.register_chatcommand("/luatransform", {
|
||||
|
||||
minetest.register_chatcommand("/mtschemcreate", {
|
||||
params = "<file>",
|
||||
description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/<filename>.mts\"",
|
||||
description = "Save the current WorldEdit region using the Minetest "..
|
||||
"Schematic format to \"(world folder)/schems/<filename>.mts\"",
|
||||
privs = {worldedit=true},
|
||||
func = safe_region(function(name, param)
|
||||
if param == nil then
|
||||
worldedit.player_notify(name, "No filename specified")
|
||||
return
|
||||
end
|
||||
if not check_filename(param) then
|
||||
worldedit.player_notify(name, "Disallowed file name: " .. param)
|
||||
return
|
||||
end
|
||||
|
||||
local path = minetest.get_worldpath() .. "/schems"
|
||||
local filename = path .. "/" .. param .. ".mts"
|
||||
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\") --escape any nasty characters
|
||||
os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
|
||||
-- Create directory if it does not already exist
|
||||
mkdir(path)
|
||||
|
||||
local ret = minetest.create_schematic(worldedit.pos1[name], worldedit.pos2[name], worldedit.prob_list[name], filename)
|
||||
local filename = path .. "/" .. param .. ".mts"
|
||||
local ret = minetest.create_schematic(worldedit.pos1[name],
|
||||
worldedit.pos2[name], worldedit.prob_list[name],
|
||||
filename)
|
||||
if ret == nil then
|
||||
worldedit.player_notify(name, "failed to create Minetest schematic", false)
|
||||
worldedit.player_notify(name, "Failed to create Minetest schematic", false)
|
||||
else
|
||||
worldedit.player_notify(name, "saved Minetest schematic to " .. param, false)
|
||||
worldedit.player_notify(name, "Saved Minetest schematic to " .. param, false)
|
||||
end
|
||||
worldedit.prob_list[name] = {}
|
||||
end),
|
||||
@ -1050,10 +1183,14 @@ minetest.register_chatcommand("/mtschemplace", {
|
||||
description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",
|
||||
privs = {worldedit=true},
|
||||
func = function(name, param)
|
||||
if param == nil then
|
||||
if param == "" then
|
||||
worldedit.player_notify(name, "no filename specified")
|
||||
return
|
||||
end
|
||||
if not check_filename(param) then
|
||||
worldedit.player_notify(name, "Disallowed file name: " .. param)
|
||||
return
|
||||
end
|
||||
|
||||
local pos = get_position(name)
|
||||
if pos == nil then return end
|
||||
@ -1087,8 +1224,8 @@ minetest.register_chatcommand("/mtschemprob", {
|
||||
return
|
||||
end
|
||||
for k,v in pairs(problist) do
|
||||
local prob = math.floor(((v["prob"] / 256) * 100) * 100 + 0.5) / 100
|
||||
text = text .. minetest.pos_to_string(v["pos"]) .. ": " .. prob .. "% | "
|
||||
local prob = math.floor(((v.prob / 256) * 100) * 100 + 0.5) / 100
|
||||
text = text .. minetest.pos_to_string(v.pos) .. ": " .. prob .. "% | "
|
||||
end
|
||||
worldedit.player_notify(name, "currently set node probabilities:")
|
||||
worldedit.player_notify(name, text)
|
||||
@ -1098,16 +1235,14 @@ minetest.register_chatcommand("/mtschemprob", {
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_on_player_receive_fields(
|
||||
function(player, formname, fields)
|
||||
if (formname == "prob_val_enter") and (fields.text ~= "") then
|
||||
local name = player:get_player_name()
|
||||
local prob_entry = {pos=worldedit.prob_pos[name], prob=tonumber(fields.text)}
|
||||
local index = table.getn(worldedit.prob_list[name]) + 1
|
||||
worldedit.prob_list[name][index] = prob_entry
|
||||
end
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "prob_val_enter" and not (fields.text == "" or fields.text == nil) then
|
||||
local name = player:get_player_name()
|
||||
local prob_entry = {pos=worldedit.prob_pos[name], prob=tonumber(fields.text)}
|
||||
local index = table.getn(worldedit.prob_list[name]) + 1
|
||||
worldedit.prob_list[name][index] = prob_entry
|
||||
end
|
||||
)
|
||||
end)
|
||||
|
||||
minetest.register_chatcommand("/clearobjects", {
|
||||
params = "",
|
||||
|
@ -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
|
||||
@ -153,7 +168,11 @@ minetest.register_entity(":worldedit:region_cube", {
|
||||
end
|
||||
end,
|
||||
on_punch = function(self, hitter)
|
||||
for _, entity in ipairs(worldedit.marker_region[self.player_name]) do
|
||||
local markers = worldedit.marker_region[self.player_name]
|
||||
if not markers then
|
||||
return
|
||||
end
|
||||
for _, entity in ipairs(markers) do
|
||||
entity:remove()
|
||||
end
|
||||
worldedit.marker_region[self.player_name] = nil
|
||||
|
@ -1,7 +1,7 @@
|
||||
local safe_region_callback = {}
|
||||
local safe_region_param = {}
|
||||
|
||||
check_region = function(name, param)
|
||||
local function check_region(name, param)
|
||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions
|
||||
if pos1 == nil or pos2 == nil then
|
||||
worldedit.player_notify(name, "no region selected")
|
||||
@ -12,7 +12,7 @@ end
|
||||
|
||||
--`callback` is a callback to run when the user confirms
|
||||
--`nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed
|
||||
safe_region = function(callback, nodes_needed)
|
||||
local function safe_region(callback, nodes_needed)
|
||||
--default node volume calculation
|
||||
nodes_needed = nodes_needed or check_region
|
||||
|
||||
@ -30,6 +30,10 @@ safe_region = function(callback, nodes_needed)
|
||||
end
|
||||
end
|
||||
|
||||
local function reset_pending(name)
|
||||
safe_region_callback[name], safe_region_param[name] = nil, nil
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("/y", {
|
||||
params = "",
|
||||
description = "Confirm a pending operation",
|
||||
@ -40,15 +44,8 @@ minetest.register_chatcommand("/y", {
|
||||
return
|
||||
end
|
||||
|
||||
--obtain positions
|
||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||
if pos1 == nil or pos2 == nil then
|
||||
worldedit.player_notify(name, "no region selected")
|
||||
return
|
||||
end
|
||||
|
||||
safe_region_callback[name], safe_region_param[name] = nil, nil --reset pending operation
|
||||
callback(name, param, pos1, pos2)
|
||||
callback(name, param)
|
||||
end,
|
||||
})
|
||||
|
||||
@ -63,3 +60,6 @@ minetest.register_chatcommand("/n", {
|
||||
safe_region_callback[name], safe_region_param[name] = nil, nil
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
return safe_region, check_region, reset_pending
|
||||
|
24
worldedit_commands/wand.lua
Normal file
24
worldedit_commands/wand.lua
Normal file
@ -0,0 +1,24 @@
|
||||
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
|
||||
|
||||
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,
|
||||
})
|
Reference in New Issue
Block a user