init.lua 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. sounds = {}
  2. minetest.register_node('sounds:test', {
  3. description = 'biome test',
  4. tiles = {'letters_station.png'},
  5. paramtype = 'light',
  6. paramtype2 = 'facedir',
  7. selection_box = {
  8. type = 'fixed',
  9. fixed = {-.5, -.5, -.5, .5, .5, .5}},
  10. collision_box = {
  11. type = 'fixed',
  12. fixed = {-.5, -.5, -.5, .5, .5, .5}},
  13. groups = {oddly_breakable_by_hand=2, choppy=3, not_in_creative_inventory=1},
  14. on_punch = function(pos, node, puncher, pointed_thing)
  15. local player_name = puncher:get_player_name()
  16. local biome_data = minetest.get_biome_data(pos)
  17. local biome_id = biome_data.biome
  18. local biome_name = minetest.get_biome_name(biome_id)
  19. minetest.chat_send_player(player_name, 'You are in a '..biome_name..' biome.')
  20. sounds.play_sound(puncher)
  21. end
  22. })
  23. function sounds.random_player()
  24. local key = #(minetest.get_connected_players())
  25. local people = minetest.get_connected_players()
  26. local person = math.random(1, key)
  27. local name = people[person] --userdata
  28. sounds.play_sound(name)
  29. end
  30. function sounds.play_sound(player)
  31. if player then
  32. local pos = player:get_pos()
  33. if pos.y > -20 and pos.y < 500 then
  34. local player_name = player:get_player_name()
  35. local biome_data = minetest.get_biome_data(pos)
  36. local biome_id = biome_data.biome
  37. local biome_name = minetest.get_biome_name(biome_id)
  38. if biome_name == 'grassland_ocean' or biome_name == 'snowy_grassland_ocean'
  39. or biome_name == 'savanna_ocean' or biome_name == 'taiga_ocean' then
  40. minetest.sound_play('ocean_beach', {to_player = player_name, gain = .5})
  41. elseif biome_name == 'rainforest' then
  42. minetest.sound_play('rainforest', {to_player = player_name, gain = .75})
  43. elseif biome_name == 'grassland' then
  44. minetest.sound_play('grassland', {to_player = player_name, gain = .75})
  45. elseif biome_name == 'deciduous_forest' then
  46. minetest.sound_play('deciduous_forest', {to_player = player_name, gain = .75})
  47. elseif biome_name == 'coniferous_forest' then
  48. minetest.sound_play('coniferous_forest', {to_player = player_name, gain = .75})
  49. elseif biome_name == 'desert' or biome_name == 'sandstone_desert' then
  50. minetest.sound_play('desert', {to_player = player_name, gain = .75})
  51. elseif biome_name == 'icesheet' then
  52. minetest.sound_play('icesheet', {to_player = player_name, gain = .75})
  53. elseif biome_name == 'savanna' then
  54. minetest.sound_play('savanna', {to_player = player_name, gain = .7})
  55. elseif biome_name == 'tundra' then
  56. minetest.sound_play('tundra', {to_player = player_name, gain = .7})
  57. end
  58. end
  59. end
  60. end