I made a mod example which plays a demo song (http://www.newgrounds.com/audio/listen/426165)
when the musicblock is punched. It turns off when punched again.
(I had to use a global variable for this because you can't save values in the node itself, can you?
As there is no crafting recipe, get the music block by writing
- Code: Select all
/giveme soundblocks:musicblock
Future: Do you have more Creative Commons music that I should add? You can make it yourself or suggest other's artwork! If there is enough I could make a jukebox with disks like in minecraft.
This should also be mesecon controlled.
If there is a dev out there who wants to create note blocks you may wanna use this code.
Download:
Version 0.1 as .zip (3.5 MB)
Source Code:
- Code: Select all
soundblocks_music={} --This is needed because you cannot save the handle of the sound in param2 of the node
minetest.register_node("soundblocks:musicblock", {
description = "Music Block",
tile_images = {"default_wood.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
})
--Some functions that you need to save the handle in soundblocks_music:
function soundblocks_get_handle(pos)
local i=0
while soundblocks_music[i]~=nil do
if soundblocks_music[i].pos.x==pos.x and soundblocks_music[i].pos.y==pos.y and soundblocks_music[i].pos.z==pos.z then
return soundblocks_music[i].handle
end
i=i+1
end
return 0
end
function soundblocks_set_handle(pos, handle)
local i=0
while soundblocks_music[i]~=nil do
if soundblocks_music[i].pos.x==pos.x and soundblocks_music[i].pos.y==pos.y and soundblocks_music[i].pos.z==pos.z then
soundblocks_music[i].handle=handle
return
end
i=i+1
end
soundblocks_music[i]={}
soundblocks_music[i].pos=pos
soundblocks_music[i].handle=handle
end
--This is the actual code that plays the sound:
minetest.register_on_punchnode(function(pos, node, puncher)
if node.name=="soundblocks:musicblock" then
if soundblocks_get_handle(pos)==0 then
local handle=0
handle = minetest.sound_play("soundblocks_music", { --name of sound, file name extension is .ogg
pos = pos, --pos where sound comes from
gain = 1.0,
max_hear_distance = 32,}) --sound gets lower the farer you get away from the jukebox
soundblocks_set_handle(pos, handle)
else
minetest.sound_stop(soundblocks_get_handle(pos))
soundblocks_set_handle(pos, 0)
end
end
end)