From 37f922b500a8953ef48b755f6befe3705b555c84 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Fri, 11 Jul 2025 17:24:15 +0200 Subject: [PATCH] Improve some deprecation warnings --- src/script/common/c_content.cpp | 42 +++++++++-------------- src/script/common/c_converter.h | 3 -- src/script/lua_api/l_mapgen.cpp | 59 ++++++++++++++++++++------------- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 91aa5b405..73842bc9c 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -637,9 +637,10 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype, bool special) // name="default_lava.png" tiledef.name.clear(); getstringfield(L, index, "name", tiledef.name); - warn_if_field_exists(L, index, "image", "TileDef", - "Deprecated: new name is \"name\"."); - getstringfield(L, index, "image", tiledef.name); + if (getstringfield(L, index, "image", tiledef.name)) { + log_deprecated(L, "Field \"image\" on TileDef is deprecated, " + "use \"name\" instead.", 2); + } tiledef.backface_culling = getboolfield_default( L, index, "backface_culling", default_culling); @@ -797,16 +798,21 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) f.setDefaultAlphaMode(); - 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) - f.alpha = ALPHAMODE_BLEND; + { + int alpha; + if (getintfield(L, index, "alpha", alpha)) { + log_deprecated(L, "Field \"alpha\" on node " + f.name + " is obsolete, " + "only limited compatibility provided; " + "replaced by \"use_texture_alpha\".", 2); + if (alpha != 255) + f.alpha = ALPHAMODE_BLEND; + } + } lua_getfield(L, index, "use_texture_alpha"); if (lua_isboolean(L, -1)) { - warn_if_field_exists(L, index, "use_texture_alpha", "node " + f.name, - "Boolean values are deprecated; use the new choices"); + log_deprecated(L, "Field \"use_texture_alpha\" on node " + f.name + ": " + "Boolean values are deprecated; use the new choices instead.", 2); if (lua_toboolean(L, -1)) f.alpha = (f.drawtype == NDT_NORMAL) ? ALPHAMODE_CLIP : ALPHAMODE_BLEND; } else if (check_field_or_nil(L, -1, LUA_TSTRING, "use_texture_alpha")) { @@ -1360,22 +1366,6 @@ void pushnode(lua_State *L, const MapNode &n) lua_call(L, 3, 1); } -/******************************************************************************/ -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, fieldname); - if (!lua_isnil(L, -1)) { - warningstream << "Field \"" << fieldname << "\""; - if (!name.empty()) { - warningstream << " on " << name; - } - warningstream << ": " << message << std::endl; - infostream << script_get_backtrace(L) << std::endl; - } - lua_pop(L, 1); -} - /******************************************************************************/ int getenumfield(lua_State *L, int table, const char *fieldname, const EnumString *spec, int default_) diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 2744fa0b5..fe3caa3ad 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -121,9 +121,6 @@ void push_v2f(lua_State *L, v2f p); void push_aabb3f_vector(lua_State *L, const std::vector &boxes, f32 divisor = 1.0f); -void warn_if_field_exists(lua_State *L, int table, const char *fieldname, - 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); diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 16fa1760e..9e84241c8 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -1365,30 +1365,43 @@ int ModApiMapgen::l_register_ore(lua_State *L) ore->flags = 0; //// Get noise_threshold - warn_if_field_exists(L, index, "noise_threshhold", "ore " + ore->name, - "Deprecated: new name is \"noise_threshold\"."); - - float nthresh; - if (!getfloatfield(L, index, "noise_threshold", nthresh) && - !getfloatfield(L, index, "noise_threshhold", nthresh)) - nthresh = 0; - ore->nthresh = nthresh; + { + float nthresh; + if (getfloatfield(L, index, "noise_threshold", nthresh)) { + } else if (getfloatfield(L, index, "noise_threshhold", nthresh)) { + log_deprecated(L, "Field \"noise_threshhold\" on ore " + ore->name + + " is deprecated, use \"noise_threshold\" instead.", 2); + } else { + nthresh = 0; + } + ore->nthresh = nthresh; + } //// Get y_min/y_max - 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", "ore " + ore->name, - "Deprecated: new name is \"y_max\"."); - int ymin, ymax; - if (!getintfield(L, index, "y_min", ymin) && - !getintfield(L, index, "height_min", ymin)) - ymin = -31000; - if (!getintfield(L, index, "y_max", ymax) && - !getintfield(L, index, "height_max", ymax)) - ymax = 31000; - ore->y_min = ymin; - ore->y_max = ymax; + { + int ymin; + if (getintfield(L, index, "y_min", ymin)) { + } else if (getintfield(L, index, "height_min", ymin)) { + log_deprecated(L, "Field \"height_min\" on ore " + ore->name + + " is deprecated, use \"y_min\" instead.", 2); + } else { + ymin = -31000; + } + ore->y_min = ymin; + } + + { + int ymax; + if (getintfield(L, index, "y_max", ymax)) { + } else if (getintfield(L, index, "height_max", ymax)) { + log_deprecated(L, "Field \"height_max\" on ore " + ore->name + + " is deprecated, use \"y_max\" instead.", 2); + } else { + ymax = 31000; + } + ore->y_max = ymax; + } if (ore->clust_scarcity <= 0 || ore->clust_num_ores <= 0) { errorstream << "register_ore: clust_scarcity and clust_num_ores" @@ -1410,8 +1423,8 @@ int ModApiMapgen::l_register_ore(lua_State *L) if (read_noiseparams(L, -1, &ore->np)) { ore->flags |= OREFLAG_USE_NOISE; } else if (ore->needs_noise) { - log_deprecated(L, - "register_ore: ore type requires 'noise_params' but it is not specified, falling back to defaults"); + log_deprecated(L, "register_ore: ore type requires 'noise_params'" + " but it is not specified, falling back to defaults", 2); } lua_pop(L, 1);