init.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. drawtype = "allfaces_optional",
  6. visual_scale = 1.3,
  7. paramtype="light",
  8. after_place_node = function(pos)
  9. minetest.env:add_node(pos, {name="mesecons_noteblock:noteblock", param2=0})
  10. end,
  11. on_punch = function (pos, node) -- change sound when punched
  12. local param2 = node.param2+1
  13. if param2==12 then param2=0 end
  14. minetest.env:add_node(pos, {name = node.name, param2 = param2})
  15. mesecon.noteblock_play(pos, param2)
  16. end,
  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. {"default:wood", "default:wood", "default:wood"},
  27. {"group:mesecon_conductor_craftable", "default:steel_ingot", "group:mesecon_conductor_craftable"},
  28. {"default:wood", "default:wood", "default: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.env: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:stone" then
  63. soundname="mesecons_noteblock_kick"
  64. end
  65. if block_below_name == "default:chest" then
  66. soundname="mesecons_noteblock_snare"
  67. end
  68. if block_below_name == "default:tree" then
  69. soundname="mesecons_noteblock_crash"
  70. end
  71. if block_below_name == "default:wood" then
  72. soundname="mesecons_noteblock_litecrash"
  73. end
  74. minetest.sound_play(soundname,
  75. {pos = pos, gain = 1.0, max_hear_distance = 32,})
  76. end