aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_env.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2013-06-27 17:06:52 -0400
committerkwolekr <kwolekr@minetest.net>2013-06-27 22:35:35 -0400
commit2e292b67a0a02b045969034c06aaf92b42a83a81 (patch)
tree499310d109cbd737633eb99a245e0054a0c458d7 /src/script/cpp_api/s_env.cpp
parent18882a4d2603488bdfb5a519a8bedf300b154940 (diff)
downloadminetest-2e292b67a0a02b045969034c06aaf92b42a83a81.tar.gz
minetest-2e292b67a0a02b045969034c06aaf92b42a83a81.tar.bz2
minetest-2e292b67a0a02b045969034c06aaf92b42a83a81.zip
Add Lua on_mapgen_init callback, and minetest.set_mapgen_params API
Diffstat (limited to 'src/script/cpp_api/s_env.cpp')
-rw-r--r--src/script/cpp_api/s_env.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp
index 334d196bc..632b28f45 100644
--- a/src/script/cpp_api/s_env.cpp
+++ b/src/script/cpp_api/s_env.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common/c_converter.h"
#include "log.h"
#include "environment.h"
+#include "mapgen.h"
#include "lua_api/l_env.h"
extern "C" {
@@ -55,6 +56,33 @@ void ScriptApiEnv::environment_Step(float dtime)
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
}
+void ScriptApiEnv::environment_OnMapgenInit(MapgenParams *mgparams)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get minetest.registered_on_mapgen_inits
+ lua_getglobal(L, "minetest");
+ 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");
+
+ std::string flagstr = writeFlagString(mgparams->flags, flagdesc_mapgen);
+ lua_pushstring(L, flagstr.c_str());
+ lua_setfield(L, -2, "flags");
+
+ runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
+}
+
void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
{
SCRIPTAPI_PRECHECKHEADER