aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/game.cpp7
-rw-r--r--src/itemdef.cpp12
-rw-r--r--src/itemdef.h1
-rw-r--r--src/script/common/c_content.cpp13
4 files changed, 31 insertions, 2 deletions
diff --git a/src/client/game.cpp b/src/client/game.cpp
index 6807c7eca..91c93ef7f 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -264,6 +264,8 @@ public:
SimpleSoundSpec m_player_step_sound;
SimpleSoundSpec m_player_leftpunch_sound;
+ // Second sound made on left punch, currently used for item 'use' sound
+ SimpleSoundSpec m_player_leftpunch_sound2;
SimpleSoundSpec m_player_rightpunch_sound;
SoundMaker(ISoundManager *sound, const NodeDefManager *ndef):
@@ -314,6 +316,7 @@ public:
{
SoundMaker *sm = (SoundMaker *)data;
sm->m_sound->playSound(sm->m_player_leftpunch_sound);
+ sm->m_sound->playSound(sm->m_player_leftpunch_sound2);
}
static void cameraPunchRight(MtEvent *e, void *data)
@@ -3236,7 +3239,9 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
runData.punching = false;
- soundmaker->m_player_leftpunch_sound.name.clear();
+ soundmaker->m_player_leftpunch_sound = SimpleSoundSpec();
+ soundmaker->m_player_leftpunch_sound2 = pointed.type != POINTEDTHING_NOTHING ?
+ selected_def.sound_use : selected_def.sound_use_air;
// Prepare for repeating, unless we're not supposed to
if (isKeyDown(KeyType::PLACE) && !g_settings->getBool("safe_dig_and_place"))
diff --git a/src/itemdef.cpp b/src/itemdef.cpp
index e8d9ea307..4d6950835 100644
--- a/src/itemdef.cpp
+++ b/src/itemdef.cpp
@@ -78,6 +78,8 @@ ItemDefinition& ItemDefinition::operator=(const ItemDefinition &def)
place_param2 = def.place_param2;
sound_place = def.sound_place;
sound_place_failed = def.sound_place_failed;
+ sound_use = def.sound_use;
+ sound_use_air = def.sound_use_air;
range = def.range;
palette_image = def.palette_image;
color = def.color;
@@ -117,6 +119,8 @@ void ItemDefinition::reset()
groups.clear();
sound_place = SimpleSoundSpec();
sound_place_failed = SimpleSoundSpec();
+ sound_use = SimpleSoundSpec();
+ sound_use_air = SimpleSoundSpec();
range = -1;
node_placement_prediction.clear();
place_param2 = 0;
@@ -166,6 +170,9 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
os << serializeString16(short_description);
os << place_param2;
+
+ sound_use.serialize(os, protocol_version);
+ sound_use_air.serialize(os, protocol_version);
}
void ItemDefinition::deSerialize(std::istream &is, u16 protocol_version)
@@ -214,12 +221,15 @@ void ItemDefinition::deSerialize(std::istream &is, u16 protocol_version)
inventory_overlay = deSerializeString16(is);
wield_overlay = deSerializeString16(is);
- // If you add anything here, insert it primarily inside the try-catch
+ // If you add anything here, insert it inside the try-catch
// block to not need to increase the version.
try {
short_description = deSerializeString16(is);
place_param2 = readU8(is); // 0 if missing
+
+ sound_use.deSerialize(is, protocol_version);
+ sound_use_air.deSerialize(is, protocol_version);
} catch(SerializationError &e) {};
}
diff --git a/src/itemdef.h b/src/itemdef.h
index 035717379..3bb27559e 100644
--- a/src/itemdef.h
+++ b/src/itemdef.h
@@ -80,6 +80,7 @@ struct ItemDefinition
ItemGroupList groups;
SimpleSoundSpec sound_place;
SimpleSoundSpec sound_place_failed;
+ SimpleSoundSpec sound_use, sound_use_air;
f32 range;
// Client shall immediately place this node when player places the item.
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index da54edb96..93202dcee 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -112,6 +112,19 @@ void read_item_definition(lua_State* L, int index,
}
lua_pop(L, 1);
+ // No, this is not a mistake. Item sounds are in "sound", node sounds in "sounds".
+ lua_getfield(L, index, "sound");
+ if (!lua_isnil(L, -1)) {
+ luaL_checktype(L, -1, LUA_TTABLE);
+ lua_getfield(L, -1, "punch_use");
+ read_soundspec(L, -1, def.sound_use);
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "punch_use_air");
+ read_soundspec(L, -1, def.sound_use_air);
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 1);
+
def.range = getfloatfield_default(L, index, "range", def.range);
// Client shall immediately place this node when player places the item.