]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Add on_object_add callback 2021.05
authorElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 11 May 2021 17:15:23 +0000 (19:15 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 11 May 2021 17:15:23 +0000 (19:15 +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 6a6d8e13c3ce6e9470fc4119689d3d7c5f90db4e..f17188b842b6c1de422a3aacba5a573838fa24ba 100644 (file)
@@ -107,6 +107,7 @@ 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_on_object_hp_change, core.register_on_object_hp_change = make_registration()
+core.registered_on_object_add, core.register_on_object_add = make_registration()
 
 core.registered_nodes = {}
 core.registered_items = {}
index e33fe0e3a37bc8bc8d4c0f14c92b5571f4f3becd..a02a281f51d16dc4b7700db6a351b22c479f0f30 100644 (file)
@@ -763,6 +763,8 @@ Call these functions only at load time!
     * Called when recieving a spawn particle command from server
     * Newest functions are called first
     * If any function returns true, the particle does not spawn
+* `minetest.register_on_object_add(function(obj))`
+       * Called every time an object is added
 * `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
index 84d200a7397f14801da1b899bc39528aac0f3832..5e9060fc8b3b19119e08a85c80339d08c5c8a58b 100644 (file)
@@ -829,6 +829,9 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
        setNodeLight(m_last_light);
        updateMeshCulling();
 
+       if (m_client->modsLoaded())
+               m_client->getScript()->on_object_add(m_id);
+
        if (m_client->modsLoaded())
                m_client->getScript()->on_object_properties_change(m_id);
 }
index 7971e4081891a99587477c3fd7508ac6efc03f0b..5990c4df218289a1883fd12f2d1eb4581aa8f85f 100644 (file)
@@ -297,7 +297,7 @@ void ScriptApiClient::on_object_properties_change(s16 id)
 {
        SCRIPTAPI_PRECHECKHEADER
 
-       // Get core.on_object_properties_change
+       // Get core.registered_on_object_properties_change
        lua_getglobal(L, "core");
        lua_getfield(L, -1, "registered_on_object_properties_change");
 
@@ -312,7 +312,7 @@ void ScriptApiClient::on_object_hp_change(s16 id)
 {
        SCRIPTAPI_PRECHECKHEADER
 
-       // Get core.on_object_hp_change
+       // Get core.registered_on_object_hp_change
        lua_getglobal(L, "core");
        lua_getfield(L, -1, "registered_on_object_hp_change");
 
@@ -323,6 +323,21 @@ void ScriptApiClient::on_object_hp_change(s16 id)
        runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
 }
 
+void ScriptApiClient::on_object_add(s16 id)
+{
+       SCRIPTAPI_PRECHECKHEADER
+
+       // Get core.registered_on_object_add
+       lua_getglobal(L, "core");
+       lua_getfield(L, -1, "registered_on_object_add");
+
+       // Push data
+       push_objectRef(L, id);
+
+       // Call functions
+       runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
+}
+
 bool ScriptApiClient::on_inventory_open(Inventory *inventory)
 {
        SCRIPTAPI_PRECHECKHEADER
index a2babfac8b10b100d58f824eaf74c3d4dd59678e..12d96d81ee4edff17516c3df8f3a8eeef7d7cfde 100644 (file)
@@ -65,6 +65,7 @@ class ScriptApiClient : virtual public ScriptApiBase
        bool on_spawn_particle(struct ParticleParameters param);
        void on_object_properties_change(s16 id);
        void on_object_hp_change(s16 id);
+       void on_object_add(s16 id);
 
        bool on_inventory_open(Inventory *inventory);
        void open_enderchest();