tweak some things

This commit is contained in:
flux
2022-06-19 17:08:21 -07:00
parent 56e709e1ec
commit e8324f5bf1
9 changed files with 56 additions and 48 deletions

View File

@ -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.

View File

@ -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

View File

@ -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",