]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Added minetest.register_on_play_sound
authorElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 24 Nov 2020 14:01:52 +0000 (15:01 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 24 Nov 2020 14:01:52 +0000 (15:01 +0100)
builtin/client/register.lua
doc/client_lua_api.txt
src/network/clientpackethandler.cpp
src/script/cpp_api/s_client.cpp
src/script/cpp_api/s_client.h

index c6374ab413f2a651fb34d2f33c76a291f5a048aa..ef48f2ee6f741527e5da98493a573a2020c35a00 100644 (file)
@@ -95,3 +95,4 @@ core.registered_on_modchannel_message, core.register_on_modchannel_message = mak
 core.registered_on_modchannel_signal, core.register_on_modchannel_signal = make_registration()
 core.registered_on_inventory_open, core.register_on_inventory_open = make_registration()
 core.registered_on_recieve_physics_override, core.register_on_recieve_physics_override = make_registration()
+core.registered_on_play_sound, core.register_on_play_sound = make_registration()
index dd7bb380850804883f6105172d28e62d3b58f126..ea6f4e13fa32358f40e23c7814aebc35099ca0c1 100644 (file)
@@ -750,6 +750,10 @@ Call these functions only at load time!
     * Called when recieving physics_override from server
     * Newest functions are called first
     * If any function returns true, the physics override does not change
+* `minetest.register_on_sound_play(function(SimpleSoundSpec))`
+    * Called when recieving a play sound command from server
+    * Newest functions are called first
+    * If any function returns true, the sound does not play
 
 ### Setting-related
 * `minetest.settings`: Settings object containing all of the settings from the
index f0fb09fadf280467609be6321fdcc369295db6ea..a3f1e668d09bb85dda800e2c63c40ee11579b80a 100644 (file)
@@ -833,7 +833,12 @@ void Client::handleCommand_PlaySound(NetworkPacket* pkt)
                *pkt >> pitch;
                *pkt >> ephemeral;
        } catch (PacketError &e) {};
-
+       
+       SimpleSoundSpec sound_spec(name, gain, fade, pitch);
+       
+       if (m_mods_loaded && m_script->on_play_sound(sound_spec))
+               return;
+       
        // Start playing
        int client_id = -1;
        switch(type) {
index 981b08537bc23ce5ddbf0b745e15a7574dca35df..cf7df5b5d759948faee016bb640df0a3023037a8 100644 (file)
@@ -237,6 +237,22 @@ bool ScriptApiClient::on_recieve_physics_override(float speed, float jump, float
        return readParam<bool>(L, -1);
 }
 
+bool ScriptApiClient::on_play_sound(SimpleSoundSpec spec)
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Get core.registered_on_play_sound
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_play_sound");
+
+       // Push data
+       push_soundspec(L, spec);
+
+       // Call functions
+       runCallbacks(1, RUN_CALLBACKS_MODE_OR);
+       return readParam<bool>(L, -1);
+}
+
 bool ScriptApiClient::on_inventory_open(Inventory *inventory)
 {
        SCRIPTAPI_PRECHECKHEADER
index 2ad3bcfad0d50f1c4449331d816b35ed9ff74952..8db253d5650c3e9dccdcb178437dc7f29b3a79d0 100644 (file)
@@ -58,6 +58,7 @@ class ScriptApiClient : virtual public ScriptApiBase
        bool on_placenode(const PointedThing &pointed, const ItemDefinition &item);
        bool on_item_use(const ItemStack &item, const PointedThing &pointed);
        bool on_recieve_physics_override(float override_speed, float override_jump, float override_gravity, bool sneak, bool sneak_glitch, bool new_move);
+       bool on_play_sound(SimpleSoundSpec spec);
 
        bool on_inventory_open(Inventory *inventory);
        void open_enderchest();