mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-25 18:20:38 +01:00
Fix safe region functionality (thanks ChaosWormz).
This commit is contained in:
parent
2784a25561
commit
4660927ca0
@ -1,15 +1,12 @@
|
|||||||
local safe_region_callback
|
local safe_region_callback = {}
|
||||||
local safe_region_name
|
local safe_region_param = {}
|
||||||
local safe_region_param
|
|
||||||
|
|
||||||
check_region = function(name, param)
|
check_region = function(name, param)
|
||||||
--obtain positions
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions
|
||||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
|
||||||
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")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return worldedit.volume(pos1, pos2)
|
return worldedit.volume(pos1, pos2)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -28,7 +25,7 @@ safe_region = function(callback, nodes_needed)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--save callback to call later
|
--save callback to call later
|
||||||
safe_region_callback, safe_region_name, safe_region_param = callback, name, param
|
safe_region_callback[name], safe_region_param[name] = callback, param
|
||||||
worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
|
worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -36,8 +33,8 @@ end
|
|||||||
minetest.register_chatcommand("/y", {
|
minetest.register_chatcommand("/y", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "Confirm a pending operation",
|
description = "Confirm a pending operation",
|
||||||
func = function()
|
func = function(name)
|
||||||
local callback, name, param = safe_region_callback, safe_region_name, safe_region_param
|
local callback, param = safe_region_callback[name], safe_region_param[name]
|
||||||
if not callback then
|
if not callback then
|
||||||
worldedit.player_notify(name, "no operation pending")
|
worldedit.player_notify(name, "no operation pending")
|
||||||
return
|
return
|
||||||
@ -50,7 +47,7 @@ minetest.register_chatcommand("/y", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
safe_region_callback, safe_region_name, safe_region_param = nil, nil, nil --reset pending operation
|
safe_region_callback[name], safe_region_param[name] = nil, nil --reset pending operation
|
||||||
callback(name, param, pos1, pos2)
|
callback(name, param, pos1, pos2)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -58,11 +55,11 @@ minetest.register_chatcommand("/y", {
|
|||||||
minetest.register_chatcommand("/n", {
|
minetest.register_chatcommand("/n", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "Confirm a pending operation",
|
description = "Confirm a pending operation",
|
||||||
func = function()
|
func = function(name)
|
||||||
if not safe_region_callback then
|
if not safe_region_callback[name] then
|
||||||
worldedit.player_notify(name, "no operation pending")
|
worldedit.player_notify(name, "no operation pending")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
safe_region_callback, safe_region_name, safe_region_param = nil, nil, nil
|
safe_region_callback[name], safe_region_param[name] = nil, nil
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user