Skip to content

Commit 94442e8

Browse files
authored
patch for #124 (#125) async race condition fix
* restructure avoiding excessive indentation * possibly fix #124 * async race condition fix
1 parent 1169cff commit 94442e8

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

compat-chests.lua

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,27 @@ if minetest.get_modpath("default") then
4747
-- get the fields from the chest formspec, we can do this bc. newest functions are called first
4848
-- https://github.com/minetest/minetest/blob/d4b10db998ebeb689b3d27368e30952a42169d03/doc/lua_api.md?plain=1#L5840
4949
minetest.register_on_player_receive_fields(function(player, formname, fields)
50-
if formname == "default:chest" then
51-
local pn = player:get_player_name()
52-
local pos = default.chest.open_chests[pn].pos
53-
local chest = pos and minetest.get_node(pos)
54-
local is_pipeworks_chest = chest and pipeworks.chests[chest]
55-
if is_pipeworks_chest and not fields.quit and pipeworks.may_configure(pos, player) then
56-
-- Pipeworks Switch
57-
fs_helpers.on_receive_fields(pos, fields)
58-
minetest.show_formspec(player:get_player_name(),
59-
"default:chest",
60-
default.chest.get_chest_formspec(pos))
61-
end
62-
-- Do NOT return true here, the callback from default still needs to run
63-
return false
50+
if fields.quit or formname ~= "default:chest" then
51+
return
6452
end
53+
local pn = player:get_player_name()
54+
local chest_open = default.chest.open_chests[pn]
55+
if not chest_open then
56+
-- chest already closed before formspec
57+
return
58+
end
59+
local pos = chest_open.pos
60+
local chest = pos and minetest.get_node(pos)
61+
local is_pipeworks_chest = chest and pipeworks.chests[chest]
62+
if is_pipeworks_chest and pipeworks.may_configure(pos, player) then
63+
-- Pipeworks Switch
64+
fs_helpers.on_receive_fields(pos, fields)
65+
minetest.show_formspec(pn,
66+
"default:chest",
67+
default.chest.get_chest_formspec(pos))
68+
end
69+
-- Do NOT return true here, the callback from default still needs to run
70+
return false
6571
end)
6672

6773
local connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1}
@@ -152,17 +158,18 @@ elseif minetest.get_modpath("hades_chests") then
152158
-- get the fields from the chest formspec, we can do this bc. newest functions are called first
153159
-- https://github.com/minetest/minetest/blob/d4b10db998ebeb689b3d27368e30952a42169d03/doc/lua_api.md?plain=1#L5840
154160
minetest.register_on_player_receive_fields(function(player, formname, fields)
155-
if formname == "hades_chests:chest_locked" then
156-
local pn = player:get_player_name()
157-
local pos = open_chests[pn]
158-
if not fields.quit and pos and pipeworks.may_configure(pos, player) then
159-
-- Pipeworks Switch
160-
fs_helpers.on_receive_fields(pos, fields)
161-
minetest.show_formspec(pn, "hades_chests:chest_locked", get_locked_chest_formspec(pos))
162-
end
163-
-- Do NOT return true here, the callback from hades still needs to run (if they add one)
164-
return false
161+
if fields.quit or formname ~= "hades_chests:chest_locked" then
162+
return
163+
end
164+
local pn = player:get_player_name()
165+
local pos = open_chests[pn]
166+
if pos and pipeworks.may_configure(pos, player) then
167+
-- Pipeworks Switch
168+
fs_helpers.on_receive_fields(pos, fields)
169+
minetest.show_formspec(pn, "hades_chests:chest_locked", get_locked_chest_formspec(pos))
165170
end
171+
-- Do NOT return true here, the callback from hades still needs to run (if they add one)
172+
return false
166173
end)
167174

168175
local connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1}
@@ -175,4 +182,4 @@ elseif minetest.get_modpath("mcl_barrels") then
175182
local connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1}
176183
pipeworks.override_chest("mcl_barrels:barrel_closed", {}, connect_sides)
177184
pipeworks.override_chest("mcl_barrels:barrel_open", {}, connect_sides)
178-
end
185+
end

0 commit comments

Comments
 (0)