diff options
author | Vincent Glize <vincentglize@hotmail.fr> | 2017-04-29 12:08:16 +0200 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-04-29 12:08:16 +0200 |
commit | dc5bc6cac7b81ab27e0064bc25b5fd1d8d617340 (patch) | |
tree | 5b7be08157b8c377dfd10152c04d44687e9b1c81 /src/script/common | |
parent | ecf08255b0b6b9d15b86f614942ac8f53f41302a (diff) | |
download | minetest-dc5bc6cac7b81ab27e0064bc25b5fd1d8d617340.tar.gz minetest-dc5bc6cac7b81ab27e0064bc25b5fd1d8d617340.tar.bz2 minetest-dc5bc6cac7b81ab27e0064bc25b5fd1d8d617340.zip |
[CSM] Add event on_place_node API lua (#5548)
* [CSM] Add event on_place_node API lua
Diffstat (limited to 'src/script/common')
-rw-r--r-- | src/script/common/c_content.cpp | 44 | ||||
-rw-r--r-- | src/script/common/c_content.h | 6 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 573347b4c..5fe5af58d 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "porting.h" #include "mg_schematic.h" #include "noise.h" +#include "util/pointedthing.h" #include <json/json.h> struct EnumString es_TileAnimationType[] = @@ -118,6 +119,16 @@ void read_item_definition(lua_State* L, int index, } /******************************************************************************/ +void push_item_definition(lua_State *L, const ItemDefinition &i) +{ + lua_newtable(L); + lua_pushstring(L, i.name.c_str()); + lua_setfield(L, -2, "name"); + lua_pushstring(L, i.description.c_str()); + lua_setfield(L, -2, "description"); +} + +/******************************************************************************/ void read_object_properties(lua_State *L, int index, ObjectProperties *prop, IItemDefManager *idef) { @@ -1427,3 +1438,36 @@ void read_json_value(lua_State *L, Json::Value &root, int index, u8 recursion) } lua_pop(L, 1); // Pop value } + +void push_pointed_thing(lua_State *L, const PointedThing &pointed) +{ + lua_newtable(L); + if (pointed.type == POINTEDTHING_NODE) { + lua_pushstring(L, "node"); + lua_setfield(L, -2, "type"); + push_v3s16(L, pointed.node_undersurface); + lua_setfield(L, -2, "under"); + push_v3s16(L, pointed.node_abovesurface); + lua_setfield(L, -2, "above"); + } else if (pointed.type == POINTEDTHING_OBJECT) { + lua_pushstring(L, "object"); + lua_setfield(L, -2, "type"); + push_objectRef(L, pointed.object_id); + lua_setfield(L, -2, "ref"); + } else { + lua_pushstring(L, "nothing"); + lua_setfield(L, -2, "type"); + } +} + +void push_objectRef(lua_State *L, const u16 id) +{ + // Get core.object_refs[i] + lua_getglobal(L, "core"); + lua_getfield(L, -1, "object_refs"); + luaL_checktype(L, -1, LUA_TTABLE); + lua_pushnumber(L, id); + lua_gettable(L, -2); + lua_remove(L, -2); // object_refs + lua_remove(L, -2); // core +} diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index c701c0384..219c5eb7c 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -88,6 +88,8 @@ void push_tool_capabilities (lua_State *L, void read_item_definition (lua_State *L, int index, const ItemDefinition &default_def, ItemDefinition &def); +void push_item_definition (lua_State *L, + const ItemDefinition &i); void read_object_properties (lua_State *L, int index, ObjectProperties *prop, IItemDefManager *idef); @@ -162,6 +164,10 @@ bool push_json_value (lua_State *L, void read_json_value (lua_State *L, Json::Value &root, int index, u8 recursion = 0); +void push_pointed_thing (lua_State *L, const PointedThing &pointed); + +void push_objectRef (lua_State *L, const u16 id); + extern struct EnumString es_TileAnimationType[]; #endif /* C_CONTENT_H_ */ |