Protect anvil's input inventory from take/put if player is not the owner (#35)

This commit is contained in:
Zemtzov7 2023-09-17 15:49:41 +05:00 committed by GitHub
parent 42b3a42544
commit 7906282fa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -150,6 +150,18 @@ local update_item = function(pos, node)
end
end
local function has_access(pos, player)
local name = player:get_player_name()
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local shared = meta:get_int("shared") == 1
if shared or name == owner then
return true
else
return false
end
end
local metal_sounds
-- Apparently node_sound_metal_defaults is a newer thing, I ran into games using an older version of the default mod without it.
if default.node_sound_metal_defaults ~= nil then
@ -257,6 +269,10 @@ minetest.register_node("anvil:anvil", {
return 0
end
if not has_access(pos, player) then
return 0
end
local player_name = player:get_player_name()
if stack:get_wear() == 0 then
minetest.chat_send_player(player_name, S("This anvil is for damaged tools only."))
@ -277,6 +293,10 @@ minetest.register_node("anvil:anvil", {
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if not has_access(pos, player) then
return 0
end
if listname ~= "input" then
return 0
end