mirror of
https://github.com/minetest-mods/moreblocks.git
synced 2025-07-03 08:30:40 +02:00
tweak some things
This commit is contained in:
@ -1,12 +0,0 @@
|
||||
invsaw
|
||||
======
|
||||
|
||||
This mod adds a button in unified_inventory that opens a formspec that works exactly like the
|
||||
moreblocks circular saw. It requires that either the server is in creative mode, you have the
|
||||
"creative" priv, or you have one or more circular saws (moreblocks:circular_saw) in your inventory.
|
||||
|
||||
Dependencies: moreblocks, unified_inventory
|
||||
|
||||
Contains large amounts of code based on Calinou's moreblocks mod, and a texture based on some textures
|
||||
from the same mod.
|
||||
|
@ -1,3 +1,5 @@
|
||||
local server_is_creative = minetest.settings:get_bool("creative_mode", false)
|
||||
|
||||
function invsaw.has_saw_in_inventory(player)
|
||||
local inv = player:get_inventory()
|
||||
return inv:contains_item("main", invsaw.settings.saw_item)
|
||||
@ -5,15 +7,17 @@ end
|
||||
|
||||
function invsaw.can_use_saw(player)
|
||||
return (
|
||||
server_is_creative or
|
||||
minetest.check_player_privs(player, invsaw.settings.creative_priv) or
|
||||
minetest.check_player_privs(player, invsaw.settings.priv)
|
||||
minetest.check_player_privs(player, invsaw.settings.priv)
|
||||
)
|
||||
end
|
||||
|
||||
function invsaw.allow_use_saw(player)
|
||||
return (
|
||||
server_is_creative or
|
||||
minetest.check_player_privs(player, invsaw.settings.creative_priv) or
|
||||
(minetest.check_player_privs(player, invsaw.settings.priv) and invsaw.has_saw_in_inventory(player))
|
||||
(minetest.check_player_privs(player, invsaw.settings.priv) and invsaw.has_saw_in_inventory(player))
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -10,22 +10,20 @@ local function on_priv_change(name)
|
||||
end
|
||||
end
|
||||
|
||||
local function override_on_priv_change(old)
|
||||
return function(name, cause)
|
||||
on_priv_change(name)
|
||||
if old then
|
||||
old(name, cause)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.registered_privileges[priv] then
|
||||
local def = minetest.registered_privileges[priv]
|
||||
local old_on_grant = def.on_grant
|
||||
local old_on_revoke = def.on_revoke
|
||||
def.on_grant = function(name, cause)
|
||||
on_priv_change(name)
|
||||
if old_on_grant then
|
||||
old_on_grant(name, cause)
|
||||
end
|
||||
end
|
||||
def.on_revoke = function(name, cause)
|
||||
on_priv_change(name)
|
||||
if old_on_revoke then
|
||||
old_on_revoke(name, cause)
|
||||
end
|
||||
end
|
||||
def.on_grant = override_on_priv_change(def.on_grant)
|
||||
def.on_revoke = override_on_priv_change(def.on_revoke)
|
||||
|
||||
else
|
||||
minetest.register_privilege(priv, {
|
||||
description = "Allow use of the circular saw in inventory",
|
||||
@ -38,20 +36,9 @@ end
|
||||
|
||||
if minetest.registered_privileges[creative_priv] then
|
||||
local def = minetest.registered_privileges[creative_priv]
|
||||
local old_on_grant = def.on_grant
|
||||
local old_on_revoke = def.on_revoke
|
||||
def.on_grant = function(name, cause)
|
||||
on_priv_change(name)
|
||||
if old_on_grant then
|
||||
old_on_grant(name, cause)
|
||||
end
|
||||
end
|
||||
def.on_revoke = function(name, cause)
|
||||
on_priv_change(name)
|
||||
if old_on_revoke then
|
||||
old_on_revoke(name, cause)
|
||||
end
|
||||
end
|
||||
def.on_grant = override_on_priv_change(def.on_grant)
|
||||
def.on_revoke = override_on_priv_change(def.on_revoke)
|
||||
|
||||
else
|
||||
minetest.register_privilege(creative_priv, {
|
||||
description = "Allow use of the inventory saw creatively",
|
||||
|
Reference in New Issue
Block a user