diff --git a/api.lua b/api.lua index 1e105d3..8a9e254 100644 --- a/api.lua +++ b/api.lua @@ -18,7 +18,7 @@ end mobs = { mod = "redo", - version = "20241002", + version = "20241010", spawning_mobs = {}, translate = S, invis = minetest.global_exists("invisibility") and invisibility or {}, @@ -4737,6 +4737,7 @@ minetest.register_chatcommand("clear_mobs", { if settings:get_bool("mobs_can_hear") ~= false then + local node_hear = settings:get_bool("mobs_can_hear_node") local old_sound_play = minetest.sound_play minetest.sound_play = function(spec, param, eph) @@ -4798,22 +4799,25 @@ if settings:get_bool("mobs_can_hear") ~= false then end -- find nodes that can hear up to 8 blocks away - local dist = min(def.max_hear_distance, 8) - local ps = minetest.find_nodes_in_area( - vector.subtract(def.pos, dist), - vector.add(def.pos, dist), {"group:on_sound"}) + if node_hear then - if #ps > 0 then + local dist = min(def.max_hear_distance, 8) + local ps = minetest.find_nodes_in_area( + vector.subtract(def.pos, dist), + vector.add(def.pos, dist), {"group:on_sound"}) - for n = 1, #ps do + if #ps > 0 then - local ndef = minetest.registered_nodes[minetest.get_node(ps[n]).name] + for n = 1, #ps do - def.distance = get_distance(def.pos, ps[n]) - def.loudness = def.gain - (bit * def.distance) + local ndef = minetest.registered_nodes[minetest.get_node(ps[n]).name] - if def.loudness > 0 and ndef and ndef.on_sound then - ndef.on_sound(ps[n], def) + def.distance = get_distance(def.pos, ps[n]) + def.loudness = def.gain - (bit * def.distance) + + if def.loudness > 0 and ndef and ndef.on_sound then + ndef.on_sound(ps[n], def) + end end end end diff --git a/api.txt b/api.txt index 71ddb8a..85ea0b6 100644 --- a/api.txt +++ b/api.txt @@ -857,6 +857,10 @@ External Settings for "minetest.conf" 'mob_pathfinding_searchdistance' max search distance from search positions (default 16) 'mob_pathfinding_max_jump' max jump height for pathfinding (default 4) 'mob_pathfinding_max_drop' max drop height for pathfinding (default 6) + 'mobs_can_hear' Enabled by default, overrides minetest.sound_play and enables + nearby mobs to run a custom on_sound function. + 'mobs_can_hear_node' Disabled by default, allows nearby nodes to hear and run a + custom on_sound function. Players can override the spawn chance for each mob registered by adding a line to their minetest.conf file with a new value, the lower the value the more each diff --git a/settingtypes.txt b/settingtypes.txt index f94ce34..c79446b 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -63,6 +63,9 @@ mob_log_spawn (Log Mob Spawning) bool false # Mob hearing, when enabled will override minetest.sound_play for mobs to hear mobs_can_hear (Enable Mob hearing) bool true +# Node hearing, when enabled will allow nodes to hear nearby sounds +mobs_can_hear_node (Enable Node hearing) bool false + [Pathfinding] # Enable pathfinding (default Enabled) mob_pathfinding_enable (Enable pathfinding) bool true