X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fscript%2Fcpp_api%2Fs_env.cpp;h=916c562fbf2ca1b280b31abef6636bace931a072;hb=8fe1d3fc2e4564fd30658c7008ef7a0e6161e2d3;hp=334d196bc68c2c49875cc22960179781dca9d69d;hpb=ab433775777c4f5055bcf4d2a1cffc506c4f9961;p=minetest.git diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp index 334d196bc..916c562fb 100644 --- a/src/script/cpp_api/s_env.cpp +++ b/src/script/cpp_api/s_env.cpp @@ -18,28 +18,27 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "cpp_api/s_env.h" +#include "cpp_api/s_internal.h" #include "common/c_converter.h" #include "log.h" #include "environment.h" +#include "mapgen.h" #include "lua_api/l_env.h" - -extern "C" { -#include "lauxlib.h" -} +#include "server.h" void ScriptApiEnv::environment_OnGenerated(v3s16 minp, v3s16 maxp, u32 blockseed) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_generateds - lua_getglobal(L, "minetest"); + // Get core.registered_on_generateds + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_generateds"); // Call callbacks push_v3s16(L, minp); push_v3s16(L, maxp); lua_pushnumber(L, blockseed); - runCallbacks(3, RUN_CALLBACKS_MODE_FIRST); + script_run_callbacks(L, 3, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiEnv::environment_Step(float dtime) @@ -47,12 +46,68 @@ void ScriptApiEnv::environment_Step(float dtime) SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_environment_step"<setAsyncFatalError(e.what()); + } +} + +void ScriptApiEnv::player_event(ServerActiveObject* player, std::string type) +{ + SCRIPTAPI_PRECHECKHEADER + + if (player == NULL) + return; + + // Get minetest.registered_playerevents + lua_getglobal(L, "minetest"); + lua_getfield(L, -1, "registered_playerevents"); + + // Call callbacks + objectrefGetOrCreate(L, player); // player + lua_pushstring(L,type.c_str()); // event type + try { + script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_FIRST); + } catch (LuaError &e) { + getServer()->setAsyncFatalError(e.what()); + } +} + +void ScriptApiEnv::environment_OnMapgenInit(MapgenParams *mgparams) +{ + SCRIPTAPI_PRECHECKHEADER + + // Get core.registered_on_mapgen_inits + lua_getglobal(L, "core"); + lua_getfield(L, -1, "registered_on_mapgen_inits"); + + // Call callbacks + lua_newtable(L); + + lua_pushstring(L, mgparams->mg_name.c_str()); + lua_setfield(L, -2, "mgname"); + + lua_pushinteger(L, mgparams->seed); + lua_setfield(L, -2, "seed"); + + lua_pushinteger(L, mgparams->water_level); + lua_setfield(L, -2, "water_level"); + + lua_pushinteger(L, mgparams->chunksize); + lua_setfield(L, -2, "chunksize"); + + std::string flagstr = writeFlagString(mgparams->flags, + flagdesc_mapgen, (u32)-1); + lua_pushstring(L, flagstr.c_str()); + lua_setfield(L, -2, "flags"); + + script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env) @@ -65,8 +120,8 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env) Add ActiveBlockModifiers to environment */ - // Get minetest.registered_abms - lua_getglobal(L, "minetest"); + // Get core.registered_abms + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_abms"); luaL_checktype(L, -1, LUA_TTABLE); int registered_abms = lua_gettop(L);