Fix ability to place items in treasure chests by swapping (#647)

This commit is contained in:
LoneWolfHT 2020-05-30 07:25:52 -07:00 committed by GitHub
parent ce1bbe0246
commit a978d8457f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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())