summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp26
-rw-r--r--src/script/common/helper.cpp24
-rw-r--r--src/script/common/helper.h3
-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
6 files changed, 157 insertions, 124 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index ecab7baa1..eca0c89d1 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -119,6 +119,8 @@ void read_item_definition(lua_State* L, int index,
// "" = no prediction
getstringfield(L, index, "node_placement_prediction",
def.node_placement_prediction);
+
+ getintfield(L, index, "place_param2", def.place_param2);
}
/******************************************************************************/
@@ -140,8 +142,10 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i)
lua_setfield(L, -2, "name");
lua_pushstring(L, i.description.c_str());
lua_setfield(L, -2, "description");
- lua_pushstring(L, i.short_description.c_str());
- lua_setfield(L, -2, "short_description");
+ if (!i.short_description.empty()) {
+ lua_pushstring(L, i.short_description.c_str());
+ lua_setfield(L, -2, "short_description");
+ }
lua_pushstring(L, type.c_str());
lua_setfield(L, -2, "type");
lua_pushstring(L, i.inventory_image.c_str());
@@ -310,6 +314,17 @@ void read_object_properties(lua_State *L, int index,
prop->nametag_color = color;
}
lua_pop(L, 1);
+ lua_getfield(L, -1, "nametag_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);
lua_getfield(L, -1, "automatic_face_movement_max_rotation_per_sec");
if (lua_isnumber(L, -1)) {
@@ -401,6 +416,13 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
lua_setfield(L, -2, "nametag");
push_ARGB8(L, prop->nametag_color);
lua_setfield(L, -2, "nametag_color");
+ if (prop->nametag_bgcolor) {
+ push_ARGB8(L, prop->nametag_bgcolor.value());
+ lua_setfield(L, -2, "nametag_bgcolor");
+ } else {
+ lua_pushboolean(L, false);
+ lua_setfield(L, -2, "nametag_bgcolor");
+ }
lua_pushnumber(L, prop->automatic_face_movement_max_rotation_per_sec);
lua_setfield(L, -2, "automatic_face_movement_max_rotation_per_sec");
lua_pushlstring(L, prop->infotext.c_str(), prop->infotext.size());
diff --git a/src/script/common/helper.cpp b/src/script/common/helper.cpp
index 488144790..fbf24e1b7 100644
--- a/src/script/common/helper.cpp
+++ b/src/script/common/helper.cpp
@@ -50,22 +50,26 @@ bool LuaHelper::isNaN(lua_State *L, int idx)
/*
* Read template functions
*/
-template <> bool LuaHelper::readParam(lua_State *L, int index)
+template <>
+bool LuaHelper::readParam(lua_State *L, int index)
{
return lua_toboolean(L, index) != 0;
}
-template <> s16 LuaHelper::readParam(lua_State *L, int index)
+template <>
+s16 LuaHelper::readParam(lua_State *L, int index)
{
return lua_tonumber(L, index);
}
-template <> int LuaHelper::readParam(lua_State *L, int index)
+template <>
+int LuaHelper::readParam(lua_State *L, int index)
{
return luaL_checkint(L, index);
}
-template <> float LuaHelper::readParam(lua_State *L, int index)
+template <>
+float LuaHelper::readParam(lua_State *L, int index)
{
if (isNaN(L, index))
throw LuaError("NaN value is not allowed.");
@@ -73,7 +77,8 @@ template <> float LuaHelper::readParam(lua_State *L, int index)
return (float)luaL_checknumber(L, index);
}
-template <> v2s16 LuaHelper::readParam(lua_State *L, int index)
+template <>
+v2s16 LuaHelper::readParam(lua_State *L, int index)
{
v2s16 p;
CHECK_POS_TAB(index);
@@ -88,7 +93,8 @@ template <> v2s16 LuaHelper::readParam(lua_State *L, int index)
return p;
}
-template <> v2f LuaHelper::readParam(lua_State *L, int index)
+template <>
+v2f LuaHelper::readParam(lua_State *L, int index)
{
v2f p;
CHECK_POS_TAB(index);
@@ -103,7 +109,8 @@ template <> v2f LuaHelper::readParam(lua_State *L, int index)
return p;
}
-template <> v3f LuaHelper::readParam(lua_State *L, int index)
+template <>
+v3f LuaHelper::readParam(lua_State *L, int index)
{
v3f p;
CHECK_POS_TAB(index);
@@ -122,7 +129,8 @@ template <> v3f LuaHelper::readParam(lua_State *L, int index)
return p;
}
-template <> std::string LuaHelper::readParam(lua_State *L, int index)
+template <>
+std::string LuaHelper::readParam(lua_State *L, int index)
{
size_t length;
std::string result;
diff --git a/src/script/common/helper.h b/src/script/common/helper.h
index 7a794dc9b..6491e73cf 100644
--- a/src/script/common/helper.h
+++ b/src/script/common/helper.h
@@ -38,7 +38,8 @@ protected:
* @param index Lua Index to read
* @return read value from Lua
*/
- template <typename T> static T readParam(lua_State *L, int index);
+ template <typename T>
+ static T readParam(lua_State *L, int index);
/**
* Read a value using a template type T from Lua State L and index
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;
}