From 83c10f59e1f30faea2020ae03291b52092cb579d Mon Sep 17 00:00:00 2001 From: fluxionary <25628292+fluxionary@users.noreply.github.com> Date: Fri, 11 Aug 2023 04:00:22 -0700 Subject: [PATCH] chest_lid_close: don't replace a node if it's not the expected open chest --- mods/default/chests.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mods/default/chests.lua b/mods/default/chests.lua index e340416f..1c1ce051 100644 --- a/mods/default/chests.lua +++ b/mods/default/chests.lua @@ -38,16 +38,23 @@ function default.chest.chest_lid_close(pn) default.chest.open_chests[pn] = nil 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 end end local node = minetest.get_node(pos) - minetest.after(0.2, minetest.swap_node, pos, { name = swap, - param2 = node.param2 }) - minetest.sound_play(sound, {gain = 0.3, pos = pos, - max_hear_distance = 10}, true) + minetest.after(0.2, function() + local current_node = minetest.get_node(pos) + if current_node.name ~= swap .. "_open" then + -- 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 default.chest.open_chests = {}