mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-25 18:20:38 +01:00
worldedit_brush: Remove "safe region" hack
This commit is contained in:
parent
03bef18272
commit
7833b68c85
@ -7,6 +7,7 @@ end
|
|||||||
local BRUSH_MAX_DIST = 150
|
local BRUSH_MAX_DIST = 150
|
||||||
local BRUSH_ALLOWED_COMMANDS = {
|
local BRUSH_ALLOWED_COMMANDS = {
|
||||||
-- basically everything that only needs pos1
|
-- basically everything that only needs pos1
|
||||||
|
-- TODO: determine automatically now that `require_pos` exists
|
||||||
"cube",
|
"cube",
|
||||||
"cylinder",
|
"cylinder",
|
||||||
"dome",
|
"dome",
|
||||||
@ -42,8 +43,10 @@ local brush_on_use = function(itemstack, placer)
|
|||||||
"This brush is not bound, use //brush to bind a command to it.")
|
"This brush is not bound, use //brush to bind a command to it.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local cmddef = minetest.registered_chatcommands["/" .. cmd]
|
|
||||||
|
local cmddef = worldedit.registered_commands[cmd]
|
||||||
if cmddef == nil then return false end -- shouldn't happen as //brush checks this
|
if cmddef == nil then return false end -- shouldn't happen as //brush checks this
|
||||||
|
|
||||||
local has_privs, missing_privs = minetest.check_player_privs(name, cmddef.privs)
|
local has_privs, missing_privs = minetest.check_player_privs(name, cmddef.privs)
|
||||||
if not has_privs then
|
if not has_privs then
|
||||||
worldedit.player_notify(name,
|
worldedit.player_notify(name,
|
||||||
@ -65,19 +68,22 @@ local brush_on_use = function(itemstack, placer)
|
|||||||
worldedit.pos1[name] = pointed_thing.under
|
worldedit.pos1[name] = pointed_thing.under
|
||||||
worldedit.pos2[name] = nil
|
worldedit.pos2[name] = nil
|
||||||
worldedit.mark_region(name)
|
worldedit.mark_region(name)
|
||||||
-- is this a horrible hack? oh yes.
|
|
||||||
worldedit._override_safe_regions = true
|
-- this isn't really clean...
|
||||||
local player_notify_old = worldedit.player_notify
|
local player_notify_old = worldedit.player_notify
|
||||||
worldedit.player_notify = function(name, msg)
|
worldedit.player_notify = function(name, msg)
|
||||||
if string.match(msg, "^%d") then return end -- discard "1234 nodes added."
|
if string.match(msg, "^%d") then return end -- discard "1234 nodes added."
|
||||||
return player_notify_old(name, msg)
|
return player_notify_old(name, msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert(cmddef.require_pos < 2)
|
||||||
|
local parsed = {cmddef.parse(meta:get_string("params"))}
|
||||||
|
if not table.remove(parsed, 1) then return false end -- shouldn't happen
|
||||||
|
|
||||||
minetest.log("action", string.format("%s uses WorldEdit brush (//%s) at %s",
|
minetest.log("action", string.format("%s uses WorldEdit brush (//%s) at %s",
|
||||||
name, cmd, minetest.pos_to_string(pointed_thing.under)))
|
name, cmd, minetest.pos_to_string(pointed_thing.under)))
|
||||||
cmddef.func(name, meta:get_string("params"))
|
cmddef.func(name, unpack(parsed))
|
||||||
|
|
||||||
worldedit._override_safe_regions = false
|
|
||||||
worldedit.player_notify = player_notify_old
|
worldedit.player_notify = player_notify_old
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -93,21 +99,22 @@ minetest.register_tool(":worldedit:brush", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("/brush", {
|
worldedit.register_command("brush", {
|
||||||
privs = {worldedit=true},
|
privs = {worldedit=true},
|
||||||
params = "none/<cmd> [parameters]",
|
params = "none/<cmd> [parameters]",
|
||||||
description = "Assign command to WorldEdit brush item",
|
description = "Assign command to WorldEdit brush item",
|
||||||
func = function(name, param)
|
parse = function(param)
|
||||||
local found, _, cmd, params = param:find("^([^%s]+)%s+(.+)$")
|
local found, _, cmd, params = param:find("^([^%s]+)%s+(.+)$")
|
||||||
if not found then
|
if not found then
|
||||||
params = ""
|
params = ""
|
||||||
found, _, cmd = param:find("^(.+)$")
|
found, _, cmd = param:find("^(.+)$")
|
||||||
end
|
end
|
||||||
if not found then
|
if not found then
|
||||||
worldedit.player_notify(name, "Invalid usage.")
|
return false
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
return true, cmd, params
|
||||||
|
end,
|
||||||
|
func = function(name, cmd, params)
|
||||||
local itemstack = minetest.get_player_by_name(name):get_wielded_item()
|
local itemstack = minetest.get_player_by_name(name):get_wielded_item()
|
||||||
if itemstack == nil or itemstack:get_name() ~= "worldedit:brush" then
|
if itemstack == nil or itemstack:get_name() ~= "worldedit:brush" then
|
||||||
worldedit.player_notify(name, "Not holding brush item.")
|
worldedit.player_notify(name, "Not holding brush item.")
|
||||||
@ -122,14 +129,21 @@ minetest.register_chatcommand("/brush", {
|
|||||||
else
|
else
|
||||||
local cmddef
|
local cmddef
|
||||||
if table.indexof(BRUSH_ALLOWED_COMMANDS, cmd) ~= -1 then
|
if table.indexof(BRUSH_ALLOWED_COMMANDS, cmd) ~= -1 then
|
||||||
cmddef = minetest.registered_chatcommands["/" .. cmd]
|
cmddef = worldedit.registered_commands[cmd]
|
||||||
else
|
|
||||||
cmddef = nil
|
|
||||||
end
|
end
|
||||||
if cmddef == nil then
|
if cmddef == nil then
|
||||||
worldedit.player_notify(name, "Invalid command for brush use: //" .. cmd)
|
worldedit.player_notify(name, "Invalid command for brush use: //" .. cmd)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Try parsing command params so we can give the user feedback
|
||||||
|
local ok, err = cmddef.parse(params)
|
||||||
|
if not ok then
|
||||||
|
err = err or "invalid usage"
|
||||||
|
worldedit.player_notify(name, "Brush command: " .. err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
meta:set_string("command", cmd)
|
meta:set_string("command", cmd)
|
||||||
meta:set_string("params", params)
|
meta:set_string("params", params)
|
||||||
local fullcmd = "//" .. cmd .. " " .. params
|
local fullcmd = "//" .. cmd .. " " .. params
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
local safe_region_callback = {}
|
local safe_region_callback = {}
|
||||||
|
|
||||||
worldedit._override_safe_regions = false -- internal use ONLY!
|
|
||||||
|
|
||||||
--`count` is the number of nodes that would possibly be modified
|
--`count` is the number of nodes that would possibly be modified
|
||||||
--`callback` is a callback to run when the user confirms
|
--`callback` is a callback to run when the user confirms
|
||||||
local function safe_region(name, count, callback)
|
local function safe_region(name, count, callback)
|
||||||
if worldedit._override_safe_regions or count < 10000 then
|
if count < 10000 then
|
||||||
return callback()
|
return callback()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user