diff --git a/res/content/base/scripts/hud.lua b/res/content/base/scripts/hud.lua new file mode 100644 index 00000000..8e605bb8 --- /dev/null +++ b/res/content/base/scripts/hud.lua @@ -0,0 +1,5 @@ +function on_hud_open() + input.add_callback("player.drop", function () + entity.test() + end) +end diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index f7b3b85b..a37128b8 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -247,9 +247,6 @@ void PlayerController::update(float delta, bool input, bool pause) { camControl.refresh(); if (input) { updateInteraction(); - if (Events::jactive("player.drop")) { - level->entities->drop(player->camera->position, player->camera->front*8.0f+glm::vec3(0, 2, 0)+player->hitbox->velocity); - } } else { player->selection.vox.id = BLOCK_VOID; player->selection.vox.state.rotation = 0; diff --git a/src/logic/scripting/lua/api_lua.hpp b/src/logic/scripting/lua/api_lua.hpp index 83130ec2..17eebcac 100644 --- a/src/logic/scripting/lua/api_lua.hpp +++ b/src/logic/scripting/lua/api_lua.hpp @@ -10,6 +10,7 @@ extern const luaL_Reg audiolib []; extern const luaL_Reg blocklib []; extern const luaL_Reg consolelib []; extern const luaL_Reg corelib []; +extern const luaL_Reg entitylib []; extern const luaL_Reg filelib []; extern const luaL_Reg guilib []; extern const luaL_Reg hudlib []; diff --git a/src/logic/scripting/lua/libentity.cpp b/src/logic/scripting/lua/libentity.cpp new file mode 100644 index 00000000..5ab0181b --- /dev/null +++ b/src/logic/scripting/lua/libentity.cpp @@ -0,0 +1,26 @@ +#include "api_lua.hpp" + +#include "../../LevelController.hpp" +#include "../../../world/Level.hpp" +#include "../../../objects/Player.hpp" +#include "../../../objects/Entities.hpp" +#include "../../../physics/Hitbox.hpp" +#include "../../../window/Camera.hpp" +#include "../../../frontend/hud.hpp" + +namespace scripting { + extern Hud* hud; +} +using namespace scripting; + +static int l_test(lua::State* L) { + auto level = controller->getLevel(); + auto player = hud->getPlayer(); + level->entities->drop(player->camera->position, player->camera->front*8.0f+glm::vec3(0, 2, 0)+player->hitbox->velocity); + return 0; +} + +const luaL_Reg entitylib [] = { + {"test", lua::wrap}, + {NULL, NULL} +}; diff --git a/src/logic/scripting/lua/lua_engine.cpp b/src/logic/scripting/lua/lua_engine.cpp index a64216a6..be8d2c1d 100644 --- a/src/logic/scripting/lua/lua_engine.cpp +++ b/src/logic/scripting/lua/lua_engine.cpp @@ -31,6 +31,7 @@ static void create_libs(lua::State* L) { openlib(L, "block", blocklib); openlib(L, "console", consolelib); openlib(L, "core", corelib); + openlib(L, "entity", entitylib); openlib(L, "file", filelib); openlib(L, "gui", guilib); openlib(L, "input", inputlib);