Spawn chest lid only if there is space

This commit is contained in:
Wuzzy 2024-12-11 22:00:52 +01:00
parent 0f62f88b56
commit 4a0ef1c6ae

View File

@ -214,20 +214,25 @@ local register_chest = function(id, def)
minetest.set_node(pos, {name="lzr_treasure:chest_"..id.."_open_"..treasure_id, param2=node.param2})
minetest.sound_play({name=sound_open, gain=0.5}, {pos=pos}, true)
-- Spawn chest lid
local lidpos = vector.offset(pos, 0, 0.01, 0)
local obj = minetest.add_entity(lidpos, "lzr_treasure:chest_lid")
if obj then
obj:set_properties({
textures = {
def.tile_top, def.tile_bottom, def.tile_side, def.tile_front,
},
})
local yaw = (3-((node.param2-1) % 4)) * (math.pi/2)
obj:set_yaw(yaw)
local ent = obj:get_luaentity()
if ent then
ent._chest_node_name = "lzr_treasure:chest_"..id.."_unlocked"
local pos_above = vector.offset(pos, 0, 1, 0)
local node_above = minetest.get_node(pos_above)
local def_above = minetest.registered_nodes[node_above.name]
if not def_above or not def_above.walkable then
-- Spawn chest lid
local lidpos = vector.offset(pos, 0, 0.01, 0)
local obj = minetest.add_entity(lidpos, "lzr_treasure:chest_lid")
if obj then
obj:set_properties({
textures = {
def.tile_top, def.tile_bottom, def.tile_side, def.tile_front,
},
})
local yaw = (3-((node.param2-1) % 4)) * (math.pi/2)
obj:set_yaw(yaw)
local ent = obj:get_luaentity()
if ent then
ent._chest_node_name = "lzr_treasure:chest_"..id.."_unlocked"
end
end
end