aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_env.cpp31
-rw-r--r--src/script/cpp_api/s_env.h2
-rw-r--r--src/script/lua_api/l_mapgen.cpp48
-rw-r--r--src/script/lua_api/l_mapgen.h4
4 files changed, 39 insertions, 46 deletions
diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp
index 916c562fb..c171bbf02 100644
--- a/src/script/cpp_api/s_env.cpp
+++ b/src/script/cpp_api/s_env.cpp
@@ -79,37 +79,6 @@ void ScriptApiEnv::player_event(ServerActiveObject* player, std::string type)
}
}
-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)
{
SCRIPTAPI_PRECHECKHEADER
diff --git a/src/script/cpp_api/s_env.h b/src/script/cpp_api/s_env.h
index 33bd81ab3..180cfabd0 100644
--- a/src/script/cpp_api/s_env.h
+++ b/src/script/cpp_api/s_env.h
@@ -34,8 +34,6 @@ public:
void environment_Step(float dtime);
// After generating a piece of map
void environment_OnGenerated(v3s16 minp, v3s16 maxp,u32 blockseed);
- // After initializing mapgens
- void environment_OnMapgenInit(MapgenParams *mgparams);
//called on player event
void player_event(ServerActiveObject* player, std::string type);
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index cccbba5a8..b7d7d096e 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -325,6 +325,31 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L)
return 0;
}
+int ModApiMapgen::l_get_mapgen_params(lua_State *L)
+{
+ MapgenParams *params = &getServer(L)->getEmergeManager()->params;
+
+ lua_newtable(L);
+
+ lua_pushstring(L, params->mg_name.c_str());
+ lua_setfield(L, -2, "mgname");
+
+ lua_pushinteger(L, params->seed);
+ lua_setfield(L, -2, "seed");
+
+ lua_pushinteger(L, params->water_level);
+ lua_setfield(L, -2, "water_level");
+
+ lua_pushinteger(L, params->chunksize);
+ lua_setfield(L, -2, "chunksize");
+
+ std::string flagstr = writeFlagString(params->flags, flagdesc_mapgen, (u32)-1);
+ lua_pushstring(L, flagstr.c_str());
+ lua_setfield(L, -2, "flags");
+
+ return 1;
+}
+
// set_mapgen_params(params)
// set mapgen parameters
int ModApiMapgen::l_set_mapgen_params(lua_State *L)
@@ -332,38 +357,34 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L)
if (!lua_istable(L, 1))
return 0;
- EmergeManager *emerge = getServer(L)->getEmergeManager();
- assert(emerge);
-
- std::string flagstr;
+ MapgenParams *params = &getServer(L)->getEmergeManager()->params;
u32 flags = 0, flagmask = 0;
lua_getfield(L, 1, "mgname");
if (lua_isstring(L, -1)) {
- emerge->params.mg_name = std::string(lua_tostring(L, -1));
- delete emerge->params.sparams;
- emerge->params.sparams = NULL;
+ params->mg_name = lua_tostring(L, -1);
+ delete params->sparams;
+ params->sparams = NULL;
}
lua_getfield(L, 1, "seed");
if (lua_isnumber(L, -1))
- emerge->params.seed = lua_tointeger(L, -1);
+ params->seed = lua_tointeger(L, -1);
lua_getfield(L, 1, "water_level");
if (lua_isnumber(L, -1))
- emerge->params.water_level = lua_tointeger(L, -1);
+ params->water_level = lua_tointeger(L, -1);
lua_getfield(L, 1, "flagmask");
if (lua_isstring(L, -1)) {
- flagstr = lua_tostring(L, -1);
- emerge->params.flags &= ~readFlagString(flagstr, flagdesc_mapgen, NULL);
+ params->flags &= ~readFlagString(lua_tostring(L, -1), flagdesc_mapgen, NULL);
errorstream << "set_mapgen_params(): flagmask field is deprecated, "
"see lua_api.txt" << std::endl;
}
if (getflagsfield(L, 1, "flags", flagdesc_mapgen, &flags, &flagmask)) {
- emerge->params.flags &= ~flagmask;
- emerge->params.flags |= flags;
+ params->flags &= ~flagmask;
+ params->flags |= flags;
}
return 0;
@@ -818,6 +839,7 @@ void ModApiMapgen::Initialize(lua_State *L, int top)
{
API_FCT(get_mapgen_object);
+ API_FCT(get_mapgen_params);
API_FCT(set_mapgen_params);
API_FCT(set_noiseparams);
API_FCT(set_gen_notify);
diff --git a/src/script/lua_api/l_mapgen.h b/src/script/lua_api/l_mapgen.h
index 247043a01..e98838470 100644
--- a/src/script/lua_api/l_mapgen.h
+++ b/src/script/lua_api/l_mapgen.h
@@ -33,6 +33,10 @@ private:
// returns the requested object used during map generation
static int l_get_mapgen_object(lua_State *L);
+ // get_mapgen_params()
+ // returns the currently active map generation parameter set
+ static int l_get_mapgen_params(lua_State *L);
+
// set_mapgen_params(params)
// set mapgen parameters
static int l_set_mapgen_params(lua_State *L);