From 15545f9f299d5cd0b12876f898e6d72840c5a567 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Thu, 16 Sep 2021 19:21:50 +0200 Subject: [PATCH] Use a random pitch and gain for the sound The volume is lower now in general. --- init.lua | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index 9943efc..33b6f1f 100644 --- a/init.lua +++ b/init.lua @@ -127,6 +127,17 @@ else end end +local function tree_fall_sound(pos) + if treecapitator.play_sound then + minetest.sound_play("tree_falling", { + gain = 0.2 + 0.2 * math.random() ^ 2, + pitch = 0.7 + 0.5 * math.random(), + pos = pos, + max_hear_distance = 32 + }, true) + end +end + local function table_contains(t, v) for i = 1,#t do @@ -486,9 +497,7 @@ function capitate_funcs.default(pos, tr, _, digger) end -- tree was capitated, play sound - if treecapitator.play_sound then - minetest.sound_play("tree_falling", {pos = pos, max_hear_distance = 32}) - end + tree_fall_sound(pos) return true end @@ -602,9 +611,7 @@ function capitate_funcs.acacia(pos, tr, node_above, digger) end -- play the sound, then dig the stem - if treecapitator.play_sound then - minetest.sound_play("tree_falling", {pos = pos, max_hear_distance = 32}) - end + tree_fall_sound(pos) for i = 1,n-1 do local pos_stem, node = unpack(tab[i]) destroy_node(pos_stem, node, digger) @@ -813,10 +820,7 @@ function capitate_funcs.palm(startpos, tr, node_above, digger) local leaves_ps = {} local lc = palm_find_valid_head_ps(hcp, leaves_ps, tr) - if treecapitator.play_sound then - minetest.sound_play("tree_falling", {pos = pos_current, - max_hear_distance = 32}) - end + tree_fall_sound(pos_current) local nodeupdate = minetest.check_for_falling minetest.check_for_falling = function() end @@ -928,9 +932,7 @@ function capitate_funcs.moretrees(pos, tr, _, digger) print("wrong leaves num: "..num_leaves) return end - if treecapitator.play_sound then - minetest.sound_play("tree_falling", {pos = pos, max_hear_distance = 32}) - end + tree_fall_sound(pos) local inv = digger:get_inventory() for _,p in pairs(ps) do local node = get_node(p)