From e4a5ead82ca54157928b34e11e6df80d58299d3a Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Wed, 2 Oct 2024 15:13:37 +0100 Subject: [PATCH] pass def onto hearing nodes --- api.lua | 7 ++++--- crafts.lua | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/api.lua b/api.lua index 906fa7c..2a1ecba 100644 --- a/api.lua +++ b/api.lua @@ -4775,6 +4775,7 @@ if settings:get_bool("mobs_can_hear") ~= false then -- find mobs within sounds hearing range local objs = minetest.get_objects_inside_radius(def.pos, def.max_hear_distance) + local bit = def.gain / def.max_hear_distance for n = 1, #objs do @@ -4788,9 +4789,6 @@ if settings:get_bool("mobs_can_hear") ~= false then -- calculate loudness of sound to mob def.distance = get_distance(def.pos, obj:get_pos()) - - local bit = def.gain / def.max_hear_distance - def.loudness = def.gain - (bit * def.distance) -- run custom on_sound function if heard @@ -4811,6 +4809,9 @@ if settings:get_bool("mobs_can_hear") ~= false then local ndef = minetest.registered_nodes[minetest.get_node(ps[n]).name] + def.distance = get_distance(def.pos, ps[n]) + def.loudness = def.gain - (bit * def.distance) + if ndef and ndef.on_sound then ndef.on_sound(ps[n], def) end end end diff --git a/crafts.lua b/crafts.lua index 2203f08..5c10d91 100644 --- a/crafts.lua +++ b/crafts.lua @@ -443,7 +443,9 @@ minetest.register_node("mobs:hearing_vines", { type = "fixed", fixed = {-6 / 16, -0.5, -6 / 16, 6 / 16, -0.25, 6 / 16}, }, on_sound = function(pos, def) - minetest.set_node(pos, {name = "mobs:hearing_vines_active"}) + if def.loudness > 0.5 then + minetest.set_node(pos, {name = "mobs:hearing_vines_active"}) + end end })