1
0
mirror of https://github.com/minetest/minetest_game.git synced 2024-12-22 23:10:17 +01:00

chest_lid_close: don't replace a node if it's not the expected open chest

This commit is contained in:
fluxionary 2023-08-11 04:00:22 -07:00 committed by GitHub
parent 960aff2f63
commit 83c10f59e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,16 +38,23 @@ function default.chest.chest_lid_close(pn)
default.chest.open_chests[pn] = nil default.chest.open_chests[pn] = nil
for k, v in pairs(default.chest.open_chests) do for k, v in pairs(default.chest.open_chests) do
if v.pos.x == pos.x and v.pos.y == pos.y and v.pos.z == pos.z then if vector.equals(v.pos, pos) then
-- another player is also looking at the chest
return true return true
end end
end end
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
minetest.after(0.2, minetest.swap_node, pos, { name = swap, minetest.after(0.2, function()
param2 = node.param2 }) local current_node = minetest.get_node(pos)
minetest.sound_play(sound, {gain = 0.3, pos = pos, if current_node.name ~= swap .. "_open" then
max_hear_distance = 10}, true) -- the chest has already been replaced, don't try to replace what's there.
return
end
minetest.swap_node(pos, {name = swap, param2 = node.param2})
minetest.sound_play(sound, {gain = 0.3, pos = pos,
max_hear_distance = 10}, true)
end)
end end
default.chest.open_chests = {} default.chest.open_chests = {}