Placenode Custom Sounds

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

Placenode Custom Sounds

by jordan4ibanez » Fri Nov 23, 2012 01:23

Well, After complaining about this for months, I gave up and made this myself. What this does, is allow for different placenode sounds to be played. This is a very simple implementation.

First take a look at the code

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
minetest.register_on_placenode(function(newnode,placer)
    --do this in case someone forgot to put sound in their mod and such
    if minetest.registered_nodes[minetest.env:get_node(newnode).name].sounds then
        local sound = minetest.registered_nodes[minetest.env:get_node(newnode).name].sounds.place.name
        local gain = minetest.registered_nodes[minetest.env:get_node(newnode).name].sounds.place.gain
        if sound ~= nil and gain ~= nil then
            minetest.sound_play(sound, {to_player = placer,gain=gain})
        end
    end
end)


How do you use this you ask? Well just get a nice sound you want played for a type of block (let's say default placenode sound) when you place it.
You would modify this:
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
function default.node_sound_defaults(table)
    table = table or {}
    table.footstep = table.footstep or
            {name="", gain=1.0}
    table.dug = table.dug or
            {name="default_dug_node", gain=1.0}
    return table
end


And add in this line in between table.dug and return table:
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
    table.place = table.place or
            {name="default_dug_node", gain=1.0}


So it would look like this:
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
function default.node_sound_defaults(table)
    table = table or {}
    table.footstep = table.footstep or
            {name="", gain=1.0}
    table.dug = table.dug or
            {name="default_dug_node", gain=1.0}
    table.place = table.place or
            {name="default_dug_node", gain=1.0}
    return table
end


Make sure you delete the default placenode sounds so only the sounds you want play.
This also has a few other advantages:
1.) It removes the sound when you just rightclick a node with nothing.
2.) It can show you how much a server is lagging just by placing a node.
3.) The obvious. Lol.

I hope to see this in minetest_game soon. Oh yea, just stick the first section of code at the bottom of the default mod's init.lua. Have fun.
Last edited by jordan4ibanez on Fri Nov 23, 2012 01:28, edited 1 time in total.
If you can think it, you can make it.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Fri Nov 23, 2012 11:24

Is the default place node sound handled in the core code? It would be nice if you would patch this and pull request it to upstream.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Fri Nov 23, 2012 14:18

 

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

by jordan4ibanez » Sat Nov 24, 2012 01:20


Push it to the main engine source code on github, PWEASE.
If you can think it, you can make it.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 15 guests

cron