init.lua 2.0 KB

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