mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
[CSM] Add event on_place_node API lua (#5548)
* [CSM] Add event on_place_node API lua
This commit is contained in:
parent
ecf08255b0
commit
dc5bc6cac7
12 changed files with 88 additions and 37 deletions
|
@ -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[] =
|
||||
|
@ -117,6 +118,16 @@ void read_item_definition(lua_State* L, int index,
|
|||
def.node_placement_prediction);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue