init.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. sounds = default.node_sound_wood_defaults(),
  18. mesecons = {effector = { -- play sound when activated
  19. action_on = function (pos, node)
  20. mesecon.noteblock_play(pos, node.param2)
  21. end
  22. }}
  23. })
  24. minetest.register_craft({
  25. output = '"mesecons_noteblock:noteblock" 1',
  26. recipe = {
  27. {"default:wood", "default:wood", "default:wood"},
  28. {"group:mesecon_conductor_craftable", "default:steel_ingot", "group:mesecon_conductor_craftable"},
  29. {"default:wood", "default:wood", "default:wood"},
  30. }
  31. })
  32. mesecon.noteblock_play = function (pos, param2)
  33. local soundname
  34. if param2==8 then
  35. soundname="mesecons_noteblock_a"
  36. elseif param2==9 then
  37. soundname="mesecons_noteblock_asharp"
  38. elseif param2==10 then
  39. soundname="mesecons_noteblock_b"
  40. elseif param2==11 then
  41. soundname="mesecons_noteblock_c"
  42. elseif param2==0 then
  43. soundname="mesecons_noteblock_csharp"
  44. elseif param2==1 then
  45. soundname="mesecons_noteblock_d"
  46. elseif param2==2 then
  47. soundname="mesecons_noteblock_dsharp"
  48. elseif param2==3 then
  49. soundname="mesecons_noteblock_e"
  50. elseif param2==4 then
  51. soundname="mesecons_noteblock_f"
  52. elseif param2==5 then
  53. soundname="mesecons_noteblock_fsharp"
  54. elseif param2==6 then
  55. soundname="mesecons_noteblock_g"
  56. elseif param2==7 then
  57. soundname="mesecons_noteblock_gsharp"
  58. end
  59. local block_below_name = minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z}).name
  60. if block_below_name == "default:glass" then
  61. soundname="mesecons_noteblock_hihat"
  62. end
  63. if block_below_name == "default:stone" then
  64. soundname="mesecons_noteblock_kick"
  65. end
  66. if block_below_name == "default:chest" then
  67. soundname="mesecons_noteblock_snare"
  68. end
  69. if block_below_name == "default:tree" then
  70. soundname="mesecons_noteblock_crash"
  71. end
  72. if block_below_name == "default:wood" then
  73. soundname="mesecons_noteblock_litecrash"
  74. end
  75. minetest.sound_play(soundname,
  76. {pos = pos, gain = 1.0, max_hear_distance = 32,})
  77. end