summaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_mapgen.cpp121
-rw-r--r--src/script/lua_api/l_object.cpp29
-rw-r--r--src/script/lua_api/l_settings.cpp78
3 files changed, 115 insertions, 113 deletions
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index 12a497b1e..eb3d49a5e 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -482,9 +482,7 @@ int ModApiMapgen::l_get_biome_id(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
- const char *biome_str = lua_tostring(L, 1);
- if (!biome_str)
- return 0;
+ const char *biome_str = luaL_checkstring(L, 1);
const BiomeManager *bmgr = getServer(L)->getEmergeManager()->getBiomeManager();
if (!bmgr)
@@ -527,30 +525,12 @@ int ModApiMapgen::l_get_heat(lua_State *L)
v3s16 pos = read_v3s16(L, 1);
- NoiseParams np_heat;
- NoiseParams np_heat_blend;
-
- MapSettingsManager *settingsmgr =
- getServer(L)->getEmergeManager()->map_settings_mgr;
+ const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen();
- if (!settingsmgr->getMapSettingNoiseParams("mg_biome_np_heat",
- &np_heat) ||
- !settingsmgr->getMapSettingNoiseParams("mg_biome_np_heat_blend",
- &np_heat_blend))
- return 0;
-
- std::string value;
- if (!settingsmgr->getMapSetting("seed", &value))
- return 0;
- std::istringstream ss(value);
- u64 seed;
- ss >> seed;
-
- const BiomeManager *bmgr = getServer(L)->getEmergeManager()->getBiomeManager();
- if (!bmgr)
+ if (!biomegen || biomegen->getType() != BIOMEGEN_ORIGINAL)
return 0;
- float heat = bmgr->getHeatAtPosOriginal(pos, np_heat, np_heat_blend, seed);
+ float heat = ((BiomeGenOriginal*) biomegen)->calcHeatAtPoint(pos);
lua_pushnumber(L, heat);
@@ -566,31 +546,12 @@ int ModApiMapgen::l_get_humidity(lua_State *L)
v3s16 pos = read_v3s16(L, 1);
- NoiseParams np_humidity;
- NoiseParams np_humidity_blend;
-
- MapSettingsManager *settingsmgr =
- getServer(L)->getEmergeManager()->map_settings_mgr;
+ const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen();
- if (!settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity",
- &np_humidity) ||
- !settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity_blend",
- &np_humidity_blend))
+ if (!biomegen || biomegen->getType() != BIOMEGEN_ORIGINAL)
return 0;
- std::string value;
- if (!settingsmgr->getMapSetting("seed", &value))
- return 0;
- std::istringstream ss(value);
- u64 seed;
- ss >> seed;
-
- const BiomeManager *bmgr = getServer(L)->getEmergeManager()->getBiomeManager();
- if (!bmgr)
- return 0;
-
- float humidity = bmgr->getHumidityAtPosOriginal(pos, np_humidity,
- np_humidity_blend, seed);
+ float humidity = ((BiomeGenOriginal*) biomegen)->calcHumidityAtPoint(pos);
lua_pushnumber(L, humidity);
@@ -606,45 +567,11 @@ int ModApiMapgen::l_get_biome_data(lua_State *L)
v3s16 pos = read_v3s16(L, 1);
- NoiseParams np_heat;
- NoiseParams np_heat_blend;
- NoiseParams np_humidity;
- NoiseParams np_humidity_blend;
-
- MapSettingsManager *settingsmgr =
- getServer(L)->getEmergeManager()->map_settings_mgr;
-
- if (!settingsmgr->getMapSettingNoiseParams("mg_biome_np_heat",
- &np_heat) ||
- !settingsmgr->getMapSettingNoiseParams("mg_biome_np_heat_blend",
- &np_heat_blend) ||
- !settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity",
- &np_humidity) ||
- !settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity_blend",
- &np_humidity_blend))
+ const BiomeGen *biomegen = getServer(L)->getEmergeManager()->getBiomeGen();
+ if (!biomegen)
return 0;
- std::string value;
- if (!settingsmgr->getMapSetting("seed", &value))
- return 0;
- std::istringstream ss(value);
- u64 seed;
- ss >> seed;
-
- const BiomeManager *bmgr = getServer(L)->getEmergeManager()->getBiomeManager();
- if (!bmgr)
- return 0;
-
- float heat = bmgr->getHeatAtPosOriginal(pos, np_heat, np_heat_blend, seed);
- if (!heat)
- return 0;
-
- float humidity = bmgr->getHumidityAtPosOriginal(pos, np_humidity,
- np_humidity_blend, seed);
- if (!humidity)
- return 0;
-
- const Biome *biome = bmgr->getBiomeFromNoiseOriginal(heat, humidity, pos);
+ const Biome *biome = biomegen->calcBiomeAtPoint(pos);
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
return 0;
@@ -653,11 +580,16 @@ int ModApiMapgen::l_get_biome_data(lua_State *L)
lua_pushinteger(L, biome->index);
lua_setfield(L, -2, "biome");
- lua_pushnumber(L, heat);
- lua_setfield(L, -2, "heat");
+ if (biomegen->getType() == BIOMEGEN_ORIGINAL) {
+ float heat = ((BiomeGenOriginal*) biomegen)->calcHeatAtPoint(pos);
+ float humidity = ((BiomeGenOriginal*) biomegen)->calcHumidityAtPoint(pos);
- lua_pushnumber(L, humidity);
- lua_setfield(L, -2, "humidity");
+ lua_pushnumber(L, heat);
+ lua_setfield(L, -2, "heat");
+
+ lua_pushnumber(L, humidity);
+ lua_setfield(L, -2, "humidity");
+ }
return 1;
}
@@ -1493,9 +1425,12 @@ int ModApiMapgen::l_generate_ores(lua_State *L)
NO_MAP_LOCK_REQUIRED;
EmergeManager *emerge = getServer(L)->getEmergeManager();
+ if (!emerge || !emerge->mgparams)
+ return 0;
Mapgen mg;
- mg.seed = emerge->mgparams->seed;
+ // Intentionally truncates to s32, see Mapgen::Mapgen()
+ mg.seed = (s32)emerge->mgparams->seed;
mg.vm = LuaVoxelManip::checkobject(L, 1)->vm;
mg.ndef = getServer(L)->getNodeDefManager();
@@ -1519,9 +1454,12 @@ int ModApiMapgen::l_generate_decorations(lua_State *L)
NO_MAP_LOCK_REQUIRED;
EmergeManager *emerge = getServer(L)->getEmergeManager();
+ if (!emerge || !emerge->mgparams)
+ return 0;
Mapgen mg;
- mg.seed = emerge->mgparams->seed;
+ // Intentionally truncates to s32, see Mapgen::Mapgen()
+ mg.seed = (s32)emerge->mgparams->seed;
mg.vm = LuaVoxelManip::checkobject(L, 1)->vm;
mg.ndef = getServer(L)->getNodeDefManager();
@@ -1734,11 +1672,10 @@ int ModApiMapgen::l_serialize_schematic(lua_State *L)
std::ostringstream os(std::ios_base::binary);
switch (schem_format) {
case SCHEM_FMT_MTS:
- schem->serializeToMts(&os, schem->m_nodenames);
+ schem->serializeToMts(&os);
break;
case SCHEM_FMT_LUA:
- schem->serializeToLua(&os, schem->m_nodenames,
- use_comments, indent_spaces);
+ schem->serializeToLua(&os, use_comments, indent_spaces);
break;
default:
return 0;
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 07aa3f7c9..8ae99b929 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -737,6 +737,18 @@ int ObjectRef::l_set_nametag_attributes(lua_State *L)
}
lua_pop(L, 1);
+ lua_getfield(L, -1, "bgcolor");
+ if (!lua_isnil(L, -1)) {
+ if (lua_toboolean(L, -1)) {
+ video::SColor color;
+ if (read_color(L, -1, &color))
+ prop->nametag_bgcolor = color;
+ } else {
+ prop->nametag_bgcolor = nullopt;
+ }
+ }
+ lua_pop(L, 1);
+
std::string nametag = getstringfield_default(L, 2, "text", "");
prop->nametag = nametag;
@@ -758,13 +770,24 @@ int ObjectRef::l_get_nametag_attributes(lua_State *L)
if (!prop)
return 0;
- video::SColor color = prop->nametag_color;
-
lua_newtable(L);
- push_ARGB8(L, color);
+
+ push_ARGB8(L, prop->nametag_color);
lua_setfield(L, -2, "color");
+
+ if (prop->nametag_bgcolor) {
+ push_ARGB8(L, prop->nametag_bgcolor.value());
+ lua_setfield(L, -2, "bgcolor");
+ } else {
+ lua_pushboolean(L, false);
+ lua_setfield(L, -2, "bgcolor");
+ }
+
lua_pushstring(L, prop->nametag.c_str());
lua_setfield(L, -2, "text");
+
+
+
return 1;
}
diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp
index bcbaf15fa..a82073ed4 100644
--- a/src/script/lua_api/l_settings.cpp
+++ b/src/script/lua_api/l_settings.cpp
@@ -20,18 +20,43 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_settings.h"
#include "lua_api/l_internal.h"
#include "cpp_api/s_security.h"
+#include "threading/mutex_auto_lock.h"
#include "util/string.h" // FlagDesc
#include "settings.h"
#include "noise.h"
#include "log.h"
-#define SET_SECURITY_CHECK(L, name) \
- if (o->m_settings == g_settings && ScriptApiSecurity::isSecure(L) && \
- name.compare(0, 7, "secure.") == 0) { \
- throw LuaError("Attempt to set secure setting."); \
+/* This protects:
+ * 'secure.*' settings from being set
+ * some mapgen settings from being set
+ * (not security-criticial, just to avoid messing up user configs)
+ */
+#define CHECK_SETTING_SECURITY(L, name) \
+ if (o->m_settings == g_settings) { \
+ if (checkSettingSecurity(L, name) == -1) \
+ return 0; \
}
+static inline int checkSettingSecurity(lua_State* L, const std::string &name)
+{
+ if (ScriptApiSecurity::isSecure(L) && name.compare(0, 7, "secure.") == 0)
+ throw LuaError("Attempt to set secure setting.");
+
+ bool is_mainmenu = false;
+#ifndef SERVER
+ is_mainmenu = ModApiBase::getGuiEngine(L) != nullptr;
+#endif
+ if (!is_mainmenu && (name == "mg_name" || name == "mg_flags")) {
+ errorstream << "Tried to set global setting " << name << ", ignoring. "
+ "minetest.set_mapgen_setting() should be used instead." << std::endl;
+ infostream << script_get_backtrace(L) << std::endl;
+ return -1;
+ }
+
+ return 0;
+}
+
LuaSettings::LuaSettings(Settings *settings, const std::string &filename) :
m_settings(settings),
m_filename(filename)
@@ -129,6 +154,7 @@ int LuaSettings::l_get_np_group(lua_State *L)
return 1;
}
+// get_flags(self, key) -> table or nil
int LuaSettings::l_get_flags(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
@@ -161,7 +187,7 @@ int LuaSettings::l_set(lua_State* L)
std::string key = std::string(luaL_checkstring(L, 2));
const char* value = luaL_checkstring(L, 3);
- SET_SECURITY_CHECK(L, key);
+ CHECK_SETTING_SECURITY(L, key);
if (!o->m_settings->set(key, value))
throw LuaError("Invalid sequence found in setting parameters");
@@ -178,14 +204,14 @@ int LuaSettings::l_set_bool(lua_State* L)
std::string key = std::string(luaL_checkstring(L, 2));
bool value = readParam<bool>(L, 3);
- SET_SECURITY_CHECK(L, key);
+ CHECK_SETTING_SECURITY(L, key);
o->m_settings->setBool(key, value);
- return 1;
+ return 0;
}
-// set(self, key, value)
+// set_np_group(self, key, value)
int LuaSettings::l_set_np_group(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
@@ -195,7 +221,7 @@ int LuaSettings::l_set_np_group(lua_State *L)
NoiseParams value;
read_noiseparams(L, 3, &value);
- SET_SECURITY_CHECK(L, key);
+ CHECK_SETTING_SECURITY(L, key);
o->m_settings->setNoiseParams(key, value);
@@ -210,7 +236,7 @@ int LuaSettings::l_remove(lua_State* L)
std::string key = std::string(luaL_checkstring(L, 2));
- SET_SECURITY_CHECK(L, key);
+ CHECK_SETTING_SECURITY(L, key);
bool success = o->m_settings->remove(key);
lua_pushboolean(L, success);
@@ -253,20 +279,36 @@ int LuaSettings::l_write(lua_State* L)
return 1;
}
-// to_table(self) -> {[key1]=value1,...}
-int LuaSettings::l_to_table(lua_State* L)
+static void push_settings_table(lua_State *L, const Settings *settings)
{
- NO_MAP_LOCK_REQUIRED;
- LuaSettings* o = checkobject(L, 1);
-
- std::vector<std::string> keys = o->m_settings->getNames();
-
+ std::vector<std::string> keys = settings->getNames();
lua_newtable(L);
for (const std::string &key : keys) {
- lua_pushstring(L, o->m_settings->get(key).c_str());
+ std::string value;
+ Settings *group = nullptr;
+
+ if (settings->getNoEx(key, value)) {
+ lua_pushstring(L, value.c_str());
+ } else if (settings->getGroupNoEx(key, group)) {
+ // Recursively push tables
+ push_settings_table(L, group);
+ } else {
+ // Impossible case (multithreading) due to MutexAutoLock
+ continue;
+ }
+
lua_setfield(L, -2, key.c_str());
}
+}
+
+// to_table(self) -> {[key1]=value1,...}
+int LuaSettings::l_to_table(lua_State* L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ LuaSettings* o = checkobject(L, 1);
+ MutexAutoLock(o->m_settings->m_mutex);
+ push_settings_table(L, o->m_settings);
return 1;
}