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(); f.setDefaultAlphaMode();
warn_if_field_exists(L, index, "alpha", warn_if_field_exists(L, index, "alpha", "node " + f.name,
"Obsolete, only limited compatibility provided; " "Obsolete, only limited compatibility provided; "
"replaced by \"use_texture_alpha\""); "replaced by \"use_texture_alpha\"");
if (getintfield_default(L, index, "alpha", 255) != 255) 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"); lua_getfield(L, index, "use_texture_alpha");
if (lua_isboolean(L, -1)) { 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"); "Boolean values are deprecated; use the new choices");
if (lua_toboolean(L, -1)) if (lua_toboolean(L, -1))
f.alpha = (f.drawtype == NDT_NORMAL) ? ALPHAMODE_CLIP : ALPHAMODE_BLEND; 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, void warn_if_field_exists(lua_State *L, int table, const char *fieldname,
const char *name, const std::string &message) std::string_view name, std::string_view message)
{ {
lua_getfield(L, table, name); lua_getfield(L, table, fieldname);
if (!lua_isnil(L, -1)) { if (!lua_isnil(L, -1)) {
warningstream << "Field \"" << name << "\": " warningstream << "Field \"" << fieldname << "\"";
<< message << std::endl; if (!name.empty()) {
warningstream << " on " << name;
}
warningstream << ": " << message << std::endl;
infostream << script_get_backtrace(L) << std::endl; infostream << script_get_backtrace(L) << std::endl;
} }
lua_pop(L, 1); 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, void warn_if_field_exists(lua_State *L, int table,
const char *fieldname, 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, size_t write_array_slice_float(lua_State *L, int table_index, float *data,
v3u16 data_size, v3u16 slice_offset, v3u16 slice_size); v3u16 data_size, v3u16 slice_offset, v3u16 slice_size);

@ -1354,7 +1354,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
ore->flags = 0; ore->flags = 0;
//// Get noise_threshold //// 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\"."); "Deprecated: new name is \"noise_threshold\".");
float nthresh; float nthresh;
@ -1364,9 +1364,9 @@ int ModApiMapgen::l_register_ore(lua_State *L)
ore->nthresh = nthresh; ore->nthresh = nthresh;
//// Get y_min/y_max //// 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\"."); "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\"."); "Deprecated: new name is \"y_max\".");
int ymin, ymax; int ymin, ymax;