Page 1 of 2

[Demo Mod]Sound Block Example

PostPosted: Mon Mar 26, 2012 17:50
by Jeija
Hello!
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
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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)

PostPosted: Mon Mar 26, 2012 18:57
by Gilli
Nice Mod.

PostPosted: Mon Mar 26, 2012 18:58
by Jeija
you have to get the newest minetest version from git!

PostPosted: Mon Mar 26, 2012 19:04
by sfan5
Nice Mod!

PostPosted: Tue Mar 27, 2012 00:58
by sdzen

PostPosted: Tue Mar 27, 2012 01:13
by sdzen
chilling to some tunes in minetest
Image

PostPosted: Tue Mar 27, 2012 01:16
by sdzen
by the way lag spike on high chords :P

PostPosted: Tue Mar 27, 2012 02:53
by jordan4ibanez
very very nice

PostPosted: Tue Mar 27, 2012 05:30
by celeron55
If you make a demo mod, you should probably post the source code too so that people can easily look at it; either in the post if it isn't huge or in a pastebin or github otherwise.

For example I would like to see this, but won't bother opening a .zip.

PostPosted: Tue Mar 27, 2012 14:53
by Jeija
You're right celeron, I posted the code in the first post.

PostPosted: Tue Mar 27, 2012 14:57
by Death Dealer
Awesome some kind of sound:D it would be nice to have menu music to tho.

PostPosted: Tue Mar 27, 2012 15:15
by randomproof
If you add
metadata_name = "generic",
to your node def you can save data to the node. Though, I don't think you can save the handle from sound_play or you could, but it would lose its meaning if the server is reset.

PostPosted: Tue Mar 27, 2012 15:16
by Jordach
@Jeija: I have some free music on my Newgrounds free of charge, or use some I have posted here before.

EG: http://www.mediafire.com/?o96iy9b9ld9bqtf

NEWGROUNDS URL: jordach.newgrounds.com

PostPosted: Tue Mar 27, 2012 15:56
by Jeija
I think minetest needs its own music style, just like minecraft. I like hang music:
http://www.youtube.com/watch?v=wpJu2xI8L6E

What do you think about that, do you have other free hang music?
What music genre do you suggest (I don't mean things like rock or hiphop, minetest music should be calm)?

PostPosted: Tue Mar 27, 2012 15:58
by Death Dealer
Jeija wrote:I think minetest needs its own music style, just like minecraft. I like hang music:
http://www.youtube.com/watch?v=wpJu2xI8L6E

What do you think about that, do you have other free hang music?
What music genre do you suggest (I don't mean things like rock or hiphop, minetest music should be calm)?

Dubstep:D

PostPosted: Tue Mar 27, 2012 16:08
by Jordach
Im busy in my DAW Basement, I think its time to unleash some nosie!

PostPosted: Tue Mar 27, 2012 16:18
by RAPHAEL
Well I just tested this mod and it mostly works. It will start playing but very loudly. Also hitting it doesn't stop it from playing. However still nice. Now we need a soundpack made for minetest. Multiple soundpacks.

PostPosted: Tue Mar 27, 2012 16:18
by Jordach
Just made something with a little electro house synths. Very questionable, such as finding mese.

Sounds are WTFPL.

http://www.mediafire.com/download.php?os9oikh5lcn6971

PostPosted: Tue Mar 27, 2012 16:28
by Jeija
Also hitting it doesn't stop it from playing.

It should...?!?

PostPosted: Tue Mar 27, 2012 19:34
by RAPHAEL
Jeija wrote:
Also hitting it doesn't stop it from playing.

It should...?!?

On local tests with latest dev compiled.. nope doesn't stop playing on hit lol. Also even removing block doesn't make it stop playing.

PostPosted: Tue Mar 27, 2012 19:47
by sdzen
i can stop the playing

PostPosted: Tue Mar 27, 2012 20:10
by RAPHAEL
sdzen wrote:i can stop the playing

Well then I'm unsure what differs between us but something does apparently lol.

PostPosted: Tue Mar 27, 2012 20:11
by sdzen
well i got that error once when i was running 8 soundblocks at once :P 7's fine but at 8 its oh no!!!

PostPosted: Tue Mar 27, 2012 20:47
by Death Dealer
your link is broken.

PostPosted: Wed Mar 28, 2012 15:01
by Jeija
Death Dealer wrote:your link is broken.

Download link? No
Link to newgrounds? No

PostPosted: Wed Mar 28, 2012 18:24
by Death Dealer
Jeija wrote:
Death Dealer wrote:your link is broken.

Download link? No
Link to newgrounds? No

it worked this time, the last time i was on here it wasnt, and i was talking about your Download v0.1

PostPosted: Sat Mar 31, 2012 11:43
by kddekadenz
Jeija wrote:[...] 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. [...]


opengameart.org

PostPosted: Sat Mar 31, 2012 14:35
by Hackeridze
I wanna have "Have Love Will Travel - The Sonics"! Too old, so no copyrights.

PostPosted: Sat Mar 31, 2012 15:04
by kddekadenz
Hackeridze wrote:I wanna have "Have Love Will Travel - The Sonics"! Too old, so no copyrights.

Not in all countries..

PostPosted: Sat Mar 31, 2012 22:27
by IPushButton2653
Make the music box an amplifier..........make a simple guitar..............pretend to be playing heavy metal...........