1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-07 19:10:23 +01:00

Updated WorldEdit

This commit is contained in:
LeMagnesium 2015-05-19 20:28:05 +02:00
parent cee9c73216
commit 0f6e885b4f
4 changed files with 42 additions and 28 deletions

View File

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

View File

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

View File

@ -11,9 +11,9 @@ if minetest.place_schematic then
end
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]
if pos1 == nil then
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
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 +30,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 +56,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 +70,15 @@ worldedit.player_axis = function(name)
return "z", dir.z > 0 and 1 or -1
end
function worldedit.mkdir(path)
if minetest.mkdir then
minetest.mkdir(path)
else
os.execute('mkdir "' .. path .. '"')
end
end
minetest.register_chatcommand("/about", {
params = "",
description = "Get information about the mod",
@ -802,10 +811,6 @@ minetest.register_chatcommand("/orient", {
worldedit.player_notify(name, count .. " nodes oriented")
end,
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+)$")
if found == nil then
worldedit.player_notify(name, "invalid usage: " .. param)
@ -880,20 +885,22 @@ 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 param:find("^[a-zA-Z0-9_%-.]+$") 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
worldedit.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)
@ -1041,24 +1048,29 @@ 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 param:find("^[a-zA-Z0-9_%-.]+$") 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
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),

View File

@ -1,7 +1,7 @@
local safe_region_callback = {}
local safe_region_param = {}
check_region = function(name, param)
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)
function safe_region(callback, nodes_needed)
--default node volume calculation
nodes_needed = nodes_needed or check_region
@ -63,3 +63,5 @@ minetest.register_chatcommand("/n", {
safe_region_callback[name], safe_region_param[name] = nil, nil
end,
})
return safe_region, check_region