Restart boiling sound on rejoining

This commit is contained in:
Wuzzy 2023-06-30 13:33:11 +02:00
parent 05544ae293
commit c165353480

View File

@ -35,9 +35,25 @@ function cauldron.stop_sound(pos)
local spos = minetest.hash_node_position(pos) local spos = minetest.hash_node_position(pos)
if sounds[spos] then if sounds[spos] then
minetest.sound_stop(sounds[spos]) minetest.sound_stop(sounds[spos])
sounds[spos] = nil
end end
end end
function cauldron.start_sound(pos)
local spos = minetest.hash_node_position(pos)
-- Stop sound if one already exists.
-- Only 1 sound per position at maximum allowed.
if sounds[spos] then
cauldron.stop_sound(pos)
end
sounds[spos] = minetest.sound_play("xdecor_boiling_water", {
pos = pos,
max_hear_distance = 5,
gain = 0.8,
loop = true
})
end
function cauldron.idle_construct(pos) function cauldron.idle_construct(pos)
local timer = minetest.get_node_timer(pos) local timer = minetest.get_node_timer(pos)
timer:start(10.0) timer:start(10.0)
@ -45,13 +61,7 @@ function cauldron.idle_construct(pos)
end end
function cauldron.boiling_construct(pos) function cauldron.boiling_construct(pos)
local spos = minetest.hash_node_position(pos) cauldron.start_sound(pos)
sounds[spos] = minetest.sound_play("xdecor_boiling_water", {
pos = pos,
max_hear_distance = 5,
gain = 0.8,
loop = true
})
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("infotext", S("Cauldron (active) - Drop foods inside to make a soup")) meta:set_string("infotext", S("Cauldron (active) - Drop foods inside to make a soup"))
@ -350,3 +360,14 @@ minetest.register_craft({
{"default:iron_lump", "default:iron_lump", "default:iron_lump"} {"default:iron_lump", "default:iron_lump", "default:iron_lump"}
} }
}) })
minetest.register_lbm({
label = "Restart boiling cauldron sounds",
name = "xdecor:restart_boiling_cauldron_sounds",
nodenames = {"xdecor:cauldron_boiling", "xdecor:cauldron_boiling_river_water"},
run_at_every_load = true,
action = function(pos, node)
cauldron.start_sound(pos)
end,
})