default_beacons.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. -- Note: it is not enough simply to register a sound beacon here.
  2. -- The nodes must also spawn the sound beacon (usually in on_timer or similar).
  3. -- Otherwise, the sound beacon is registered, but no sound is played!
  4. --
  5. -- Note on sound files: files MUST BE MONO-TRACK! Otherwise fade-with-distance
  6. -- WILL NOT WORK.
  7. if not ambiance.node_sound_beacons_loaded then
  8. local function register_node_sound(name, nodes, sound)
  9. ambiance.register_sound_beacon(name, {
  10. check_time = 1,
  11. play_time = sound.track_length,
  12. play_immediate = true,
  13. on_check_environment = function(self, pos)
  14. local node = minetest.get_node(pos)
  15. for k, v in ipairs(nodes) do
  16. if node.name == v then
  17. return true
  18. end
  19. end
  20. end,
  21. on_play_sound = function(self, pos, time_since_last_play)
  22. local hnd = minetest.sound_play(sound,
  23. {pos=pos, max_hear_distance=sound.max_hear_distance}, false)
  24. if self.hnd then
  25. minetest.sound_fade(self.hnd, 3, 0)
  26. self.hnd = nil
  27. end
  28. if hnd then
  29. self.hnd = hnd
  30. end
  31. end,
  32. on_stop_sound = function(self)
  33. if self.hnd then
  34. minetest.sound_fade(self.hnd, 1, 0)
  35. self.hnd = nil
  36. end
  37. end,
  38. })
  39. end
  40. local furnace_types = {
  41. "cobble_furnace:active",
  42. "redstone_furnace:active",
  43. "coal_alloy_furnace:active",
  44. "alloyf2:mv_active",
  45. "ecfurn2:lv_active",
  46. "ecfurn2:mv_active",
  47. "ecfurn2:hv_active",
  48. "gen2:lv_active",
  49. "gen2:mv_active",
  50. "gen2:hv_active",
  51. }
  52. register_node_sound("ambiance:furnace_active", furnace_types,
  53. {name="default_furnace_active", gain=0.5, track_length=8, max_hear_distance=30})
  54. local grinder_types = {
  55. "grind2:lv_active",
  56. "grind2:mv_active",
  57. "crusher:active",
  58. }
  59. register_node_sound("ambiance:grinder_active", grinder_types,
  60. {name="grinder_grinding", gain=1.00, track_length=38, max_hear_distance=50})
  61. local gemcutter_types = {
  62. "gemcut2:lv_active",
  63. }
  64. register_node_sound("ambiance:gemcutter_active", gemcutter_types,
  65. {name="gemcutter_grinding", gain=0.60, track_length=2.7, max_hear_distance=30})
  66. ambiance.node_sound_beacons_loaded = true
  67. end