init.lua 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. minetest.register_node("mesecons_noteblock:noteblock", {
  2. description = "Noteblock",
  3. tiles = {"mesecons_noteblock.png"},
  4. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
  5. visual_scale = 1.3,
  6. paramtype="light",
  7. after_place_node = function(pos)
  8. minetest.add_node(pos, {name="mesecons_noteblock:noteblock", param2=0})
  9. end,
  10. on_punch = function (pos, node) -- change sound when punched
  11. local param2 = node.param2+1
  12. if param2==12 then param2=0 end
  13. minetest.add_node(pos, {name = node.name, param2 = param2})
  14. mesecon.noteblock_play(pos, param2)
  15. end,
  16. sounds = default.node_sound_wood_defaults(),
  17. mesecons = {effector = { -- play sound when activated
  18. action_on = function (pos, node)
  19. mesecon.noteblock_play(pos, node.param2)
  20. end
  21. }}
  22. })
  23. minetest.register_craft({
  24. output = "mesecons_noteblock:noteblock 1",
  25. recipe = {
  26. {"group:wood", "group:wood", "group:wood"},
  27. {"group:mesecon_conductor_craftable", "default:steel_ingot", "group:mesecon_conductor_craftable"},
  28. {"group:wood", "group:wood", "group:wood"},
  29. }
  30. })
  31. mesecon.noteblock_play = function (pos, param2)
  32. local soundname
  33. if param2==8 then
  34. soundname="mesecons_noteblock_a"
  35. elseif param2==9 then
  36. soundname="mesecons_noteblock_asharp"
  37. elseif param2==10 then
  38. soundname="mesecons_noteblock_b"
  39. elseif param2==11 then
  40. soundname="mesecons_noteblock_c"
  41. elseif param2==0 then
  42. soundname="mesecons_noteblock_csharp"
  43. elseif param2==1 then
  44. soundname="mesecons_noteblock_d"
  45. elseif param2==2 then
  46. soundname="mesecons_noteblock_dsharp"
  47. elseif param2==3 then
  48. soundname="mesecons_noteblock_e"
  49. elseif param2==4 then
  50. soundname="mesecons_noteblock_f"
  51. elseif param2==5 then
  52. soundname="mesecons_noteblock_fsharp"
  53. elseif param2==6 then
  54. soundname="mesecons_noteblock_g"
  55. elseif param2==7 then
  56. soundname="mesecons_noteblock_gsharp"
  57. end
  58. local block_below_name = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name
  59. if block_below_name == "default:glass" then
  60. soundname="mesecons_noteblock_hihat"
  61. end
  62. if block_below_name == "default:steelblock" then
  63. soundname=soundname.."2" -- Go up an octave.
  64. end
  65. if block_below_name == "default:stone" then
  66. soundname="mesecons_noteblock_kick"
  67. end
  68. if block_below_name == "default:lava_source" then
  69. soundname="fire_large"
  70. end
  71. if block_below_name == "default:chest" then
  72. soundname="mesecons_noteblock_snare"
  73. end
  74. if block_below_name == "default:tree" then
  75. soundname="mesecons_noteblock_crash"
  76. end
  77. if block_below_name == "default:wood" then
  78. soundname="mesecons_noteblock_litecrash"
  79. end
  80. if block_below_name == "default:coalblock" then
  81. soundname="tnt_explode"
  82. end
  83. minetest.sound_play(soundname,
  84. {pos = pos, gain = 1.0, max_hear_distance = 32,})
  85. end