moreblocks/invsaw/api.lua

34 lines
910 B
Lua
Raw Normal View History

2022-06-20 02:08:21 +02:00
local server_is_creative = minetest.settings:get_bool("creative_mode", false)
2022-06-20 00:26:05 +02:00
function invsaw.has_saw_in_inventory(player)
local inv = player:get_inventory()
return inv:contains_item("main", invsaw.settings.saw_item)
end
function invsaw.can_use_saw(player)
return (
2022-06-20 02:08:21 +02:00
server_is_creative or
2022-06-20 00:26:05 +02:00
minetest.check_player_privs(player, invsaw.settings.creative_priv) or
2022-06-20 02:08:21 +02:00
minetest.check_player_privs(player, invsaw.settings.priv)
2022-06-20 00:26:05 +02:00
)
end
function invsaw.allow_use_saw(player)
return (
2022-06-20 02:08:21 +02:00
server_is_creative or
2022-06-20 00:26:05 +02:00
minetest.check_player_privs(player, invsaw.settings.creative_priv) or
2022-06-20 02:08:21 +02:00
(minetest.check_player_privs(player, invsaw.settings.priv) and invsaw.has_saw_in_inventory(player))
2022-06-20 00:26:05 +02:00
)
end
2022-06-20 00:34:08 +02:00
function invsaw.check_use_status(player)
2022-06-20 00:26:05 +02:00
if invsaw.can_use_saw(player) then
2022-06-20 00:34:08 +02:00
invsaw.initialize_inventory(player)
2022-06-20 00:26:05 +02:00
else
invsaw.drop_inventory(player)
end
end
2022-06-20 00:34:08 +02:00
minetest.register_on_joinplayer(invsaw.check_use_status)