init.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. on_punch = function(pos, node) -- change sound when punched
  6. node.param2 = (node.param2+1)%12
  7. mesecon.noteblock_play(pos, node.param2)
  8. minetest.set_node(pos, node)
  9. end,
  10. sounds = default.node_sound_wood_defaults(),
  11. mesecons = {effector = { -- play sound when activated
  12. action_on = function(pos, node)
  13. mesecon.noteblock_play(pos, node.param2)
  14. end
  15. }}
  16. })
  17. minetest.register_craft({
  18. output = "mesecons_noteblock:noteblock 1",
  19. recipe = {
  20. {"group:wood", "group:wood", "group:wood"},
  21. {"group:mesecon_conductor_craftable", "default:steel_ingot", "group:mesecon_conductor_craftable"},
  22. {"group:wood", "group:wood", "group:wood"},
  23. }
  24. })
  25. local soundnames = {
  26. [0] = "mesecons_noteblock_csharp",
  27. "mesecons_noteblock_d",
  28. "mesecons_noteblock_dsharp",
  29. "mesecons_noteblock_e",
  30. "mesecons_noteblock_f",
  31. "mesecons_noteblock_fsharp",
  32. "mesecons_noteblock_g",
  33. "mesecons_noteblock_gsharp",
  34. "mesecons_noteblock_a",
  35. "mesecons_noteblock_asharp",
  36. "mesecons_noteblock_b",
  37. "mesecons_noteblock_c"
  38. }
  39. local node_sounds = {
  40. ["default:glass"] = "mesecons_noteblock_hihat",
  41. ["default:stone"] = "mesecons_noteblock_kick",
  42. ["default:lava_source"] = "fire_large",
  43. ["default:chest"] = "mesecons_noteblock_snare",
  44. ["default:tree"] = "mesecons_noteblock_crash",
  45. ["default:wood"] = "mesecons_noteblock_litecrash",
  46. ["default:coalblock"] = "tnt_explode",
  47. }
  48. mesecon.noteblock_play = function(pos, param2)
  49. pos.y = pos.y-1
  50. local nodeunder = minetest.get_node(pos).name
  51. local soundname = node_sounds[nodeunder]
  52. if not soundname then
  53. soundname = soundnames[param2]
  54. if not soundname then
  55. minetest.log("error", "[mesecons_noteblock] No soundname found, test param2")
  56. return
  57. end
  58. if nodeunder == "default:steelblock" then
  59. soundname = soundname.. 2
  60. end
  61. end
  62. pos.y = pos.y+1
  63. minetest.sound_play(soundname, {pos = pos})
  64. end