Prevent players from putting class items in furnaces (#620)

This commit is contained in:
rubenwardy 2020-07-17 00:44:34 +01:00 committed by GitHub
parent a78fdd95c5
commit cb51d78a27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View file

@ -1,3 +1,5 @@
local S = minetest.get_translator("ctf")
local function stack_list_to_map(stacks)
local map = {}
for i = 1, #stacks do
@ -84,3 +86,29 @@ end
dropondie.register_drop_filter(function(player, itemname)
return not is_class_blacklisted(player, itemname)
end)
local function protect_metadata_inventory(nodename)
local def = assert(minetest.registered_nodes[nodename])
local function wrap(defname)
local old = def[defname]
def[defname] = function(pos, listname, index, stack, player, ...)
if is_class_blacklisted(player, stack:get_name()) then
minetest.chat_send_player(player:get_player_name(),
S("You're not allowed to put class items in @1!", def.description or "?"))
return 0
end
return old(pos, listname, index, stack, player, ...)
end
end
wrap("allow_metadata_inventory_put")
wrap("allow_metadata_inventory_take")
minetest.register_node(":" .. nodename, def)
end
protect_metadata_inventory("furnace:furnace")
protect_metadata_inventory("furnace:furnace_active")

View file

@ -1,3 +1,3 @@
name = ctf_classes
depends = ctf, ctf_flag, ctf_colors, ctf_map_core, ctf_stats, ctf_bandages, physics, shooter, hpregen, give_initial_stuff, dropondie, crafting, sniper_rifles, grenades
depends = ctf, ctf_flag, ctf_colors, ctf_map_core, ctf_stats, ctf_bandages, physics, shooter, hpregen, give_initial_stuff, dropondie, crafting, sniper_rifles, grenades, furnace
description = Adds classes, including knight, shooter, and medic