mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-22 23:10:17 +01:00
Ensure chests close properly (#2965)
Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
fdcf458b56
commit
ec2f57db0e
@ -53,19 +53,22 @@ end
|
|||||||
default.chest.open_chests = {}
|
default.chest.open_chests = {}
|
||||||
|
|
||||||
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
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if not player or not fields.quit then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local pn = player:get_player_name()
|
local pn = player:get_player_name()
|
||||||
|
|
||||||
if not default.chest.open_chests[pn] then
|
if formname ~= "default:chest" then
|
||||||
|
if default.chest.open_chests[pn] then
|
||||||
|
default.chest.chest_lid_close(pn)
|
||||||
|
end
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not (fields.quit and default.chest.open_chests[pn]) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
default.chest.chest_lid_close(pn)
|
default.chest.chest_lid_close(pn)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -129,6 +132,12 @@ function default.chest.register_chest(prefixed_name, d)
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local cn = clicker:get_player_name()
|
||||||
|
|
||||||
|
if default.chest.open_chests[cn] then
|
||||||
|
default.chest.chest_lid_close(cn)
|
||||||
|
end
|
||||||
|
|
||||||
minetest.sound_play(def.sound_open, {gain = 0.3,
|
minetest.sound_play(def.sound_open, {gain = 0.3,
|
||||||
pos = pos, max_hear_distance = 10}, true)
|
pos = pos, max_hear_distance = 10}, true)
|
||||||
if not default.chest.chest_lid_obstructed(pos) then
|
if not default.chest.chest_lid_obstructed(pos) then
|
||||||
@ -136,10 +145,9 @@ function default.chest.register_chest(prefixed_name, d)
|
|||||||
{ name = name .. "_open",
|
{ name = name .. "_open",
|
||||||
param2 = node.param2 })
|
param2 = node.param2 })
|
||||||
end
|
end
|
||||||
minetest.after(0.2, minetest.show_formspec,
|
minetest.after(0.2, minetest.show_formspec, cn,
|
||||||
clicker:get_player_name(),
|
|
||||||
"default:chest", default.chest.get_chest_formspec(pos))
|
"default:chest", default.chest.get_chest_formspec(pos))
|
||||||
default.chest.open_chests[clicker:get_player_name()] = { pos = pos,
|
default.chest.open_chests[cn] = { pos = pos,
|
||||||
sound = def.sound_close, swap = name }
|
sound = def.sound_close, swap = name }
|
||||||
end
|
end
|
||||||
def.on_blast = function() end
|
def.on_blast = function() end
|
||||||
@ -200,6 +208,12 @@ function default.chest.register_chest(prefixed_name, d)
|
|||||||
return inv:is_empty("main")
|
return inv:is_empty("main")
|
||||||
end
|
end
|
||||||
def.on_rightclick = function(pos, node, clicker)
|
def.on_rightclick = function(pos, node, clicker)
|
||||||
|
local cn = clicker:get_player_name()
|
||||||
|
|
||||||
|
if default.chest.open_chests[cn] then
|
||||||
|
default.chest.chest_lid_close(cn)
|
||||||
|
end
|
||||||
|
|
||||||
minetest.sound_play(def.sound_open, {gain = 0.3, pos = pos,
|
minetest.sound_play(def.sound_open, {gain = 0.3, pos = pos,
|
||||||
max_hear_distance = 10}, true)
|
max_hear_distance = 10}, true)
|
||||||
if not default.chest.chest_lid_obstructed(pos) then
|
if not default.chest.chest_lid_obstructed(pos) then
|
||||||
@ -208,9 +222,9 @@ function default.chest.register_chest(prefixed_name, d)
|
|||||||
param2 = node.param2 })
|
param2 = node.param2 })
|
||||||
end
|
end
|
||||||
minetest.after(0.2, minetest.show_formspec,
|
minetest.after(0.2, minetest.show_formspec,
|
||||||
clicker:get_player_name(),
|
cn,
|
||||||
"default:chest", default.chest.get_chest_formspec(pos))
|
"default:chest", default.chest.get_chest_formspec(pos))
|
||||||
default.chest.open_chests[clicker:get_player_name()] = { pos = pos,
|
default.chest.open_chests[cn] = { pos = pos,
|
||||||
sound = def.sound_close, swap = name }
|
sound = def.sound_close, swap = name }
|
||||||
end
|
end
|
||||||
def.on_blast = function(pos)
|
def.on_blast = function(pos)
|
||||||
@ -274,6 +288,18 @@ function default.chest.register_chest(prefixed_name, d)
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- close opened chests on load
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "close opened chests on load",
|
||||||
|
name = "default:close_" .. prefixed_name:gsub(":", "_") .. "_open",
|
||||||
|
nodenames = {prefixed_name .. "_open"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = function(pos, node)
|
||||||
|
node.name = prefixed_name
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
end
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
default.chest.register_chest("default:chest", {
|
default.chest.register_chest("default:chest", {
|
||||||
|
Loading…
Reference in New Issue
Block a user