default_beacons.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. local function register_node_sound(name, nodes, sound)
  8. ambiance.register_sound_beacon(name, {
  9. check_time = 1,
  10. play_time = sound.track_length,
  11. play_immediate = true,
  12. on_check_environment = function(self, pos)
  13. local node = minetest.get_node(pos)
  14. for k, v in ipairs(nodes) do
  15. if node.name == v then
  16. return true
  17. end
  18. end
  19. end,
  20. on_play_sound = function(self, pos, time_since_last_play)
  21. local hnd = minetest.sound_play(sound,
  22. {pos=pos, max_hear_distance=sound.max_hear_distance}, false)
  23. if self.hnd then
  24. minetest.sound_fade(self.hnd, 3, 0)
  25. self.hnd = nil
  26. end
  27. if hnd then
  28. self.hnd = hnd
  29. end
  30. end,
  31. on_stop_sound = function(self)
  32. if self.hnd then
  33. minetest.sound_fade(self.hnd, 1, 0)
  34. self.hnd = nil
  35. end
  36. end,
  37. })
  38. end
  39. local furnace_types = {
  40. "cobble_furnace:active",
  41. "redstone_furnace:active",
  42. "coal_alloy_furnace:active",
  43. "alloyf2:mv_active",
  44. "ecfurn2:lv_active",
  45. "ecfurn2:mv_active",
  46. "ecfurn2:hv_active",
  47. "gen2:lv_active",
  48. "gen2:mv_active",
  49. "gen2:hv_active",
  50. }
  51. register_node_sound("ambiance:furnace_active", furnace_types,
  52. {name="default_furnace_active", gain=0.5, track_length=8, max_hear_distance=30})
  53. local grinder_types = {
  54. "grind2:lv_active",
  55. "grind2:mv_active",
  56. "crusher:active",
  57. }
  58. register_node_sound("ambiance:grinder_active", grinder_types,
  59. {name="grinder_grinding", gain=1.00, track_length=38, max_hear_distance=50})
  60. local gemcutter_types = {
  61. "gemcut2:lv_active",
  62. }
  63. register_node_sound("ambiance:gemcutter_active", gemcutter_types,
  64. {name="gemcutter_grinding", gain=0.60, track_length=2.7, max_hear_distance=30})