diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-05-10 20:45:05 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-05-10 20:45:05 +0200 |
commit | c86dcd0f682f76339989afec255bf3d7078db096 (patch) | |
tree | cd74cff6f879026a47c197545796aa2deb20ea15 /src/script | |
parent | b84ed7d0beb524a62070a503a40b78b77506b258 (diff) | |
download | dragonfireclient-c86dcd0f682f76339989afec255bf3d7078db096.tar.xz |
Add on_object_hp_change callback and nametag images
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/cpp_api/s_client.cpp | 15 | ||||
-rw-r--r-- | src/script/cpp_api/s_client.h | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_clientobject.cpp | 23 | ||||
-rw-r--r-- | src/script/lua_api/l_clientobject.h | 3 |
4 files changed, 40 insertions, 2 deletions
diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp index b8decf2cd..2231cf573 100644 --- a/src/script/cpp_api/s_client.cpp +++ b/src/script/cpp_api/s_client.cpp @@ -308,6 +308,21 @@ void ScriptApiClient::on_object_properties_change(s16 id) runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); } +void ScriptApiClient::on_object_hp_change(s16 id) +{ + SCRIPTAPI_PRECHECKHEADER + + // Get core.on_object_hp_change + lua_getglobal(L, "core"); + lua_getfield(L, -1, "registered_on_object_hp_change"); + + // Push data + ClientObjectRef::create(L, id); + + // Call functions + runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); +} + bool ScriptApiClient::on_inventory_open(Inventory *inventory) { SCRIPTAPI_PRECHECKHEADER diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h index 62921b528..a2babfac8 100644 --- a/src/script/cpp_api/s_client.h +++ b/src/script/cpp_api/s_client.h @@ -64,6 +64,7 @@ public: bool on_play_sound(SimpleSoundSpec spec); bool on_spawn_particle(struct ParticleParameters param); void on_object_properties_change(s16 id); + void on_object_hp_change(s16 id); bool on_inventory_open(Inventory *inventory); void open_enderchest(); diff --git a/src/script/lua_api/l_clientobject.cpp b/src/script/lua_api/l_clientobject.cpp index 0147fd48b..8a4647d45 100644 --- a/src/script/lua_api/l_clientobject.cpp +++ b/src/script/lua_api/l_clientobject.cpp @@ -205,6 +205,23 @@ int ClientObjectRef::l_remove(lua_State *L) return 0; } +int ClientObjectRef::l_set_nametag_images(lua_State *L) +{ + ClientObjectRef *ref = checkobject(L, 1); + GenericCAO *gcao = get_generic_cao(ref, L); + gcao->nametag_images.clear(); + if(lua_istable(L, 2)){ + lua_pushnil(L); + while(lua_next(L, 2) != 0){ + gcao->nametag_images.push_back(lua_tostring(L, -1)); + lua_pop(L, 1); + } + } + gcao->updateNametag(); + + return 0; +} + ClientObjectRef::ClientObjectRef(ClientActiveObject *object) : m_object(object) { } @@ -271,5 +288,7 @@ luaL_Reg ClientObjectRef::methods[] = {luamethod(ClientObjectRef, get_pos), luamethod(ClientObjectRef, get_properties), luamethod(ClientObjectRef, set_properties), luamethod(ClientObjectRef, get_hp), - luamethod(ClientObjectRef, get_max_hp), luamethod(ClientObjectRef, punch), - luamethod(ClientObjectRef, rightclick), {0, 0}}; + luamethod(ClientObjectRef, get_max_hp), + luamethod(ClientObjectRef, punch), + luamethod(ClientObjectRef, rightclick), + luamethod(ClientObjectRef, set_nametag_images), {0, 0}}; diff --git a/src/script/lua_api/l_clientobject.h b/src/script/lua_api/l_clientobject.h index 22d2f4a1c..60d10dcf6 100644 --- a/src/script/lua_api/l_clientobject.h +++ b/src/script/lua_api/l_clientobject.h @@ -98,4 +98,7 @@ private: // remove(self) static int l_remove(lua_State *L); + + // set_nametag_images(self, images) + static int l_set_nametag_images(lua_State *L); }; |