1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-01-23 16:30:19 +01:00

Updated WorldEdit

This commit is contained in:
LeMagnesium 2015-05-19 20:28:05 +02:00
parent b8cee76680
commit 2ffbab6556
4 changed files with 45 additions and 28 deletions

View File

@ -23,7 +23,7 @@ end
local path = minetest.get_modpath(minetest.get_current_modname()) local path = minetest.get_modpath(minetest.get_current_modname())
local function load_module(path) local function load_module(path)
local file = io.open(path) local file = io.open(path, "r")
if not file then return end if not file then return end
file:close() file:close()
return dofile(path) return dofile(path)

View File

@ -503,8 +503,8 @@ function worldedit.orient(pos1, pos2, angle)
worldedit.keep_loaded(pos1, pos2) worldedit.keep_loaded(pos1, pos2)
local count = 0 local count = 0
local get_node, get_meta, swap_node = minetest.get_node, local set_node, get_node, get_meta, swap_node = minetest.set_node,
minetest.get_meta, minetest.swap_node minetest.get_node, minetest.get_meta, minetest.swap_node
local pos = {x=pos1.x, y=0, z=0} local pos = {x=pos1.x, y=0, z=0}
while pos.x <= pos2.x do while pos.x <= pos2.x do
pos.y = pos1.y pos.y = pos1.y

View File

@ -11,9 +11,9 @@ if minetest.place_schematic then
end end
dofile(minetest.get_modpath("worldedit_commands") .. "/mark.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 local safe_region, check_region = 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] local pos1 = worldedit.pos1[name]
if pos1 == nil then if pos1 == nil then
worldedit.player_notify(name, "no position 1 selected") worldedit.player_notify(name, "no position 1 selected")
@ -21,7 +21,7 @@ local get_position = function(name) --position 1 retrieval function for when not
return pos1 return pos1
end end
local get_node = function(name, nodename) local function get_node(name, nodename)
local node = worldedit.normalize_nodename(nodename) local node = worldedit.normalize_nodename(nodename)
if not node then if not node then
worldedit.player_notify(name, "invalid node name: " .. nodename) worldedit.player_notify(name, "invalid node name: " .. nodename)
@ -30,7 +30,7 @@ local get_node = function(name, nodename)
return node return node
end end
worldedit.player_notify = function(name, message) function worldedit.player_notify(name, message)
minetest.chat_send_player(name, "WorldEdit -!- " .. message, false) minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)
end end
@ -56,8 +56,8 @@ worldedit.normalize_nodename = function(nodename)
return nil return nil
end end
--determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1) -- 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) function worldedit.player_axis(name)
local dir = minetest.get_player_by_name(name):get_look_dir() 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) local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
if x > y then if x > y then
@ -70,6 +70,15 @@ worldedit.player_axis = function(name)
return "z", dir.z > 0 and 1 or -1 return "z", dir.z > 0 and 1 or -1
end end
function worldedit.mkdir(path)
if minetest.mkdir then
minetest.mkdir(path)
else
os.execute('mkdir "' .. path .. '"')
end
end
minetest.register_chatcommand("/about", { minetest.register_chatcommand("/about", {
params = "", params = "",
description = "Get information about the mod", description = "Get information about the mod",
@ -802,10 +811,6 @@ minetest.register_chatcommand("/orient", {
worldedit.player_notify(name, count .. " nodes oriented") worldedit.player_notify(name, count .. " nodes oriented")
end, end,
function(name, param) function(name, param)
if param == nil then
minetest.log("error","No parameters given to /orient WE's command!")
return
end
local found, _, angle = param:find("^([+-]?%d+)$") local found, _, angle = param:find("^([+-]?%d+)$")
if found == nil then if found == nil then
worldedit.player_notify(name, "invalid usage: " .. param) worldedit.player_notify(name, "invalid usage: " .. param)
@ -880,20 +885,22 @@ minetest.register_chatcommand("/save", {
worldedit.player_notify(name, "invalid usage: " .. param) worldedit.player_notify(name, "invalid usage: " .. param)
return return
end end
if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then if not param:find("^[a-zA-Z0-9_%-.]+$") then
worldedit.player_notify(name, "invalid file name: " .. param) worldedit.player_notify(name, "Disallowed file name: " .. param)
return return
end 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" local path = minetest.get_worldpath() .. "/schems"
-- Create directory if it does not already exist
worldedit.mkdir(path)
local filename = path .. "/" .. param .. ".we" 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") local file, err = io.open(filename, "wb")
if err ~= nil then 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 return
end end
file:write(result) file:write(result)
@ -1041,24 +1048,31 @@ minetest.register_chatcommand("/luatransform", {
minetest.register_chatcommand("/mtschemcreate", { minetest.register_chatcommand("/mtschemcreate", {
params = "<file>", 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}, privs = {worldedit=true},
func = safe_region(function(name, param) func = safe_region(function(name, param)
if param == nil then if param == nil then
worldedit.player_notify(name, "No filename specified") worldedit.player_notify(name, "No filename specified")
return return
end end
if not param:find("^[a-zA-Z0-9_%-.]+$") then
worldedit.player_notify(name, "Disallowed file name: " .. param)
return
end
local path = minetest.get_worldpath() .. "/schems" local path = minetest.get_worldpath() .. "/schems"
local filename = path .. "/" .. param .. ".mts" -- Create directory if it does not already exist
filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\") --escape any nasty characters worldedit.mkdir(path)
os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist
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 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 else
worldedit.player_notify(name, "saved Minetest schematic to " .. param, false) worldedit.player_notify(name, "Saved Minetest schematic to " .. param, false)
end end
worldedit.prob_list[name] = {} worldedit.prob_list[name] = {}
end), end),

View File

@ -1,7 +1,7 @@
local safe_region_callback = {} local safe_region_callback = {}
local safe_region_param = {} 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 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions
if pos1 == nil or pos2 == nil then if pos1 == nil or pos2 == nil then
worldedit.player_notify(name, "no region selected") worldedit.player_notify(name, "no region selected")
@ -12,7 +12,7 @@ end
--`callback` is a callback to run when the user confirms --`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 --`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 --default node volume calculation
nodes_needed = nodes_needed or check_region nodes_needed = nodes_needed or check_region
@ -63,3 +63,6 @@ minetest.register_chatcommand("/n", {
safe_region_callback[name], safe_region_param[name] = nil, nil safe_region_callback[name], safe_region_param[name] = nil, nil
end, end,
}) })
return safe_region, check_region