Page 1 of 1

Placenode Custom Sounds

PostPosted: Fri Nov 23, 2012 01:23
by jordan4ibanez
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.

PostPosted: Fri Nov 23, 2012 11:24
by PilzAdam
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.

PostPosted: Fri Nov 23, 2012 14:18
by PilzAdam

PostPosted: Sat Nov 24, 2012 01:20
by jordan4ibanez

Push it to the main engine source code on github, PWEASE.