]> git.lizzy.rs Git - minetest.git/commitdiff
Add different place sound for nodes
authorPilzAdam <pilzadam@minetest.net>
Mon, 25 Mar 2013 22:59:17 +0000 (23:59 +0100)
committerPilzAdam <pilzadam@minetest.net>
Fri, 29 Mar 2013 19:14:18 +0000 (20:14 +0100)
doc/lua_api.txt
games/minimal/mods/default/init.lua
src/clientserver.h
src/game.cpp
src/itemdef.cpp
src/itemdef.h
src/scriptapi_item.cpp

index 42ca58239374928ea70246d1c2df335964c476dc..beb70db1577a7cbd7b35eb76797150b4792e0782 100644 (file)
@@ -1514,6 +1514,9 @@ Item definition (register_node, register_craftitem, register_tool)
     ^ Otherwise should be name of node which the client immediately places
       on ground when the player places the item. Server will always update
       actual result to client in a short moment.
+    sound = {
+        place = <SimpleSoundSpec>,
+    }
 
     on_place = func(itemstack, placer, pointed_thing),
     ^ Shall place item and return the leftover itemstack
@@ -1581,6 +1584,7 @@ Node definition (register_node)
         footstep = <SimpleSoundSpec>,
         dig = <SimpleSoundSpec>, -- "__group" = group-based sound (default)
         dug = <SimpleSoundSpec>,
+        place = <SimpleSoundSpec>,
     },
 
     on_construct = func(pos),
index fbb481a0cd440c02edc02af285af3ec3403813bc..163998883bbd0ffe116fbd3b18d3f7169a7bbba7 100644 (file)
@@ -659,6 +659,8 @@ function default.node_sound_dirt_defaults(table)
                        {name="", gain=0.5}
        --table.dug = table.dug or
        --              {name="default_dirt_break", gain=0.5}
+       table.place = table.place or
+                       {name="default_grass_footstep", gain=0.5}
        default.node_sound_defaults(table)
        return table
 end
index aba84fb311c0012f509b3dee30ff184c0d400fdf..28b57997195a1e79093478fcaf66f189a020f698 100644 (file)
@@ -87,6 +87,7 @@ SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed);
                TOCLIENT_DELETE_PARTICLESPAWNER
        PROTOCOL_VERSION 18:
                damageGroups added to ToolCapabilities
+               sound_place added to ItemDefinition
 */
 
 #define LATEST_PROTOCOL_VERSION 18
index 58ca654a0258d922eddc65f5aa6408b2b408afe8..5e4e0614803f5050733c0a3c11d227d16207d0b6 100644 (file)
@@ -2394,11 +2394,6 @@ void the_game(
                                }
                        }
                        
-                       // We can't actually know, but assume the sound of right-clicking
-                       // to be the sound of placing a node
-                       soundmaker.m_player_rightpunch_sound.gain = 0.5;
-                       soundmaker.m_player_rightpunch_sound.name = "default_place_node";
-                       
                        /*
                                Handle digging
                        */
@@ -2617,6 +2612,9 @@ void the_game(
                                                                        <<") - Position not loaded"<<std::endl;
                                                }
                                        }while(0);
+                                       
+                                       // Read the sound
+                                       soundmaker.m_player_rightpunch_sound = def.sound_place;
                                }
                        }
                }
index 98d7ce0a8dce0dfe6808818441f02c5ebd8ac523..72ce0e6546dd990093e5b120bd5e0b622e5d3169 100644 (file)
@@ -75,6 +75,7 @@ ItemDefinition& ItemDefinition::operator=(const ItemDefinition &def)
        }
        groups = def.groups;
        node_placement_prediction = def.node_placement_prediction;
+       sound_place = def.sound_place;
        return *this;
 }
 
@@ -107,13 +108,17 @@ void ItemDefinition::reset()
                tool_capabilities = NULL;
        }
        groups.clear();
+       sound_place = SimpleSoundSpec();
 
        node_placement_prediction = "";
 }
 
 void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
 {
-       writeU8(os, 1); // version
+       if(protocol_version <= 17)
+               writeU8(os, 1); // version
+       else
+               writeU8(os, 2); // version
        writeU8(os, type);
        os<<serializeString(name);
        os<<serializeString(description);
@@ -137,6 +142,11 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
                writeS16(os, i->second);
        }
        os<<serializeString(node_placement_prediction);
+       if(protocol_version > 17){
+               //serializeSimpleSoundSpec(sound_place, os);
+               os<<serializeString(sound_place.name);
+               writeF1000(os, sound_place.gain);
+       }
 }
 
 void ItemDefinition::deSerialize(std::istream &is)
@@ -146,7 +156,7 @@ void ItemDefinition::deSerialize(std::istream &is)
 
        // Deserialize
        int version = readU8(is);
-       if(version != 1)
+       if(version != 1 && version != 2)
                throw SerializationError("unsupported ItemDefinition version");
        type = (enum ItemType)readU8(is);
        name = deSerializeString(is);
@@ -171,10 +181,24 @@ void ItemDefinition::deSerialize(std::istream &is)
                int value = readS16(is);
                groups[name] = value;
        }
+       if(version == 1){
+               // We cant be sure that node_placement_prediction is send in version 1
+               try{
+                       node_placement_prediction = deSerializeString(is);
+               }catch(SerializationError &e) {};
+               // Set the old default sound
+               sound_place.name = "default_place_node";
+               sound_place.gain = 0.5;
+       } else if(version == 2) {
+               node_placement_prediction = deSerializeString(is);
+               //deserializeSimpleSoundSpec(sound_place, is);
+               sound_place.name = deSerializeString(is);
+               sound_place.gain = readF1000(is);
+       }
        // If you add anything here, insert it primarily inside the try-catch
        // block to not need to increase the version.
        try{
-               node_placement_prediction = deSerializeString(is);
+               
        }catch(SerializationError &e) {};
 }
 
index cbbe7e2adcf844ba35db37c9c582bf8f7ac07c61..08c9c835870b111254f8e43a5dbebb520e78d94f 100644 (file)
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <iostream>
 #include <set>
 #include "itemgroup.h"
+#include "sound.h"
 class IGameDef;
 struct ToolCapabilities;
 
@@ -66,6 +67,7 @@ struct ItemDefinition
        // May be NULL. If non-NULL, deleted by destructor
        ToolCapabilities *tool_capabilities;
        ItemGroupList groups;
+       SimpleSoundSpec sound_place;
 
        // Client shall immediately place this node when player places the item.
        // Server will update the precise end result a moment later.
index 204939f8f52fc6af6201a5e6995553f111f9ab3b..b266d856d26fbd332fa9be2940584fb24b706f54 100644 (file)
@@ -96,6 +96,14 @@ ItemDefinition read_item_definition(lua_State *L, int index,
        read_groups(L, -1, def.groups);
        lua_pop(L, 1);
 
+       lua_getfield(L, index, "sounds");
+       if(lua_istable(L, -1)){
+               lua_getfield(L, -1, "place");
+               read_soundspec(L, -1, def.sound_place);
+               lua_pop(L, 1);
+       }
+       lua_pop(L, 1);
+
        // Client shall immediately place this node when player places the item.
        // Server will update the precise end result a moment later.
        // "" = no prediction