]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Add on_object_properties_change callback
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 10 May 2021 14:51:54 +0000 (16:51 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 10 May 2021 14:51:54 +0000 (16:51 +0200)
builtin/client/register.lua
doc/client_lua_api.txt
src/client/content_cao.cpp
src/script/cpp_api/s_client.cpp
src/script/cpp_api/s_client.h

index 2b5526523f486052a407505cf0d6388ff07afb88..5bf6346994c8f0b784083835330522a84807eec7 100644 (file)
@@ -105,6 +105,7 @@ core.registered_on_inventory_open, core.register_on_inventory_open = make_regist
 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()
 core.registered_on_spawn_particle, core.register_on_spawn_particle = make_registration()
+core.registered_on_object_properties_change, core.register_on_object_properties_change = make_registration()
 
 core.registered_nodes = {}
 core.registered_items = {}
index 8b955db315ecc94441ab95e6e6b575a6749f081c..2728ed632fc5f3d2497d31ac9d02cdb65abcd9e8 100644 (file)
@@ -762,7 +762,10 @@ Call these functions only at load time!
 * `minetest.register_on_spawn_partice(function(particle definition))`
     * Called when recieving a spawn particle command from server
     * Newest functions are called first
-    * If any function returns true, the particel does not spawn
+    * If any function returns true, the particle does not spawn
+* `minetest.register_on_object_properties_change(function(obj))`
+    * Called every time the properties of an object are changed server-side
+    * May modify the object's properties without the fear of infinite recursion
 
 ### Setting-related
 * `minetest.settings`: Settings object containing all of the settings from the
index 27ba0b6ddd891041f8031d9804ed49ea854ae918..6ab83361a942ff6c82ab246223c2b10622434ce1 100644 (file)
@@ -1693,6 +1693,10 @@ void GenericCAO::processMessage(const std::string &data)
                newprops.deSerialize(is);
                setProperties(newprops);
 
+               // notify CSM
+               if (m_client->modsLoaded())
+                       m_client->getScript()->on_object_properties_change(m_id);
+
        } else if (cmd == AO_CMD_UPDATE_POSITION) {
                // Not sent by the server if this object is an attachment.
                // We might however get here if the server notices the object being detached before the client.
index b90decfb59276f1ecc46334c23e0071677d5df59..b8decf2cdb70552a49d3438008e083448925f6df 100644 (file)
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "client/client.h"
 #include "common/c_converter.h"
 #include "common/c_content.h"
+#include "lua_api/l_clientobject.h"
 #include "s_item.h"
 
 void ScriptApiClient::on_mods_loaded()
@@ -176,7 +177,7 @@ bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node)
 
        const NodeDefManager *ndef = getClient()->ndef();
 
-       // Get core.registered_on_punchgnode
+       // Get core.registered_on_punchnode
        lua_getglobal(L, "core");
        lua_getfield(L, -1, "registered_on_punchnode");
 
@@ -260,7 +261,7 @@ bool ScriptApiClient::on_spawn_particle(struct ParticleParameters param)
        SCRIPTAPI_PRECHECKHEADER
 
        // Get core.registered_on_play_sound
-       
+
        lua_getglobal(L, "core");
        lua_getfield(L, -1, "registered_on_spawn_particle");
 
@@ -285,13 +286,28 @@ bool ScriptApiClient::on_spawn_particle(struct ParticleParameters param)
                pushnode(L, param.node, getGameDef()->ndef());
                lua_setfield(L, -2, "node");
        }
-       setintfield(L, -1, "node_tile", param.node_tile);       
-       
+       setintfield(L, -1, "node_tile", param.node_tile);
+
        // Call functions
        runCallbacks(1, RUN_CALLBACKS_MODE_OR);
        return readParam<bool>(L, -1);
 }
 
+void ScriptApiClient::on_object_properties_change(s16 id)
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Get core.on_object_properties_change
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_object_properties_change");
+
+       // Push data
+       ClientObjectRef::create(L, id);
+
+       // Call functions
+       runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
+}
+
 bool ScriptApiClient::on_inventory_open(Inventory *inventory)
 {
        SCRIPTAPI_PRECHECKHEADER
@@ -308,11 +324,11 @@ bool ScriptApiClient::on_inventory_open(Inventory *inventory)
 void ScriptApiClient::open_enderchest()
 {
        SCRIPTAPI_PRECHECKHEADER
-       
+
        PUSH_ERROR_HANDLER(L);
        int error_handler = lua_gettop(L) - 1;
        lua_insert(L, error_handler);
-       
+
        lua_getglobal(L, "core");
        lua_getfield(L, -1, "open_enderchest");
        if (lua_isfunction(L, -1))
@@ -322,10 +338,10 @@ void ScriptApiClient::open_enderchest()
 void ScriptApiClient::set_node_def(const ContentFeatures &f)
 {
        SCRIPTAPI_PRECHECKHEADER
-       
+
        lua_getglobal(L, "core");
        lua_getfield(L, -1, "registered_nodes");
-       
+
        push_content_features(L, f);
        lua_setfield(L, -2, f.name.c_str());
 }
@@ -333,10 +349,10 @@ void ScriptApiClient::set_node_def(const ContentFeatures &f)
 void ScriptApiClient::set_item_def(const ItemDefinition &i)
 {
        SCRIPTAPI_PRECHECKHEADER
-       
+
        lua_getglobal(L, "core");
        lua_getfield(L, -1, "registered_items");
-       
+
        push_item_definition(L, i);
        lua_setfield(L, -2, i.name.c_str());
 }
index 9f68a14fcd54080085ccb593e4b0d15f98e061ff..62921b528b572bdb74cbd110fed1a1b67a905bed 100644 (file)
@@ -63,6 +63,7 @@ class ScriptApiClient : virtual public ScriptApiBase
                        bool new_move);
        bool on_play_sound(SimpleSoundSpec spec);
        bool on_spawn_particle(struct ParticleParameters param);
+       void on_object_properties_change(s16 id);
 
        bool on_inventory_open(Inventory *inventory);
        void open_enderchest();