[Demo Mod]Sound Block Example

User avatar
Jeija
Member
Posts: 686
Joined: Fri Dec 23, 2011 21:46
Location: Nürtingen, Germany

[Demo Mod]Sound Block Example

by Jeija » Post

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

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)
Last edited by Jeija on Tue Mar 27, 2012 14:52, edited 1 time in total.
Redstone for minetest: Mesecons (mesecons.net)

Gilli
Member
Posts: 20
Joined: Sat Mar 17, 2012 21:15

by Gilli » Post

Nice Mod.
Last edited by Gilli on Mon Mar 26, 2012 19:20, edited 1 time in total.

User avatar
Jeija
Member
Posts: 686
Joined: Fri Dec 23, 2011 21:46
Location: Nürtingen, Germany

by Jeija » Post

you have to get the newest minetest version from git!
Redstone for minetest: Mesecons (mesecons.net)

sfan5
Moderator
Posts: 4095
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5
Location: Germany

by sfan5 » Post

Nice Mod!
Mods: Mesecons | WorldEdit | Nuke & Minetest builds for Windows (32-bit & 64-bit)

User avatar
sdzen
Member
Posts: 1170
Joined: Fri Aug 05, 2011 22:33
Location: Paradise (your not allowed)

by sdzen » Post

Zen S.D.

The next generation of tranquility!
malheureusement mon français n'est pas bon :<
Owner of the Zelo's
In game name: MuadTralk, spdtainted, sdzen, sd zen, sdzeno

User avatar
sdzen
Member
Posts: 1170
Joined: Fri Aug 05, 2011 22:33
Location: Paradise (your not allowed)

by sdzen » Post

chilling to some tunes in minetest
Image

Zen S.D.

The next generation of tranquility!
malheureusement mon français n'est pas bon :<
Owner of the Zelo's
In game name: MuadTralk, spdtainted, sdzen, sd zen, sdzeno

User avatar
sdzen
Member
Posts: 1170
Joined: Fri Aug 05, 2011 22:33
Location: Paradise (your not allowed)

by sdzen » Post

by the way lag spike on high chords :P

Zen S.D.

The next generation of tranquility!
malheureusement mon français n'est pas bon :<
Owner of the Zelo's
In game name: MuadTralk, spdtainted, sdzen, sd zen, sdzeno

User avatar
jordan4ibanez
Member
Posts: 1923
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Post

very very nice
hello, am program. do language in rust. make computer do. okay i go now.

User avatar
celeron55
Administrator
Posts: 533
Joined: Tue Apr 19, 2011 10:10
GitHub: celeron55
IRC: celeron55

by celeron55 » Post

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.

User avatar
Jeija
Member
Posts: 686
Joined: Fri Dec 23, 2011 21:46
Location: Nürtingen, Germany

by Jeija » Post

You're right celeron, I posted the code in the first post.
Redstone for minetest: Mesecons (mesecons.net)

User avatar
Death Dealer
Member
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo
Contact:

by Death Dealer » Post

Awesome some kind of sound:D it would be nice to have menu music to tho.
Keep calm and code python^_^

randomproof
Member
Posts: 214
Joined: Thu Nov 17, 2011 06:31
Location: California, USA

by randomproof » Post

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.

Jordach
Member
Posts: 4534
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach
Location: Blender Scene

by Jordach » Post

@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
Last edited by Jordach on Tue Mar 27, 2012 15:19, edited 1 time in total.

User avatar
Jeija
Member
Posts: 686
Joined: Fri Dec 23, 2011 21:46
Location: Nürtingen, Germany

by Jeija » Post

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)?
Redstone for minetest: Mesecons (mesecons.net)

User avatar
Death Dealer
Member
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo
Contact:

by Death Dealer » Post

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
Keep calm and code python^_^

Jordach
Member
Posts: 4534
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach
Location: Blender Scene

by Jordach » Post

Im busy in my DAW Basement, I think its time to unleash some nosie!

User avatar
RAPHAEL
Member
Posts: 627
Joined: Tue Nov 01, 2011 09:09
Location: Earth

by RAPHAEL » Post

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.
"Before you speak, ask yourself: Is it kind, is it true, is it necessary, does it improve upon the silence?"
My mods: http://goo.gl/n4kpn
(Currently Various, Industrial, Fakeblocks, Jail, MoarCraft, Christmas, Replicator, minetest dev installer for linux, bash mod installer, windows mod installer)

Jordach
Member
Posts: 4534
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach
Location: Blender Scene

by Jordach » Post

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
Last edited by Jordach on Tue Mar 27, 2012 16:18, edited 1 time in total.

User avatar
Jeija
Member
Posts: 686
Joined: Fri Dec 23, 2011 21:46
Location: Nürtingen, Germany

by Jeija » Post

Also hitting it doesn't stop it from playing.
It should...?!?
Redstone for minetest: Mesecons (mesecons.net)

User avatar
RAPHAEL
Member
Posts: 627
Joined: Tue Nov 01, 2011 09:09
Location: Earth

by RAPHAEL » Post

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.
"Before you speak, ask yourself: Is it kind, is it true, is it necessary, does it improve upon the silence?"
My mods: http://goo.gl/n4kpn
(Currently Various, Industrial, Fakeblocks, Jail, MoarCraft, Christmas, Replicator, minetest dev installer for linux, bash mod installer, windows mod installer)

User avatar
sdzen
Member
Posts: 1170
Joined: Fri Aug 05, 2011 22:33
Location: Paradise (your not allowed)

by sdzen » Post

i can stop the playing

Zen S.D.

The next generation of tranquility!
malheureusement mon français n'est pas bon :<
Owner of the Zelo's
In game name: MuadTralk, spdtainted, sdzen, sd zen, sdzeno

User avatar
RAPHAEL
Member
Posts: 627
Joined: Tue Nov 01, 2011 09:09
Location: Earth

by RAPHAEL » Post

sdzen wrote:i can stop the playing
Well then I'm unsure what differs between us but something does apparently lol.
"Before you speak, ask yourself: Is it kind, is it true, is it necessary, does it improve upon the silence?"
My mods: http://goo.gl/n4kpn
(Currently Various, Industrial, Fakeblocks, Jail, MoarCraft, Christmas, Replicator, minetest dev installer for linux, bash mod installer, windows mod installer)

User avatar
sdzen
Member
Posts: 1170
Joined: Fri Aug 05, 2011 22:33
Location: Paradise (your not allowed)

by sdzen » Post

well i got that error once when i was running 8 soundblocks at once :P 7's fine but at 8 its oh no!!!

Zen S.D.

The next generation of tranquility!
malheureusement mon français n'est pas bon :<
Owner of the Zelo's
In game name: MuadTralk, spdtainted, sdzen, sd zen, sdzeno

User avatar
Death Dealer
Member
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo
Contact:

by Death Dealer » Post

your link is broken.
Keep calm and code python^_^

User avatar
Jeija
Member
Posts: 686
Joined: Fri Dec 23, 2011 21:46
Location: Nürtingen, Germany

by Jeija » Post

Death Dealer wrote:your link is broken.
Download link? No
Link to newgrounds? No
Redstone for minetest: Mesecons (mesecons.net)

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests