Skip to content

Commit c5c9e42

Browse files
tenplus1SmallJoker
authored andcommittedSep 20, 2017
Chests: Fix open chest after player leave (#1884)
This should fix the chest staying open when a player disconnects while inside.
1 parent 4ccafd1 commit c5c9e42

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed
 

‎mods/default/nodes.lua

+25-13
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,24 @@ end
17981798

17991799
local open_chests = {}
18001800

1801+
local function chest_lid_close(pn)
1802+
local pos = open_chests[pn].pos
1803+
local sound = open_chests[pn].sound
1804+
local swap = open_chests[pn].swap
1805+
1806+
open_chests[pn] = nil
1807+
for k, v in pairs(open_chests) do
1808+
if v.pos.x == pos.x and v.pos.y == pos.y and v.pos.z == pos.z then
1809+
return true
1810+
end
1811+
end
1812+
1813+
local node = minetest.get_node(pos)
1814+
minetest.after(0.2, minetest.swap_node, pos, { name = "default:" .. swap,
1815+
param2 = node.param2 })
1816+
minetest.sound_play(sound, {gain = 0.3, pos = pos, max_hear_distance = 10})
1817+
end
1818+
18011819
minetest.register_on_player_receive_fields(function(player, formname, fields)
18021820
if formname ~= "default:chest" then
18031821
return
@@ -1811,21 +1829,15 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
18111829
return
18121830
end
18131831

1814-
local pos = open_chests[pn].pos
1815-
local sound = open_chests[pn].sound
1816-
local swap = open_chests[pn].swap
1817-
local node = minetest.get_node(pos)
1832+
chest_lid_close(pn)
1833+
return true
1834+
end)
18181835

1819-
open_chests[pn] = nil
1820-
for k, v in pairs(open_chests) do
1821-
if v.pos.x == pos.x and v.pos.y == pos.y and v.pos.z == pos.z then
1822-
return true
1823-
end
1836+
minetest.register_on_leaveplayer(function(player)
1837+
local pn = player:get_player_name()
1838+
if open_chests[pn] then
1839+
chest_lid_close(pn)
18241840
end
1825-
minetest.after(0.2, minetest.swap_node, pos, { name = "default:" .. swap,
1826-
param2 = node.param2 })
1827-
minetest.sound_play(sound, {gain = 0.3, pos = pos, max_hear_distance = 10})
1828-
return true
18291841
end)
18301842

18311843
function default.register_chest(name, d)

0 commit comments

Comments
 (0)
Please sign in to comment.