From a978d8457f988ace3539a1269df10aa0bbfcbaf0 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Sat, 30 May 2020 07:25:52 -0700 Subject: [PATCH] Fix ability to place items in treasure chests by swapping (#647) --- mods/other/tsm_chests/init.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mods/other/tsm_chests/init.lua b/mods/other/tsm_chests/init.lua index 5949b1d..c0832f7 100755 --- a/mods/other/tsm_chests/init.lua +++ b/mods/other/tsm_chests/init.lua @@ -75,9 +75,17 @@ minetest.register_node("tsm_chests:chest", { " moves stuff to chest at " .. minetest.pos_to_string(pos)) end, on_metadata_inventory_take = function(pos, listname, index, stack, player) + local inv = minetest.get_inventory({type = "node", pos = pos}) + local swapped_item = inv:get_stack(listname, index) + + if swapped_item:get_name() ~= "" then + inv:remove_item(listname, swapped_item) + player:get_inventory():add_item(listname, swapped_item) + end + minetest.log("action", player:get_player_name() .. " takes stuff from chest at " .. minetest.pos_to_string(pos)) - local inv = minetest.get_inventory({type = "node", pos=pos}) + if not inv or inv:is_empty("main") then minetest.set_node(pos, {name="air"}) minetest.show_formspec(player:get_player_name(), "", player:get_inventory_formspec())