mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-01-07 08:20:21 +01:00
pass def onto hearing nodes
This commit is contained in:
parent
f4861ced2a
commit
e4a5ead82c
7
api.lua
7
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
|
||||
|
@ -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
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user