forked from minetest/minetest_game
Chests: Fix open chest after player leave (#1884)
This should fix the chest staying open when a player disconnects while inside.
This commit is contained in:
parent
4ccafd1518
commit
c5c9e423ca
@ -1798,6 +1798,24 @@ end
|
|||||||
|
|
||||||
local open_chests = {}
|
local open_chests = {}
|
||||||
|
|
||||||
|
local function chest_lid_close(pn)
|
||||||
|
local pos = open_chests[pn].pos
|
||||||
|
local sound = open_chests[pn].sound
|
||||||
|
local swap = open_chests[pn].swap
|
||||||
|
|
||||||
|
open_chests[pn] = nil
|
||||||
|
for k, v in pairs(open_chests) do
|
||||||
|
if v.pos.x == pos.x and v.pos.y == pos.y and v.pos.z == pos.z then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
minetest.after(0.2, minetest.swap_node, pos, { name = "default:" .. swap,
|
||||||
|
param2 = node.param2 })
|
||||||
|
minetest.sound_play(sound, {gain = 0.3, pos = pos, max_hear_distance = 10})
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if formname ~= "default:chest" then
|
if formname ~= "default:chest" then
|
||||||
return
|
return
|
||||||
@ -1811,21 +1829,15 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos = open_chests[pn].pos
|
chest_lid_close(pn)
|
||||||
local sound = open_chests[pn].sound
|
return true
|
||||||
local swap = open_chests[pn].swap
|
end)
|
||||||
local node = minetest.get_node(pos)
|
|
||||||
|
|
||||||
open_chests[pn] = nil
|
minetest.register_on_leaveplayer(function(player)
|
||||||
for k, v in pairs(open_chests) do
|
local pn = player:get_player_name()
|
||||||
if v.pos.x == pos.x and v.pos.y == pos.y and v.pos.z == pos.z then
|
if open_chests[pn] then
|
||||||
return true
|
chest_lid_close(pn)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
minetest.after(0.2, minetest.swap_node, pos, { name = "default:" .. swap,
|
|
||||||
param2 = node.param2 })
|
|
||||||
minetest.sound_play(sound, {gain = 0.3, pos = pos, max_hear_distance = 10})
|
|
||||||
return true
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function default.register_chest(name, d)
|
function default.register_chest(name, d)
|
||||||
|
Loading…
Reference in New Issue
Block a user