Fix swapping class items into other invs (#670)
* Fix bug with team/loot chest swapping * Fix furnace swapping
This commit is contained in:
parent
cb51d78a27
commit
b24d1b3097
3 changed files with 20 additions and 4 deletions
|
@ -89,10 +89,11 @@ end)
|
||||||
|
|
||||||
|
|
||||||
local function protect_metadata_inventory(nodename)
|
local function protect_metadata_inventory(nodename)
|
||||||
local def = assert(minetest.registered_nodes[nodename])
|
local def = table.copy(assert(minetest.registered_nodes[nodename]))
|
||||||
|
local old
|
||||||
|
|
||||||
local function wrap(defname)
|
local function wrap(defname)
|
||||||
local old = def[defname]
|
old = def[defname]
|
||||||
def[defname] = function(pos, listname, index, stack, player, ...)
|
def[defname] = function(pos, listname, index, stack, player, ...)
|
||||||
if is_class_blacklisted(player, stack:get_name()) then
|
if is_class_blacklisted(player, stack:get_name()) then
|
||||||
minetest.chat_send_player(player:get_player_name(),
|
minetest.chat_send_player(player:get_player_name(),
|
||||||
|
@ -104,6 +105,21 @@ local function protect_metadata_inventory(nodename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
old = def.on_metadata_inventory_take
|
||||||
|
function def.on_metadata_inventory_take(pos, listname, index, stack, player, ...)
|
||||||
|
local furnaceinv = minetest.get_inventory({type = "node", pos = pos})
|
||||||
|
local swapped_item = furnaceinv:get_stack(listname, index)
|
||||||
|
|
||||||
|
if is_class_blacklisted(player, swapped_item:get_name()) then
|
||||||
|
furnaceinv:remove_item(listname, swapped_item)
|
||||||
|
player:get_inventory():add_item("main", swapped_item)
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(old) == "function" then
|
||||||
|
return old(pos, listname, index, stack, player, ...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
wrap("allow_metadata_inventory_put")
|
wrap("allow_metadata_inventory_put")
|
||||||
wrap("allow_metadata_inventory_take")
|
wrap("allow_metadata_inventory_take")
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ for _, chest_color in pairs(colors) do
|
||||||
|
|
||||||
if not ctf_map.is_item_allowed_in_team_chest(listname, swapped_item, player) then
|
if not ctf_map.is_item_allowed_in_team_chest(listname, swapped_item, player) then
|
||||||
chestinv:remove_item(listname, swapped_item)
|
chestinv:remove_item(listname, swapped_item)
|
||||||
player:get_inventory():add_item(listname, swapped_item)
|
player:get_inventory():add_item("main", swapped_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.log("action", player:get_player_name() ..
|
minetest.log("action", player:get_player_name() ..
|
||||||
|
|
|
@ -80,7 +80,7 @@ minetest.register_node("tsm_chests:chest", {
|
||||||
|
|
||||||
if swapped_item:get_name() ~= "" then
|
if swapped_item:get_name() ~= "" then
|
||||||
inv:remove_item(listname, swapped_item)
|
inv:remove_item(listname, swapped_item)
|
||||||
player:get_inventory():add_item(listname, swapped_item)
|
player:get_inventory():add_item("main", swapped_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.log("action", player:get_player_name() ..
|
minetest.log("action", player:get_player_name() ..
|
||||||
|
|
Loading…
Reference in a new issue