Add sounds for falling and attached nodes (#7719)

* Add sounds for falling and attached nodes

The sound specified in `node_definition.sounds.fall` is used.
When a falling node is spawned at a position or an attached node drops, the sound is played at this position.

* allow all sorts of soundspecs
This commit is contained in:
DS 2019-03-05 08:17:48 +01:00 committed by Loïc Blot
parent ee698770b9
commit 60ab2d94f0
2 changed files with 10 additions and 1 deletions

@ -116,7 +116,7 @@ core.register_entity(":__builtin:falling_node", {
local meta = core.get_meta(np) local meta = core.get_meta(np)
meta:from_table(self.meta) meta:from_table(self.meta)
end end
if def.sounds and def.sounds.place and def.sounds.place.name then if def.sounds and def.sounds.place then
core.sound_play(def.sounds.place, {pos = np}) core.sound_play(def.sounds.place, {pos = np})
end end
end end
@ -141,6 +141,11 @@ local function convert_to_falling_node(pos, node)
local meta = core.get_meta(pos) local meta = core.get_meta(pos)
local metatable = meta and meta:to_table() or {} local metatable = meta and meta:to_table() or {}
local def = core.registered_nodes[node.name]
if def and def.sounds and def.sounds.fall then
core.sound_play(def.sounds.fall, {pos = pos})
end
obj:get_luaentity():set_node(node, metatable) obj:get_luaentity():set_node(node, metatable)
core.remove_node(pos) core.remove_node(pos)
return true return true
@ -170,6 +175,9 @@ local function drop_attached_node(p)
drops = drop_stacks drops = drop_stacks
def.preserve_metadata(pos_copy, node_copy, oldmeta, drops) def.preserve_metadata(pos_copy, node_copy, oldmeta, drops)
end end
if def and def.sounds and def.sounds.fall then
core.sound_play(def.sounds.fall, {pos = p})
end
core.remove_node(p) core.remove_node(p)
for _, item in pairs(drops) do for _, item in pairs(drops) do
local pos = { local pos = {

@ -6084,6 +6084,7 @@ Used by `minetest.register_node`.
dug = <SimpleSoundSpec>, dug = <SimpleSoundSpec>,
place = <SimpleSoundSpec>, place = <SimpleSoundSpec>,
place_failed = <SimpleSoundSpec>, place_failed = <SimpleSoundSpec>,
fall = <SimpleSoundSpec>,
}, },
drop = "", drop = "",