[Demo Mod]Sound Block Example

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

[Demo Mod]Sound Block Example

by Jeija » Mon Mar 26, 2012 17:50

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)
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 » Mon Mar 26, 2012 18:57

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

by Jeija » Mon Mar 26, 2012 18:58

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

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Mon Mar 26, 2012 19:04

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

by sdzen » Tue Mar 27, 2012 00:58

[h]Zen S.D.[/h] 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

by sdzen » Tue Mar 27, 2012 01:13

chilling to some tunes in minetest
Image
[h]Zen S.D.[/h] 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

by sdzen » Tue Mar 27, 2012 01:16

by the way lag spike on high chords :P
[h]Zen S.D.[/h] 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: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Tue Mar 27, 2012 02:53

very very nice
If you can think it, you can make it.
 

celeron55
Member
 
Posts: 430
Joined: Tue Apr 19, 2011 10:10

by celeron55 » Tue Mar 27, 2012 05:30

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

by Jeija » Tue Mar 27, 2012 14:53

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

by Death Dealer » Tue Mar 27, 2012 14:57

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

by randomproof » Tue Mar 27, 2012 15:15

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.
 

User avatar
Jordach
Member
 
Posts: 4412
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Tue Mar 27, 2012 15:16

@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.

( ͡° ͜ʖ ͡°) ( ͡o ͜ʖ ͡o) [$ ( ͡° ͜ʖ ͡°) $] ( ͡$ ͜ʖ ͡$) ヽ༼ຈل͜ຈ༽ノ



My image and media server is back online and is functioning as normal.
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Tue Mar 27, 2012 15:56

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

by Death Dealer » Tue Mar 27, 2012 15:58

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^_^
 

User avatar
Jordach
Member
 
Posts: 4412
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Tue Mar 27, 2012 16:08

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

( ͡° ͜ʖ ͡°) ( ͡o ͜ʖ ͡o) [$ ( ͡° ͜ʖ ͡°) $] ( ͡$ ͜ʖ ͡$) ヽ༼ຈل͜ຈ༽ノ



My image and media server is back online and is functioning as normal.
 

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

by RAPHAEL » Tue Mar 27, 2012 16:18

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)
 

User avatar
Jordach
Member
 
Posts: 4412
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Tue Mar 27, 2012 16:18

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.

( ͡° ͜ʖ ͡°) ( ͡o ͜ʖ ͡o) [$ ( ͡° ͜ʖ ͡°) $] ( ͡$ ͜ʖ ͡$) ヽ༼ຈل͜ຈ༽ノ



My image and media server is back online and is functioning as normal.
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Tue Mar 27, 2012 16:28

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

by RAPHAEL » Tue Mar 27, 2012 19:34

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

by sdzen » Tue Mar 27, 2012 19:47

i can stop the playing
[h]Zen S.D.[/h] 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

by RAPHAEL » Tue Mar 27, 2012 20:10

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

by sdzen » Tue Mar 27, 2012 20:11

well i got that error once when i was running 8 soundblocks at once :P 7's fine but at 8 its oh no!!!
[h]Zen S.D.[/h] 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

by Death Dealer » Tue Mar 27, 2012 20:47

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

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Wed Mar 28, 2012 15:01

Death Dealer wrote:your link is broken.

Download link? No
Link to newgrounds? No
Redstone for minetest: Mesecons (mesecons.net)
 

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

by Death Dealer » Wed Mar 28, 2012 18:24

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

User avatar
kddekadenz
Member
 
Posts: 323
Joined: Mon Jun 27, 2011 17:21
GitHub: tinyworlds

by kddekadenz » Sat Mar 31, 2012 11:43

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
 

User avatar
Hackeridze
Member
 
Posts: 310
Joined: Thu Nov 03, 2011 13:35

by Hackeridze » Sat Mar 31, 2012 14:35

I wanna have "Have Love Will Travel - The Sonics"! Too old, so no copyrights.
My game: RTMG
GENTOO USER
 

User avatar
kddekadenz
Member
 
Posts: 323
Joined: Mon Jun 27, 2011 17:21
GitHub: tinyworlds

by kddekadenz » Sat Mar 31, 2012 15:04

Hackeridze wrote:I wanna have "Have Love Will Travel - The Sonics"! Too old, so no copyrights.

Not in all countries..
 

User avatar
IPushButton2653
Member
 
Posts: 666
Joined: Wed Nov 16, 2011 22:47

by IPushButton2653 » Sat Mar 31, 2012 22:27

Make the music box an amplifier..........make a simple guitar..............pretend to be playing heavy metal...........
 

Next

Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 45 guests

cron