add gfx.blockwraps library & add on_player_tick world event

This commit is contained in:
MihailRis
2024-11-21 06:48:23 +03:00
parent 2ba90625ce
commit 61b1aa8e3d
13 changed files with 98 additions and 15 deletions
+3 -2
View File
@@ -18,6 +18,7 @@ extern const luaL_Reg audiolib[];
extern const luaL_Reg base64lib[];
extern const luaL_Reg bjsonlib[];
extern const luaL_Reg blocklib[];
extern const luaL_Reg blockwrapslib[]; // gfx.blockwraps
extern const luaL_Reg cameralib[];
extern const luaL_Reg consolelib[];
extern const luaL_Reg corelib[];
@@ -32,10 +33,10 @@ extern const luaL_Reg itemlib[];
extern const luaL_Reg jsonlib[];
extern const luaL_Reg mat4lib[];
extern const luaL_Reg packlib[];
extern const luaL_Reg particleslib[];
extern const luaL_Reg particleslib[]; // gfx.particles
extern const luaL_Reg playerlib[];
extern const luaL_Reg quatlib[];
extern const luaL_Reg text3dlib[];
extern const luaL_Reg text3dlib[]; // gfx.text3d
extern const luaL_Reg timelib[];
extern const luaL_Reg tomllib[];
extern const luaL_Reg utf8lib[];
@@ -0,0 +1,43 @@
#include "api_lua.hpp"
#include "logic/scripting/scripting_hud.hpp"
#include "graphics/render/WorldRenderer.hpp"
#include "graphics/render/BlockWrapsRenderer.hpp"
using namespace scripting;
static int l_wrap(lua::State* L) {
auto position = lua::tovec3(L, 1);
std::string texture = lua::require_string(L, 2);
return lua::pushinteger(
L, renderer->blockWraps->add(position, std::move(texture))
);
}
static int l_unwrap(lua::State* L) {
renderer->blockWraps->remove(lua::tointeger(L, 1));
return 0;
}
static int l_set_pos(lua::State* L) {
if (auto wrapper = renderer->blockWraps->get(lua::tointeger(L, 1))) {
wrapper->position = lua::tovec3(L, 2);
}
return 0;
}
static int l_set_texture(lua::State* L) {
if (auto wrapper = renderer->blockWraps->get(lua::tointeger(L, 1))) {
wrapper->texture = lua::require_string(L, 2);
}
return 0;
}
const luaL_Reg blockwrapslib[] = {
{"wrap", lua::wrap<l_wrap>},
{"unwrap", lua::wrap<l_unwrap>},
{"set_pos", lua::wrap<l_set_pos>},
{"set_texture", lua::wrap<l_set_texture>},
{NULL, NULL}
};