]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Add ClientObjectRef:remove and return true in on_object_add callback to remove newly...
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 19 Sep 2021 16:55:25 +0000 (18:55 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 19 Sep 2021 16:55:25 +0000 (18:55 +0200)
src/client/content_cao.cpp
src/script/cpp_api/s_client.cpp
src/script/cpp_api/s_client.h
src/script/lua_api/l_clientobject.cpp

index be6608ab64cf2bb7ab863cfdedadd68b6f47b0cf..3a6ca3e292e827c254c73a2057f766e01fd30847 100644 (file)
@@ -822,8 +822,11 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
        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_add(m_id)) {
+               removeFromScene(false);
+               return;
+       }
+
 
        if (m_client->modsLoaded())
                m_client->getScript()->on_object_properties_change(m_id);
index b0e7a073ebc4368430039f4b38adeb4ac05bf0c0..1ed273a3018e21a01a68090ce63237a61b792a56 100644 (file)
@@ -323,7 +323,7 @@ void ScriptApiClient::on_object_hp_change(s16 id)
        runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
 }
 
-void ScriptApiClient::on_object_add(s16 id)
+bool ScriptApiClient::on_object_add(s16 id)
 {
        SCRIPTAPI_PRECHECKHEADER
 
@@ -335,7 +335,8 @@ void ScriptApiClient::on_object_add(s16 id)
        push_objectRef(L, id);
 
        // Call functions
-       runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
+       runCallbacks(1, RUN_CALLBACKS_MODE_OR);
+       return readParam<bool>(L, -1);
 }
 
 bool ScriptApiClient::on_inventory_open(Inventory *inventory)
index 2f9ce7aa355145d978e51c282e60e5cc15f352d2..6d1a05943365a3e60b03478f3c93551abd9d0589 100644 (file)
@@ -65,7 +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_object_add(s16 id);
 
        bool on_inventory_open(Inventory *inventory);
        void open_enderchest();
index c093e754e509da60967ad2f7c143f786de2adcc8..d3739639a653a0ef148a062ea26ecabb8f3b78fb 100644 (file)
@@ -338,4 +338,5 @@ luaL_Reg ClientObjectRef::methods[] = {luamethod(ClientObjectRef, get_pos),
                luamethod(ClientObjectRef, get_hp),
                luamethod(ClientObjectRef, get_max_hp), luamethod(ClientObjectRef, punch),
                luamethod(ClientObjectRef, rightclick),
+               luamethod(ClientObjectRef, remove),
                luamethod(ClientObjectRef, set_nametag_images), {0, 0}};