Log node/ore name when detecting deprecated fields (#14794)

This commit is contained in:
1F616EMO~nya 2024-07-01 23:26:15 +08:00 committed by GitHub
parent 3958c19f83
commit 321b217feb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 11 deletions

@ -760,7 +760,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
f.setDefaultAlphaMode();
warn_if_field_exists(L, index, "alpha",
warn_if_field_exists(L, index, "alpha", "node " + f.name,
"Obsolete, only limited compatibility provided; "
"replaced by \"use_texture_alpha\"");
if (getintfield_default(L, index, "alpha", 255) != 255)
@ -768,7 +768,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
lua_getfield(L, index, "use_texture_alpha");
if (lua_isboolean(L, -1)) {
warn_if_field_exists(L, index, "use_texture_alpha",
warn_if_field_exists(L, index, "use_texture_alpha", "node " + f.name,
"Boolean values are deprecated; use the new choices");
if (lua_toboolean(L, -1))
f.alpha = (f.drawtype == NDT_NORMAL) ? ALPHAMODE_CLIP : ALPHAMODE_BLEND;
@ -1315,13 +1315,16 @@ void pushnode(lua_State *L, const MapNode &n)
}
/******************************************************************************/
void warn_if_field_exists(lua_State *L, int table,
const char *name, const std::string &message)
void warn_if_field_exists(lua_State *L, int table, const char *fieldname,
std::string_view name, std::string_view message)
{
lua_getfield(L, table, name);
lua_getfield(L, table, fieldname);
if (!lua_isnil(L, -1)) {
warningstream << "Field \"" << name << "\": "
<< message << std::endl;
warningstream << "Field \"" << fieldname << "\"";
if (!name.empty()) {
warningstream << " on " << name;
}
warningstream << ": " << message << std::endl;
infostream << script_get_backtrace(L) << std::endl;
}
lua_pop(L, 1);

@ -120,7 +120,8 @@ void push_aabb3f_vector (lua_State *L, const std::vector<aabb3f>
void warn_if_field_exists(lua_State *L, int table,
const char *fieldname,
const std::string &message);
std::string_view name,
std::string_view message);
size_t write_array_slice_float(lua_State *L, int table_index, float *data,
v3u16 data_size, v3u16 slice_offset, v3u16 slice_size);

@ -1354,7 +1354,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
ore->flags = 0;
//// Get noise_threshold
warn_if_field_exists(L, index, "noise_threshhold",
warn_if_field_exists(L, index, "noise_threshhold", "ore " + ore->name,
"Deprecated: new name is \"noise_threshold\".");
float nthresh;
@ -1364,9 +1364,9 @@ int ModApiMapgen::l_register_ore(lua_State *L)
ore->nthresh = nthresh;
//// Get y_min/y_max
warn_if_field_exists(L, index, "height_min",
warn_if_field_exists(L, index, "height_min", "ore " + ore->name,
"Deprecated: new name is \"y_min\".");
warn_if_field_exists(L, index, "height_max",
warn_if_field_exists(L, index, "height_max", "ore " + ore->name,
"Deprecated: new name is \"y_max\".");
int ymin, ymax;