1 minetest
.register_node("mesecons_noteblock:noteblock", {
2 description
= "Note Block",
3 _doc_items_longdesc
= "A note block is a musical block which plays one of many musical notes and different intruments when it is punched or supplied with redstone power.",
4 _doc_items_usagehelp
= [[Rightclick the note block to choose the next musical note (there are 24 half notes, or 2 octaves). The intrument played depends on the material of the block below the note block:
9 • Sand or gravel: Snare drum
10 • Anything else: Piano
12 The note block will only play a note when it is below air, otherwise, it stays silent.]],
13 tiles
= {"mesecons_noteblock.png"},
14 groups
= {handy
=1,axey
=1, material_wood
=1},
15 is_ground_content
= false,
17 on_rightclick
= function (pos
, node
) -- change sound when rightclicked
18 node
.param2
= (node
.param2
+1)%24
19 mesecon
.noteblock_play(pos
, node
.param2
)
20 minetest
.set_node(pos
, node
)
22 on_punch
= function (pos
, node
) -- play current sound when punched
23 mesecon
.noteblock_play(pos
, node
.param2
)
25 sounds
= mcl_sounds
.node_sound_wood_defaults(),
26 mesecons
= {effector
= { -- play sound when activated
27 action_on
= function (pos
, node
)
28 mesecon
.noteblock_play(pos
, node
.param2
)
30 rules
= mesecon
.rules
.alldirs
,
32 _mcl_blast_resistance
= 4,
36 minetest
.register_craft({
37 output
= '"mesecons_noteblock:noteblock" 1',
39 {"group:wood", "group:wood", "group:wood"},
40 {"group:wood", "mesecons:redstone", "group:wood"},
41 {"group:wood", "group:wood", "group:wood"},
45 minetest
.register_craft({
47 recipe
= "mesecons_noteblock:noteblock",
51 local soundnames_piano
= {
52 [0] = "mesecons_noteblock_c",
53 "mesecons_noteblock_csharp",
54 "mesecons_noteblock_d",
55 "mesecons_noteblock_dsharp",
56 "mesecons_noteblock_e",
57 "mesecons_noteblock_f",
58 "mesecons_noteblock_fsharp",
59 "mesecons_noteblock_g",
60 "mesecons_noteblock_gsharp",
61 "mesecons_noteblock_a",
62 "mesecons_noteblock_asharp",
63 "mesecons_noteblock_b",
65 "mesecons_noteblock_c2",
66 "mesecons_noteblock_csharp2",
67 "mesecons_noteblock_d2",
68 "mesecons_noteblock_dsharp2",
69 "mesecons_noteblock_e2",
70 "mesecons_noteblock_f2",
71 "mesecons_noteblock_fsharp2",
72 "mesecons_noteblock_g2",
73 "mesecons_noteblock_gsharp2",
74 "mesecons_noteblock_a2",
75 "mesecons_noteblock_asharp2",
76 "mesecons_noteblock_b2",
80 mesecon
.noteblock_play
= function (pos
, param2
)
81 local block_above_name
= minetest
.get_node({x
=pos
.x
, y
=pos
.y
+1, z
=pos
.z
}).name
82 if block_above_name
~= "air" then
83 -- Don't play sound if no air is above
87 -- Default: One of 24 piano notes
88 local soundname
= soundnames_piano
[param2
]
90 local block_below_name
= minetest
.get_node({x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
}).name
92 if minetest
.get_item_group(block_below_name
, "material_glass") ~= 0 then
93 -- TODO: 24 sticks and clicks
94 soundname
="mesecons_noteblock_temp_stick"
95 elseif minetest
.get_item_group(block_below_name
, "material_wood") ~= 0 then
96 -- TODO: 24 bass guitar sounds
97 soundname
="mesecons_noteblock_temp_bass_guitar"
98 elseif minetest
.get_item_group(block_below_name
, "material_sand") ~= 0 then
99 -- TODO: 24 snare drum sounds
100 soundname
="mesecons_noteblock_temp_snare"
101 elseif minetest
.get_item_group(block_below_name
, "material_stone") ~= 0 then
102 -- TODO: 24 bass drum sounds
103 soundname
="mesecons_noteblock_temp_kick"
105 minetest
.sound_play(soundname
,
106 {pos
= pos
, gain
= 1.0, max_hear_distance
= 48,})