]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Add ClientObjectRef.get_properties
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 10 May 2021 13:41:23 +0000 (15:41 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 10 May 2021 13:41:23 +0000 (15:41 +0200)
doc/client_lua_api.txt
src/script/lua_api/l_clientobject.cpp
src/script/lua_api/l_clientobject.h

index d7a8b6bcee480c9bfe34051bc3e5e75a287d6d8c..bc78d5dda80e3f6be4cdb3056f3005a8bb9bdd1d 100644 (file)
@@ -1411,9 +1411,10 @@ This is basically a reference to a C++ `GenericCAO`.
 * `is_player()`: returns true if the object is a player
 * `is_local_player()`: returns true if the object is the local player
 * `get_attach()`: returns parent or nil if it isn't attached.
-* `get_nametag()`: returns the nametag (string)
-* `get_item_textures()`: returns the textures
-* `get_max_hp()`: returns the maximum heath
+* `get_nametag()`: returns the nametag (deprecated, use get_properties().nametag instead)
+* `get_item_textures()`: returns the textures (deprecated, use get_properties().textures instead)
+* `get_max_hp()`: returns the maximum heath (deprecated, use get_properties().hp_max instead)
+* `get_properties()`: returns object property table
 * `punch()`: punches the object
 * `rightclick()`: rightclicks the object
 * `remove()`: removes the object permanently
index 76d0d65ab9f30de455b599d185e4c713532407bb..7b9c4c3fa04b2eaa7bc3eb20460cb2f2d0890294 100644 (file)
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "lua_api/l_clientobject.h"
 #include "l_internal.h"
 #include "common/c_converter.h"
+#include "common/c_content.h"
 #include "client/client.h"
 #include "object_properties.h"
 #include "util/pointedthing.h"
@@ -118,6 +119,7 @@ int ClientObjectRef::l_get_attach(lua_State *L)
 
 int ClientObjectRef::l_get_nametag(lua_State *L)
 {
+       log_deprecated(L,"Deprecated call to get_nametag, use get_properties().nametag instead");
        ClientObjectRef *ref = checkobject(L, 1);
        GenericCAO *gcao = get_generic_cao(ref, L);
        ObjectProperties *props = gcao->getProperties();
@@ -127,6 +129,7 @@ int ClientObjectRef::l_get_nametag(lua_State *L)
 
 int ClientObjectRef::l_get_item_textures(lua_State *L)
 {
+       log_deprecated(L,"Deprecated call to get_item_textures, use get_properties().textures instead");
        ClientObjectRef *ref = checkobject(L, 1);
        GenericCAO *gcao = get_generic_cao(ref, L);
        ObjectProperties *props = gcao->getProperties();
@@ -138,20 +141,30 @@ int ClientObjectRef::l_get_item_textures(lua_State *L)
        return 1;
 }
 
-int ClientObjectRef::l_get_hp(lua_State *L)
+int ClientObjectRef::l_get_max_hp(lua_State *L)
 {
+       log_deprecated(L,"Deprecated call to get_max_hp, use get_properties().hp_max instead");
        ClientObjectRef *ref = checkobject(L, 1);
        GenericCAO *gcao = get_generic_cao(ref, L);
-       lua_pushnumber(L, gcao->getHp());
+       ObjectProperties *props = gcao->getProperties();
+       lua_pushnumber(L, props->hp_max);
        return 1;
 }
 
-int ClientObjectRef::l_get_max_hp(lua_State *L)
+int ClientObjectRef::l_get_properties(lua_State *L)
 {
        ClientObjectRef *ref = checkobject(L, 1);
        GenericCAO *gcao = get_generic_cao(ref, L);
-       ObjectProperties *props = gcao->getProperties();
-       lua_pushnumber(L, props->hp_max);
+       ObjectProperties *prop = gcao->getProperties();
+       push_object_properties(L, prop);
+       return 1;
+}
+
+int ClientObjectRef::l_get_hp(lua_State *L)
+{
+       ClientObjectRef *ref = checkobject(L, 1);
+       GenericCAO *gcao = get_generic_cao(ref, L);
+       lua_pushnumber(L, gcao->getHp());
        return 1;
 }
 
@@ -245,6 +258,7 @@ luaL_Reg ClientObjectRef::methods[] = {luamethod(ClientObjectRef, get_pos),
                luamethod(ClientObjectRef, get_attach),
                luamethod(ClientObjectRef, get_nametag),
                luamethod(ClientObjectRef, get_item_textures),
+               luamethod(ClientObjectRef, get_properties),
                luamethod(ClientObjectRef, get_hp),
                luamethod(ClientObjectRef, get_max_hp), luamethod(ClientObjectRef, punch),
                luamethod(ClientObjectRef, rightclick), {0, 0}};
index ebc0f2a90b3b219508230f88befa3f99711e53bb..160b6c4fe5e8fcb17ead8bba7667e0c48e122cf0 100644 (file)
@@ -78,6 +78,9 @@ class ClientObjectRef : public ModApiBase
        // get_textures(self)
        static int l_get_item_textures(lua_State *L);
 
+       // get_properties(self)
+       static int l_get_properties(lua_State *L);
+
        // get_hp(self)
        static int l_get_hp(lua_State *L);